Skip to content

Commit 18b19aa

Browse files
author
awlsring
committed
feat: lvm, lvmthin storage data source & resource
1 parent 5f0fa2e commit 18b19aa

File tree

16 files changed

+1361
-163
lines changed

16 files changed

+1361
-163
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "proxmox_lvm_storage_classes Data Source - terraform-provider-proxmox"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# proxmox_lvm_storage_classes (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+
- `lvm_storage_classes` (Attributes List) (see [below for nested schema](#nestedatt--lvm_storage_classes))
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--lvm_storage_classes"></a>
36+
### Nested Schema for `lvm_storage_classes`
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 storage class.
42+
- `nodes` (List of String) Nodes that implement this storage class.
43+
- `volume_group` (String) The NFS server used in the storage class.
44+
45+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "proxmox_lvm_thinpool_storage_classes Data Source - terraform-provider-proxmox"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# proxmox_lvm_thinpool_storage_classes (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+
- `lvm_thinpool_storage_classes` (Attributes List) (see [below for nested schema](#nestedatt--lvm_thinpool_storage_classes))
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--lvm_thinpool_storage_classes"></a>
36+
### Nested Schema for `lvm_thinpool_storage_classes`
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 storage class.
42+
- `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.
45+
46+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "proxmox_lvm_storage_class Resource - terraform-provider-proxmox"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# proxmox_lvm_storage_class (Resource)
10+
11+
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `id` (String) The identifier of the storage class.
21+
- `volume_group` (String) The associated volume group.
22+
23+
### Optional
24+
25+
- `content_types` (List of String) The content types that can be stored on this storage class.
26+
- `nodes` (List of String) Nodes that implement this storage class.
27+
28+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "proxmox_lvm_thinpool_storage_class Resource - terraform-provider-proxmox"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# proxmox_lvm_thinpool_storage_class (Resource)
10+
11+
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `id` (String) The identifier of the storage class.
21+
- `thinpool` (String) The LVM thinpool that should be implemented by each node.
22+
- `volume_group` (String) The associated volume group.
23+
24+
### Optional
25+
26+
- `content_types` (List of String) The content types that can be stored on this storage class.
27+
- `nodes` (List of String) Nodes that implement this storage class.
28+
29+
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package service
2+
3+
import (
4+
"context"
5+
6+
"github.com/awlsring/proxmox-go/proxmox"
7+
"github.com/awlsring/terraform-provider-proxmox/internal/service/errors"
8+
)
9+
10+
type LVMStorageClass struct {
11+
Id string
12+
VolumeGroup string
13+
Nodes []string
14+
Content []string
15+
}
16+
17+
func (c *Proxmox) ListLVMStorageClasses(ctx context.Context) ([]LVMStorageClass, error) {
18+
storage, err := c.listStorageOfType(ctx, proxmox.STORAGETYPE_LVM)
19+
if err != nil {
20+
return nil, err
21+
}
22+
23+
allNodes := []string{}
24+
storageList := []LVMStorageClass{}
25+
for _, s := range storage {
26+
var nodes []string
27+
if s.Nodes != nil {
28+
nodes = StringCommaPtrListToSlice(s.Nodes)
29+
} else {
30+
if len(allNodes) == 0 {
31+
allNodes, err = c.ListNodesNames(ctx)
32+
if err != nil {
33+
return nil, err
34+
}
35+
}
36+
nodes = allNodes
37+
}
38+
39+
s := LVMStorageClass{
40+
Id: s.Storage,
41+
VolumeGroup: *s.Vgname,
42+
Nodes: nodes,
43+
Content: StringCommaPtrListToSlice(s.Content),
44+
}
45+
storageList = append(storageList, s)
46+
}
47+
48+
return storageList, nil
49+
}
50+
51+
func (c *Proxmox) GetLVMStorageClass(ctx context.Context, name string) (*LVMStorageClass, error) {
52+
storage, err := c.GetStorageClass(ctx, name)
53+
if err != nil {
54+
return nil, err
55+
}
56+
57+
var nodes []string
58+
if storage.Nodes != nil {
59+
nodes = StringCommaPtrListToSlice(storage.Nodes)
60+
} else {
61+
nodes, err = c.ListNodesNames(ctx)
62+
if err != nil {
63+
return nil, err
64+
}
65+
}
66+
67+
s := LVMStorageClass{
68+
Id: storage.Storage,
69+
VolumeGroup: *storage.Vgname,
70+
Nodes: nodes,
71+
Content: StringCommaPtrListToSlice(storage.Content),
72+
}
73+
74+
return &s, nil
75+
}
76+
77+
type CreateLVMStorageClassInput struct {
78+
Id string
79+
VolumeGroup string
80+
Nodes []string
81+
ContentTypes []string
82+
}
83+
84+
func (c *Proxmox) CreateLVMStorageClass(ctx context.Context, input *CreateLVMStorageClassInput) error {
85+
request := c.client.CreateStorage(ctx)
86+
content := proxmox.CreateStorageRequestContent{
87+
Storage: input.Id,
88+
Vgname: &input.VolumeGroup,
89+
Type: proxmox.STORAGETYPE_LVM,
90+
Content: SliceToStringCommaListPtr(input.ContentTypes),
91+
Nodes: SliceToStringCommaListPtr(input.Nodes),
92+
}
93+
request = request.CreateStorageRequestContent(content)
94+
95+
_, h, err := c.client.CreateStorageExecute(request)
96+
if err != nil {
97+
return errors.ApiError(h, err)
98+
}
99+
100+
return nil
101+
}
102+
103+
func (c *Proxmox) DeleteLVMSStorageClass(ctx context.Context, name string) error {
104+
request := c.client.DeleteStorage(ctx, name)
105+
h, err := c.client.DeleteStorageExecute(request)
106+
if err != nil {
107+
return errors.ApiError(h, err)
108+
}
109+
110+
return nil
111+
}
112+
113+
type ModifyLVMStorageClassInput struct {
114+
Nodes []string
115+
ContentTypes []string
116+
}
117+
118+
func (c *Proxmox) ModifyLVMStorageClass(ctx context.Context, name string, input *ModifyLVMStorageClassInput) error {
119+
request := c.client.ModifyStorage(ctx, name)
120+
content := proxmox.ModifyStorageRequestContent{
121+
Nodes: SliceToStringCommaListPtr(input.Nodes),
122+
Content: SliceToStringCommaListPtr(input.ContentTypes),
123+
}
124+
request = request.ModifyStorageRequestContent(content)
125+
126+
_, h, err := c.client.ModifyStorageExecute(request)
127+
if err != nil {
128+
return errors.ApiError(h, err)
129+
}
130+
131+
return nil
132+
}

0 commit comments

Comments
 (0)