Skip to content

Commit 20141ab

Browse files
author
awlsring
committed
feat: node storage lvm, lvmthin, nfs
1 parent 18b19aa commit 20141ab

22 files changed

+837
-38
lines changed

docs/data-sources/lvm_storage_classes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ Read-Only:
4040
- `content_types` (List of String) The content types that can be stored on this storage class.
4141
- `id` (String) The identifier of the storage class.
4242
- `nodes` (List of String) Nodes that implement this storage class.
43-
- `volume_group` (String) The NFS server used in the storage class.
43+
- `volume_group` (String) The volume group used by the thinpool.
4444

4545

docs/data-sources/lvm_thinpool_storage_classes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Read-Only:
4040
- `content_types` (List of String) The content types that can be stored on this storage class.
4141
- `id` (String) The identifier of the storage class.
4242
- `nodes` (List of String) Nodes that implement this storage class.
43-
- `thinpool` (String) The local mount of the NFS share that should be implemented by each node.
44-
- `volume_group` (String) The NFS server used in the storage class.
43+
- `thinpool` (String) The thinpools name.
44+
- `volume_group` (String) The path the volume group used by the thinpool.
4545

4646

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "proxmox_node_storage_lvm_thinpools Data Source - terraform-provider-proxmox"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# proxmox_node_storage_lvm_thinpools (Data Source)
10+
11+
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- `filters` (Attributes List) (see [below for nested schema](#nestedatt--filters))
21+
22+
### Read-Only
23+
24+
- `node_storage_lvm_thinpools` (Attributes List) (see [below for nested schema](#nestedatt--node_storage_lvm_thinpools))
25+
26+
<a id="nestedatt--filters"></a>
27+
### Nested Schema for `filters`
28+
29+
Required:
30+
31+
- `name` (String) The name of the attribute to filter on.
32+
- `values` (List of String) The value(s) to be used in the filter.
33+
34+
35+
<a id="nestedatt--node_storage_lvm_thinpools"></a>
36+
### Nested Schema for `node_storage_lvm_thinpools`
37+
38+
Read-Only:
39+
40+
- `content_types` (List of String) The content types that can be stored on this storage class.
41+
- `id` (String) The identifier of the node storage. Formatted as `{node}/{storage}`
42+
- `node` (String) The node which the class implementation is on.
43+
- `size` (Number) The size of the storage in bytes.
44+
- `storage` (String) The name of the storage class this implements.
45+
- `thinpool` (String) The thinpools name.
46+
- `volume_group` (String) The associated volume group.
47+
48+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "proxmox_node_storage_lvms Data Source - terraform-provider-proxmox"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# proxmox_node_storage_lvms (Data Source)
10+
11+
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- `filters` (Attributes List) (see [below for nested schema](#nestedatt--filters))
21+
22+
### Read-Only
23+
24+
- `node_storage_lvms` (Attributes List) (see [below for nested schema](#nestedatt--node_storage_lvms))
25+
26+
<a id="nestedatt--filters"></a>
27+
### Nested Schema for `filters`
28+
29+
Required:
30+
31+
- `name` (String) The name of the attribute to filter on.
32+
- `values` (List of String) The value(s) to be used in the filter.
33+
34+
35+
<a id="nestedatt--node_storage_lvms"></a>
36+
### Nested Schema for `node_storage_lvms`
37+
38+
Read-Only:
39+
40+
- `content_types` (List of String) The content types that can be stored on this storage class.
41+
- `id` (String) The identifier of the node storage. Formatted as `{node}/{storage}`
42+
- `node` (String) The node which the class implementation is on.
43+
- `size` (Number) The size of the storage in bytes.
44+
- `storage` (String) The name of the storage class this implements.
45+
- `volume_group` (String) The associated volume group.
46+
47+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "proxmox_node_storage_nfs Data Source - terraform-provider-proxmox"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# proxmox_node_storage_nfs (Data Source)
10+
11+
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- `filters` (Attributes List) (see [below for nested schema](#nestedatt--filters))
21+
22+
### Read-Only
23+
24+
- `node_storage_nfs` (Attributes List) (see [below for nested schema](#nestedatt--node_storage_nfs))
25+
26+
<a id="nestedatt--filters"></a>
27+
### Nested Schema for `filters`
28+
29+
Required:
30+
31+
- `name` (String) The name of the attribute to filter on.
32+
- `values` (List of String) The value(s) to be used in the filter.
33+
34+
35+
<a id="nestedatt--node_storage_nfs"></a>
36+
### Nested Schema for `node_storage_nfs`
37+
38+
Read-Only:
39+
40+
- `content_types` (List of String) The content types that can be stored on this storage class.
41+
- `export` (String) The path the NFS has exported as the share.
42+
- `id` (String) The identifier of the node storage. Formatted as `{node}/{storage}`
43+
- `mount` (String) The path the NFS share is mounted at.
44+
- `node` (String) The node which the class implementation is on.
45+
- `server` (String) The NFS server.
46+
- `size` (Number) The size of the storage in bytes.
47+
- `storage` (String) The name of the storage class this implements.
48+
49+

internal/service/node_storage.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package service
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/awlsring/proxmox-go/proxmox"
8+
)
9+
10+
func (c *Proxmox) GetNodeStorage(ctx context.Context, node string, storage string) (*proxmox.NodeStorageSummary, error) {
11+
request := c.client.ListNodeStorage(ctx, node)
12+
request = request.Storage(storage)
13+
resp, _, err := c.client.ListNodeStorageExecute(request)
14+
if err != nil {
15+
return nil, err
16+
}
17+
18+
if len(resp.Data) != 1 {
19+
return nil, fmt.Errorf("expected 1 storage, got %d", len(resp.Data))
20+
}
21+
22+
return &resp.Data[0], nil
23+
}
24+
25+
func (c *Proxmox) ListNodeStorage(ctx context.Context, node string) ([]proxmox.NodeStorageSummary, error) {
26+
request := c.client.ListNodeStorage(ctx, node)
27+
request.Enabled(1)
28+
resp, _, err := c.client.ListNodeStorageExecute(request)
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
return resp.Data, nil
34+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package service
2+
3+
import (
4+
"context"
5+
6+
"github.com/awlsring/proxmox-go/proxmox"
7+
)
8+
9+
type LVMNodeStorage struct {
10+
Id string
11+
Node string
12+
Storage string
13+
ContentTypes []string
14+
Size int64
15+
VolumeGroup string
16+
}
17+
18+
func (c *Proxmox) DescribeLVMNodeStorage(ctx context.Context, node string) ([]*LVMNodeStorage, error) {
19+
nodeStorage, err := c.ListNodeStorage(ctx, node)
20+
if err != nil {
21+
return nil, err
22+
}
23+
24+
storageList := []*LVMNodeStorage{}
25+
for _, s := range nodeStorage {
26+
if s.Type != proxmox.STORAGETYPE_LVM || s.Enabled == nil {
27+
continue
28+
}
29+
if *s.Enabled != 1 {
30+
continue
31+
}
32+
33+
s := &LVMNodeStorage{
34+
Id: s.Storage,
35+
Node: node,
36+
Storage: s.Storage,
37+
Size: PtrFloatToInt64(s.Total),
38+
ContentTypes: StringCommaListToSlice(s.Content),
39+
}
40+
storageList = append(storageList, s)
41+
}
42+
43+
for _, s := range storageList {
44+
storage, err := c.GetLVMStorageClass(ctx, s.Storage)
45+
if err != nil {
46+
return nil, err
47+
}
48+
s.VolumeGroup = storage.VolumeGroup
49+
}
50+
51+
return storageList, nil
52+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package service
2+
3+
import (
4+
"context"
5+
6+
"github.com/awlsring/proxmox-go/proxmox"
7+
)
8+
9+
type LVMThinNodeStorage struct {
10+
Id string
11+
Node string
12+
Storage string
13+
ContentTypes []string
14+
Size int64
15+
VolumeGroup string
16+
Thinpool string
17+
}
18+
19+
func (c *Proxmox) DescribeLVMThinNodeStorage(ctx context.Context, node string) ([]*LVMThinNodeStorage, error) {
20+
nodeStorage, err := c.ListNodeStorage(ctx, node)
21+
if err != nil {
22+
return nil, err
23+
}
24+
25+
storageList := []*LVMThinNodeStorage{}
26+
for _, s := range nodeStorage {
27+
if s.Type != proxmox.STORAGETYPE_LVMTHIN || s.Enabled == nil {
28+
continue
29+
}
30+
if *s.Enabled != 1 {
31+
continue
32+
}
33+
34+
s := &LVMThinNodeStorage{
35+
Id: s.Storage,
36+
Node: node,
37+
Storage: s.Storage,
38+
Size: PtrFloatToInt64(s.Total),
39+
ContentTypes: StringCommaListToSlice(s.Content),
40+
}
41+
storageList = append(storageList, s)
42+
}
43+
44+
for _, s := range storageList {
45+
storage, err := c.GetLVMThinStorageClass(ctx, s.Storage)
46+
if err != nil {
47+
return nil, err
48+
}
49+
s.VolumeGroup = storage.VolumeGroup
50+
s.Thinpool = storage.Thinpool
51+
}
52+
53+
return storageList, nil
54+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package service
2+
3+
import (
4+
"context"
5+
6+
"github.com/awlsring/proxmox-go/proxmox"
7+
)
8+
9+
type NFSNodeStorage struct {
10+
Id string
11+
Node string
12+
Storage string
13+
ContentTypes []string
14+
Size int64
15+
Server string
16+
Mount string
17+
Export string
18+
}
19+
20+
func (c *Proxmox) DescribeNFSNodeStorage(ctx context.Context, node string) ([]*NFSNodeStorage, error) {
21+
nodeStorage, err := c.ListNodeStorage(ctx, node)
22+
if err != nil {
23+
return nil, err
24+
}
25+
26+
storageList := []*NFSNodeStorage{}
27+
for _, s := range nodeStorage {
28+
if s.Type != proxmox.STORAGETYPE_NFS || s.Enabled == nil {
29+
continue
30+
}
31+
if *s.Enabled != 1 {
32+
continue
33+
}
34+
35+
s := &NFSNodeStorage{
36+
Id: s.Storage,
37+
Node: node,
38+
Storage: s.Storage,
39+
Size: PtrFloatToInt64(s.Total),
40+
ContentTypes: StringCommaListToSlice(s.Content),
41+
}
42+
storageList = append(storageList, s)
43+
}
44+
45+
for _, s := range storageList {
46+
storage, err := c.GetNFSStorageClass(ctx, s.Storage)
47+
if err != nil {
48+
return nil, err
49+
}
50+
s.Server = storage.Server
51+
s.Export = storage.Export
52+
s.Mount = storage.Mount
53+
}
54+
55+
return storageList, nil
56+
}

0 commit comments

Comments
 (0)