Skip to content

Commit dffec7b

Browse files
committed
feat(sfs): extend resource-pool commands with snapshotPolicyId
relates to STACKITCLI-394
1 parent f6c5649 commit dffec7b

8 files changed

Lines changed: 80 additions & 13 deletions

File tree

docs/stackit_beta_sfs_resource-pool_create.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,22 @@ stackit beta sfs resource-pool create [flags]
2727
2828
Create a SFS resource pool with visible snapshots
2929
$ stackit beta sfs resource-pool create --availability-zone eu01-m --ip-acl 10.88.135.144/28 --performance-class Standard --size 500 --name resource-pool-01 --snapshots-visible
30+
31+
Create a SFS resource pool with specific snapshot policy
32+
$ stackit beta sfs resource-pool create --availability-zone eu01-m --ip-acl 10.88.135.144/28 --performance-class Standard --size 500 --name resource-pool-01 --snapshot-policy-id XXX
3033
```
3134

3235
### Options
3336

3437
```
35-
--availability-zone string Availability zone
36-
-h, --help Help for "stackit beta sfs resource-pool create"
37-
--ip-acl strings List of network addresses in the form <address/prefix>, e.g. 192.168.10.0/24 that can mount the resource pool readonly (default [])
38-
--name string Name
39-
--performance-class string Performance class
40-
--size int32 Size of the pool in Gigabytes
41-
--snapshots-visible Set snapshots visible and accessible to users
38+
--availability-zone string Availability zone
39+
-h, --help Help for "stackit beta sfs resource-pool create"
40+
--ip-acl strings List of network addresses in the form <address/prefix>, e.g. 192.168.10.0/24 that can mount the resource pool readonly (default [])
41+
--name string Name
42+
--performance-class string Performance class
43+
--size int32 Size of the pool in Gigabytes
44+
--snapshot-policy-id string Set snapshot policy ID
45+
--snapshots-visible Set snapshots visible and accessible to users
4246
```
4347

4448
### Options inherited from parent commands

docs/stackit_beta_sfs_resource-pool_update.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@ stackit beta sfs resource-pool update [flags]
2727
2828
Update the SFS resource pool with ID "xxx", set snapshots visible to false
2929
$ stackit beta sfs resource-pool update xxx --snapshots-visible=false
30+
31+
Update the SFS resource pool with ID "xxx" to set snapshot policy id to "YYY"
32+
$ stackit beta sfs resource-pool update xxx --snapshot-policy-id=YYY
3033
```
3134

3235
### Options
3336

3437
```
35-
-h, --help Help for "stackit beta sfs resource-pool update"
36-
--ip-acl strings List of network addresses in the form <address/prefix>, e.g. 192.168.10.0/24 that can mount the resource pool readonly (default [])
37-
--performance-class string Performance class
38-
--size int32 Size of the pool in Gigabytes
39-
--snapshots-visible Set snapshots visible and accessible to users
38+
-h, --help Help for "stackit beta sfs resource-pool update"
39+
--ip-acl strings List of network addresses in the form <address/prefix>, e.g. 192.168.10.0/24 that can mount the resource pool readonly (default [])
40+
--performance-class string Performance class
41+
--size int32 Size of the pool in Gigabytes
42+
--snapshot-policy-id string Set snapshot policy ID
43+
--snapshots-visible Set snapshots visible and accessible to users
4044
```
4145

4246
### Options inherited from parent commands

internal/cmd/beta/sfs/resource-pool/create/create.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
availabilityZoneFlag = "availability-zone"
2929
nameFlag = "name"
3030
snapshotsVisibleFlag = "snapshots-visible"
31+
snapshotPolicyIdFlag = "snapshot-policy-id"
3132
)
3233

3334
type inputModel struct {
@@ -38,6 +39,7 @@ type inputModel struct {
3839
Name string
3940
AvailabilityZone string
4041
SnapshotsVisible bool
42+
SnapshotPolicyId string
4143
}
4244

4345
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -62,6 +64,9 @@ The available performance class values can be obtained by running:
6264
examples.NewExample(
6365
`Create a SFS resource pool with visible snapshots`,
6466
"$ stackit beta sfs resource-pool create --availability-zone eu01-m --ip-acl 10.88.135.144/28 --performance-class Standard --size 500 --name resource-pool-01 --snapshots-visible"),
67+
examples.NewExample(
68+
`Create a SFS resource pool with specific snapshot policy`,
69+
"$ stackit beta sfs resource-pool create --availability-zone eu01-m --ip-acl 10.88.135.144/28 --performance-class Standard --size 500 --name resource-pool-01 --snapshot-policy-id XXX"),
6570
),
6671
RunE: func(cmd *cobra.Command, args []string) error {
6772
ctx := context.Background()
@@ -124,6 +129,7 @@ func configureFlags(cmd *cobra.Command) {
124129
cmd.Flags().String(availabilityZoneFlag, "", "Availability zone")
125130
cmd.Flags().String(nameFlag, "", "Name")
126131
cmd.Flags().Bool(snapshotsVisibleFlag, false, "Set snapshots visible and accessible to users")
132+
cmd.Flags().String(snapshotPolicyIdFlag, "", "Set snapshot policy ID")
127133

128134
for _, flag := range []string{sizeFlag, performanceClassFlag, ipAclFlag, availabilityZoneFlag, nameFlag} {
129135
err := flags.MarkFlagsRequired(cmd, flag)
@@ -140,6 +146,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *sfs.APIClie
140146
PerformanceClass: model.PerformanceClass,
141147
SizeGigabytes: *model.SizeInGB,
142148
SnapshotsAreVisible: &model.SnapshotsVisible,
149+
SnapshotPolicyId: &model.SnapshotPolicyId,
143150
})
144151
return req
145152
}
@@ -156,6 +163,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
156163
ipAcls := flags.FlagToStringSliceValue(p, cmd, ipAclFlag)
157164
name := flags.FlagToStringValue(p, cmd, nameFlag)
158165
snapshotsVisible := flags.FlagToBoolValue(p, cmd, snapshotsVisibleFlag)
166+
snapshotPolicyId := flags.FlagToStringValue(p, cmd, snapshotPolicyIdFlag)
159167

160168
model := inputModel{
161169
GlobalFlagModel: globalFlags,
@@ -165,6 +173,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
165173
AvailabilityZone: availabilityZone,
166174
Name: name,
167175
SnapshotsVisible: snapshotsVisible,
176+
SnapshotPolicyId: snapshotPolicyId,
168177
}
169178

170179
p.DebugInputModel(model)

internal/cmd/beta/sfs/resource-pool/create/create_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var (
3131
testResourcePoolName = "sfs-resource-pool-01"
3232
testResourcePoolIpAcl = []string{"10.88.135.144/28", "250.81.87.224/32"}
3333
testSnapshotsVisible = true
34+
testSnapshotPolicyId = uuid.NewString()
3435
)
3536

3637
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
@@ -43,6 +44,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
4344
availabilityZoneFlag: testResourcePoolAvailabilityZone,
4445
nameFlag: testResourcePoolName,
4546
snapshotsVisibleFlag: strconv.FormatBool(testSnapshotsVisible),
47+
snapshotPolicyIdFlag: testSnapshotPolicyId,
4648
}
4749
for _, mod := range mods {
4850
mod(flagValues)
@@ -63,6 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6365
SizeInGB: &testResourcePoolSizeInGB,
6466
IpAcl: testResourcePoolIpAcl,
6567
SnapshotsVisible: testSnapshotsVisible,
68+
SnapshotPolicyId: testSnapshotPolicyId,
6669
}
6770
for _, mod := range mods {
6871
mod(model)
@@ -79,6 +82,7 @@ func fixtureRequest(mods ...func(request *sfs.ApiCreateResourcePoolRequest)) sfs
7982
IpAcl: testResourcePoolIpAcl,
8083
SizeGigabytes: testResourcePoolSizeInGB,
8184
SnapshotsAreVisible: &testSnapshotsVisible,
85+
SnapshotPolicyId: &testSnapshotPolicyId,
8286
})
8387
for _, mod := range mods {
8488
mod(&request)
@@ -211,6 +215,16 @@ func TestParseInput(t *testing.T) {
211215
}),
212216
isValid: false,
213217
},
218+
{
219+
description: "snapshot policy id missing",
220+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
221+
delete(flagValues, snapshotPolicyIdFlag)
222+
}),
223+
expectedModel: fixtureInputModel(func(model *inputModel) {
224+
model.SnapshotPolicyId = ""
225+
}),
226+
isValid: true,
227+
},
214228
}
215229

216230
for _, tt := range tests {

internal/cmd/beta/sfs/resource-pool/describe/describe.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ func outputResult(p *print.Printer, outputFormat, resourcePoolId, projectLabel s
111111
ipAclStr = strings.Join(resourcePool.IpAcl, ", ")
112112
}
113113

114+
var snapshotPolicyId string
115+
if resourcePool.SnapshotPolicy.Get() != nil {
116+
snapshotPolicyId = *resourcePool.SnapshotPolicy.Get().Id
117+
}
118+
114119
table.AddRow("ID", utils.PtrString(resourcePool.Id))
115120
table.AddSeparator()
116121
table.AddRow("NAME", utils.PtrString(resourcePool.Name))
@@ -129,6 +134,8 @@ func outputResult(p *print.Printer, outputFormat, resourcePoolId, projectLabel s
129134
}
130135
table.AddRow("SNAPSHOTS ARE VISIBLE", utils.PtrString(resourcePool.SnapshotsAreVisible))
131136
table.AddSeparator()
137+
table.AddRow("SNAPSHOT POLICY ID", snapshotPolicyId)
138+
table.AddSeparator()
132139
table.AddRow("NEXT PERFORMANCE CLASS DOWNGRADE TIME", resourcePool.PerformanceClassDowngradableAt)
133140
table.AddSeparator()
134141
table.AddRow("NEXT SIZE REDUCTION TIME", resourcePool.SizeReducibleAt)

internal/cmd/beta/sfs/resource-pool/list/list.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,25 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, resourceP
128128
}
129129

130130
table := tables.NewTable()
131-
table.SetHeader("ID", "NAME", "AVAILABILITY ZONE", "STATE", "TOTAL SIZE (GB)", "USED SIZE (GB)")
131+
table.SetHeader("ID", "NAME", "AVAILABILITY ZONE", "STATE", "TOTAL SIZE (GB)", "USED SIZE (GB), SNAPSHOT POLICY ID")
132132
for _, resourcePool := range resourcePools {
133133
totalSizeGigabytes, usedSizeGigabytes := "", ""
134134
if resourcePool.HasSpace() {
135135
totalSizeGigabytes = utils.PtrString(resourcePool.Space.SizeGigabytes)
136136
usedSizeGigabytes = utils.PtrString(resourcePool.Space.UsedGigabytes.Get())
137137
}
138+
var snapshotPolicyId string
139+
if resourcePool.SnapshotPolicy.Get() != nil {
140+
snapshotPolicyId = *resourcePool.SnapshotPolicy.Get().Id
141+
}
138142
table.AddRow(
139143
utils.PtrString(resourcePool.Id),
140144
utils.PtrString(resourcePool.Name),
141145
utils.PtrString(resourcePool.AvailabilityZone),
142146
utils.PtrString(resourcePool.State),
143147
totalSizeGigabytes,
144148
usedSizeGigabytes,
149+
snapshotPolicyId,
145150
)
146151
}
147152
err := table.Display(p)

internal/cmd/beta/sfs/resource-pool/update/update.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
sizeFlag = "size"
2929
ipAclFlag = "ip-acl"
3030
snapshotsVisibleFlag = "snapshots-visible"
31+
snapshotPolicyIdFlag = "snapshot-policy-id"
3132
)
3233

3334
type inputModel struct {
@@ -37,6 +38,7 @@ type inputModel struct {
3738
IpAcl []string
3839
ResourcePoolId string
3940
SnapshotsVisible *bool
41+
SnapshotPolicyId *string
4042
}
4143

4244
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -61,6 +63,9 @@ The available performance class values can be obtained by running:
6163
examples.NewExample(
6264
`Update the SFS resource pool with ID "xxx", set snapshots visible to false`,
6365
"$ stackit beta sfs resource-pool update xxx --snapshots-visible=false"),
66+
examples.NewExample(
67+
`Update the SFS resource pool with ID "xxx" to set snapshot policy id to "YYY"`,
68+
"$ stackit beta sfs resource-pool update xxx --snapshot-policy-id=YYY"),
6469
),
6570
RunE: func(cmd *cobra.Command, args []string) error {
6671
ctx := context.Background()
@@ -123,6 +128,7 @@ func configureFlags(cmd *cobra.Command) {
123128
cmd.Flags().String(performanceClassFlag, "", "Performance class")
124129
cmd.Flags().Var(flags.CIDRSliceFlag(), ipAclFlag, "List of network addresses in the form <address/prefix>, e.g. 192.168.10.0/24 that can mount the resource pool readonly")
125130
cmd.Flags().Bool(snapshotsVisibleFlag, false, "Set snapshots visible and accessible to users")
131+
cmd.Flags().String(snapshotPolicyIdFlag, "", "Set snapshot policy ID")
126132
}
127133

128134
func buildRequest(ctx context.Context, model *inputModel, apiClient *sfs.APIClient) sfs.ApiUpdateResourcePoolRequest {
@@ -132,6 +138,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *sfs.APIClie
132138
PerformanceClass: model.PerformanceClass,
133139
SizeGigabytes: *sfs.NewNullableInt32(model.SizeGigabytes),
134140
SnapshotsAreVisible: model.SnapshotsVisible,
141+
SnapshotPolicyId: model.SnapshotPolicyId,
135142
})
136143
return req
137144
}
@@ -148,6 +155,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
148155
size := flags.FlagToInt32Pointer(p, cmd, sizeFlag)
149156
ipAcls := flags.FlagToStringSliceValue(p, cmd, ipAclFlag)
150157
snapshotsVisible := flags.FlagToBoolPointer(p, cmd, snapshotsVisibleFlag)
158+
snapshotPolicyId := flags.FlagToStringPointer(p, cmd, snapshotPolicyIdFlag)
151159

152160
if performanceClass == nil && size == nil && ipAcls == nil && snapshotsVisible == nil {
153161
return nil, &cliErr.EmptyUpdateError{}
@@ -160,6 +168,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
160168
PerformanceClass: performanceClass,
161169
ResourcePoolId: resourcePoolId,
162170
SnapshotsVisible: snapshotsVisible,
171+
SnapshotPolicyId: snapshotPolicyId,
163172
}
164173

165174
p.DebugInputModel(model)

internal/cmd/beta/sfs/resource-pool/update/update_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
testResourcePoolPerformanceClass = "Standard"
3535
testResourcePoolSizeInGB int32 = 50
3636
testSnapshotsVisible = true
37+
testSnapshotPolicyId = uuid.NewString()
3738
)
3839

3940
func fixtureArgValues(mods ...func(argValues []string)) []string {
@@ -54,6 +55,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
5455
sizeFlag: strconv.FormatInt(int64(testResourcePoolSizeInGB), 10),
5556
ipAclFlag: strings.Join(testResourcePoolIpAcl, ","),
5657
snapshotsVisibleFlag: strconv.FormatBool(testSnapshotsVisible),
58+
snapshotPolicyIdFlag: testSnapshotPolicyId,
5759
}
5860
for _, mod := range mods {
5961
mod(flagValues)
@@ -75,6 +77,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
7577
PerformanceClass: &testResourcePoolPerformanceClass,
7678
IpAcl: ipAclClone,
7779
SnapshotsVisible: &testSnapshotsVisible,
80+
SnapshotPolicyId: &testSnapshotPolicyId,
7881
}
7982
for _, mod := range mods {
8083
mod(model)
@@ -89,6 +92,7 @@ func fixtureRequest(mods ...func(request *sfs.ApiUpdateResourcePoolRequest)) sfs
8992
PerformanceClass: &testResourcePoolPerformanceClass,
9093
SizeGigabytes: *sfs.NewNullableInt32(&testResourcePoolSizeInGB),
9194
SnapshotsAreVisible: &testSnapshotsVisible,
95+
SnapshotPolicyId: &testSnapshotPolicyId,
9296
})
9397
for _, mod := range mods {
9498
mod(&request)
@@ -266,6 +270,17 @@ func TestParseInput(t *testing.T) {
266270
model.IpAcl = append(model.IpAcl, "198.51.100.14/24", "198.51.100.14/32")
267271
}),
268272
},
273+
{
274+
description: "snapshot policy id missing",
275+
argValues: fixtureArgValues(),
276+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
277+
delete(flagValues, snapshotPolicyIdFlag)
278+
}),
279+
expectedModel: fixtureInputModel(func(model *inputModel) {
280+
model.SnapshotPolicyId = nil
281+
}),
282+
isValid: true,
283+
},
269284
}
270285

271286
for _, tt := range tests {

0 commit comments

Comments
 (0)