Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions docs/stackit_beta_sfs_resource-pool_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@ stackit beta sfs resource-pool create [flags]

Create a SFS resource pool with visible snapshots
$ 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

Create a SFS resource pool with specific snapshot policy
$ 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
```

### Options

```
--availability-zone string Availability zone
-h, --help Help for "stackit beta sfs resource-pool create"
--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 [])
--name string Name
--performance-class string Performance class
--size int32 Size of the pool in Gigabytes
--snapshots-visible Set snapshots visible and accessible to users
--availability-zone string Availability zone
-h, --help Help for "stackit beta sfs resource-pool create"
--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 [])
--name string Name
--performance-class string Performance class
--size int32 Size of the pool in Gigabytes
--snapshot-policy-id string Set snapshot policy ID
--snapshots-visible Set snapshots visible and accessible to users
```

### Options inherited from parent commands
Expand Down
14 changes: 9 additions & 5 deletions docs/stackit_beta_sfs_resource-pool_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ stackit beta sfs resource-pool update [flags]

Update the SFS resource pool with ID "xxx", set snapshots visible to false
$ stackit beta sfs resource-pool update xxx --snapshots-visible=false

Update the SFS resource pool with ID "xxx" to set snapshot policy id to "YYY"
$ stackit beta sfs resource-pool update xxx --snapshot-policy-id YYY
```

### Options

```
-h, --help Help for "stackit beta sfs resource-pool update"
--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 [])
--performance-class string Performance class
--size int32 Size of the pool in Gigabytes
--snapshots-visible Set snapshots visible and accessible to users
-h, --help Help for "stackit beta sfs resource-pool update"
--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 [])
--performance-class string Performance class
--size int32 Size of the pool in Gigabytes
--snapshot-policy-id string Set snapshot policy ID
--snapshots-visible Set snapshots visible and accessible to users
```

### Options inherited from parent commands
Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/beta/sfs/resource-pool/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
availabilityZoneFlag = "availability-zone"
nameFlag = "name"
snapshotsVisibleFlag = "snapshots-visible"
snapshotPolicyIdFlag = "snapshot-policy-id"
)

type inputModel struct {
Expand All @@ -38,6 +39,7 @@ type inputModel struct {
Name string
AvailabilityZone string
SnapshotsVisible bool
SnapshotPolicyId string
}

func NewCmd(params *types.CmdParams) *cobra.Command {
Expand All @@ -62,6 +64,9 @@ The available performance class values can be obtained by running:
examples.NewExample(
`Create a SFS resource pool with visible snapshots`,
"$ 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"),
examples.NewExample(
`Create a SFS resource pool with specific snapshot policy`,
"$ 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"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down Expand Up @@ -124,6 +129,7 @@ func configureFlags(cmd *cobra.Command) {
cmd.Flags().String(availabilityZoneFlag, "", "Availability zone")
cmd.Flags().String(nameFlag, "", "Name")
cmd.Flags().Bool(snapshotsVisibleFlag, false, "Set snapshots visible and accessible to users")
cmd.Flags().String(snapshotPolicyIdFlag, "", "Set snapshot policy ID")

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

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

p.DebugInputModel(model)
Expand Down
14 changes: 14 additions & 0 deletions internal/cmd/beta/sfs/resource-pool/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
testResourcePoolName = "sfs-resource-pool-01"
testResourcePoolIpAcl = []string{"10.88.135.144/28", "250.81.87.224/32"}
testSnapshotsVisible = true
testSnapshotPolicyId = uuid.NewString()
)

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
Expand All @@ -43,6 +44,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
availabilityZoneFlag: testResourcePoolAvailabilityZone,
nameFlag: testResourcePoolName,
snapshotsVisibleFlag: strconv.FormatBool(testSnapshotsVisible),
snapshotPolicyIdFlag: testSnapshotPolicyId,
}
for _, mod := range mods {
mod(flagValues)
Expand All @@ -63,6 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
SizeInGB: &testResourcePoolSizeInGB,
IpAcl: testResourcePoolIpAcl,
SnapshotsVisible: testSnapshotsVisible,
SnapshotPolicyId: testSnapshotPolicyId,
}
for _, mod := range mods {
mod(model)
Expand All @@ -79,6 +82,7 @@ func fixtureRequest(mods ...func(request *sfs.ApiCreateResourcePoolRequest)) sfs
IpAcl: testResourcePoolIpAcl,
SizeGigabytes: testResourcePoolSizeInGB,
SnapshotsAreVisible: &testSnapshotsVisible,
SnapshotPolicyId: &testSnapshotPolicyId,
})
for _, mod := range mods {
mod(&request)
Expand Down Expand Up @@ -211,6 +215,16 @@ func TestParseInput(t *testing.T) {
}),
isValid: false,
},
{
description: "snapshot policy id missing",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, snapshotPolicyIdFlag)
}),
expectedModel: fixtureInputModel(func(model *inputModel) {
model.SnapshotPolicyId = ""
}),
isValid: true,
},
}

for _, tt := range tests {
Expand Down
7 changes: 7 additions & 0 deletions internal/cmd/beta/sfs/resource-pool/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ func outputResult(p *print.Printer, outputFormat, resourcePoolId, projectLabel s
ipAclStr = strings.Join(resourcePool.IpAcl, ", ")
}

var snapshotPolicyId string
if resourcePool.SnapshotPolicy.Get() != nil {
snapshotPolicyId = *resourcePool.SnapshotPolicy.Get().Id
}

table.AddRow("ID", utils.PtrString(resourcePool.Id))
table.AddSeparator()
table.AddRow("NAME", utils.PtrString(resourcePool.Name))
Expand All @@ -129,6 +134,8 @@ func outputResult(p *print.Printer, outputFormat, resourcePoolId, projectLabel s
}
table.AddRow("SNAPSHOTS ARE VISIBLE", utils.PtrString(resourcePool.SnapshotsAreVisible))
table.AddSeparator()
table.AddRow("SNAPSHOT POLICY ID", snapshotPolicyId)
table.AddSeparator()
table.AddRow("NEXT PERFORMANCE CLASS DOWNGRADE TIME", resourcePool.PerformanceClassDowngradableAt)
table.AddSeparator()
table.AddRow("NEXT SIZE REDUCTION TIME", resourcePool.SizeReducibleAt)
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/beta/sfs/resource-pool/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
sizeFlag = "size"
ipAclFlag = "ip-acl"
snapshotsVisibleFlag = "snapshots-visible"
snapshotPolicyIdFlag = "snapshot-policy-id"
)

type inputModel struct {
Expand All @@ -37,6 +38,7 @@ type inputModel struct {
IpAcl []string
ResourcePoolId string
SnapshotsVisible *bool
SnapshotPolicyId *string
}

func NewCmd(params *types.CmdParams) *cobra.Command {
Expand All @@ -61,6 +63,9 @@ The available performance class values can be obtained by running:
examples.NewExample(
`Update the SFS resource pool with ID "xxx", set snapshots visible to false`,
"$ stackit beta sfs resource-pool update xxx --snapshots-visible=false"),
examples.NewExample(
`Update the SFS resource pool with ID "xxx" to set snapshot policy id to "YYY"`,
"$ stackit beta sfs resource-pool update xxx --snapshot-policy-id YYY"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down Expand Up @@ -123,6 +128,7 @@ func configureFlags(cmd *cobra.Command) {
cmd.Flags().String(performanceClassFlag, "", "Performance class")
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")
cmd.Flags().Bool(snapshotsVisibleFlag, false, "Set snapshots visible and accessible to users")
cmd.Flags().String(snapshotPolicyIdFlag, "", "Set snapshot policy ID")
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *sfs.APIClient) sfs.ApiUpdateResourcePoolRequest {
Expand All @@ -132,6 +138,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *sfs.APIClie
PerformanceClass: model.PerformanceClass,
SizeGigabytes: *sfs.NewNullableInt32(model.SizeGigabytes),
SnapshotsAreVisible: model.SnapshotsVisible,
SnapshotPolicyId: model.SnapshotPolicyId,
})
return req
}
Expand All @@ -148,8 +155,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
size := flags.FlagToInt32Pointer(p, cmd, sizeFlag)
ipAcls := flags.FlagToStringSliceValue(p, cmd, ipAclFlag)
snapshotsVisible := flags.FlagToBoolPointer(p, cmd, snapshotsVisibleFlag)
snapshotPolicyId := flags.FlagToStringPointer(p, cmd, snapshotPolicyIdFlag)

if performanceClass == nil && size == nil && ipAcls == nil && snapshotsVisible == nil {
if performanceClass == nil && size == nil && ipAcls == nil && snapshotsVisible == nil && snapshotPolicyId == nil {
return nil, &cliErr.EmptyUpdateError{}
}

Expand All @@ -160,6 +168,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
PerformanceClass: performanceClass,
ResourcePoolId: resourcePoolId,
SnapshotsVisible: snapshotsVisible,
SnapshotPolicyId: snapshotPolicyId,
}

p.DebugInputModel(model)
Expand Down
16 changes: 16 additions & 0 deletions internal/cmd/beta/sfs/resource-pool/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
testResourcePoolPerformanceClass = "Standard"
testResourcePoolSizeInGB int32 = 50
testSnapshotsVisible = true
testSnapshotPolicyId = uuid.NewString()
)

func fixtureArgValues(mods ...func(argValues []string)) []string {
Expand All @@ -54,6 +55,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
sizeFlag: strconv.FormatInt(int64(testResourcePoolSizeInGB), 10),
ipAclFlag: strings.Join(testResourcePoolIpAcl, ","),
snapshotsVisibleFlag: strconv.FormatBool(testSnapshotsVisible),
snapshotPolicyIdFlag: testSnapshotPolicyId,
}
for _, mod := range mods {
mod(flagValues)
Expand All @@ -75,6 +77,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
PerformanceClass: &testResourcePoolPerformanceClass,
IpAcl: ipAclClone,
SnapshotsVisible: &testSnapshotsVisible,
SnapshotPolicyId: &testSnapshotPolicyId,
}
for _, mod := range mods {
mod(model)
Expand All @@ -89,6 +92,7 @@ func fixtureRequest(mods ...func(request *sfs.ApiUpdateResourcePoolRequest)) sfs
PerformanceClass: &testResourcePoolPerformanceClass,
SizeGigabytes: *sfs.NewNullableInt32(&testResourcePoolSizeInGB),
SnapshotsAreVisible: &testSnapshotsVisible,
SnapshotPolicyId: &testSnapshotPolicyId,
})
for _, mod := range mods {
mod(&request)
Expand Down Expand Up @@ -138,6 +142,7 @@ func TestParseInput(t *testing.T) {
delete(flagValues, ipAclFlag)
delete(flagValues, performanceClassFlag)
delete(flagValues, snapshotsVisibleFlag)
delete(flagValues, snapshotPolicyIdFlag)
}),
isValid: false,
},
Expand Down Expand Up @@ -266,6 +271,17 @@ func TestParseInput(t *testing.T) {
model.IpAcl = append(model.IpAcl, "198.51.100.14/24", "198.51.100.14/32")
}),
},
{
description: "snapshot policy id missing",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, snapshotPolicyIdFlag)
}),
expectedModel: fixtureInputModel(func(model *inputModel) {
model.SnapshotPolicyId = nil
}),
isValid: true,
},
}

for _, tt := range tests {
Expand Down
Loading