From 75f2be4cf92f234b3c4cc61d2bee0ef1c3414e7c Mon Sep 17 00:00:00 2001 From: Carlo Goetz Date: Fri, 8 May 2026 17:41:51 +0200 Subject: [PATCH] feat(sfs): extend snapshot create with --snaplock-retention-hours STACKITCLI-399 --- docs/stackit_beta_sfs_snapshot_create.md | 12 ++++--- .../cmd/beta/sfs/snapshot/create/create.go | 33 ++++++++++++------- .../beta/sfs/snapshot/create/create_test.go | 20 +++++++---- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/docs/stackit_beta_sfs_snapshot_create.md b/docs/stackit_beta_sfs_snapshot_create.md index ac7a1988b..4d1bc519b 100644 --- a/docs/stackit_beta_sfs_snapshot_create.md +++ b/docs/stackit_beta_sfs_snapshot_create.md @@ -18,15 +18,19 @@ stackit beta sfs snapshot create [flags] Create a new snapshot with name "snapshot-name" and comment "snapshot-comment" of a resource pool with ID "xxx" $ stackit beta sfs snapshot create --name snapshot-name --resource-pool-id xxx --comment "snapshot-comment" + + Create a new snapshot with name "snapshot-name" and snaplock retention hours "24" of a resource pool with ID "xxx" + $ stackit beta sfs snapshot create --name snapshot-name --resource-pool-id xxx --snaplock-retention-hours 24 ``` ### Options ``` - --comment string A comment to add more information to the snapshot - -h, --help Help for "stackit beta sfs snapshot create" - --name string Snapshot name - --resource-pool-id string The resource pool from which the snapshot should be created + --comment string A comment to add more information to the snapshot + -h, --help Help for "stackit beta sfs snapshot create" + --name string Snapshot name + --resource-pool-id string The resource pool from which the snapshot should be created + --snaplock-retention-hours int32 Retention hours for the snaplock ``` ### Options inherited from parent commands diff --git a/internal/cmd/beta/sfs/snapshot/create/create.go b/internal/cmd/beta/sfs/snapshot/create/create.go index 90efa3dd3..c94a4df72 100644 --- a/internal/cmd/beta/sfs/snapshot/create/create.go +++ b/internal/cmd/beta/sfs/snapshot/create/create.go @@ -20,16 +20,18 @@ import ( ) const ( - resourcePoolIdFlag = "resource-pool-id" - nameFlag = "name" - commentFlag = "comment" + resourcePoolIdFlag = "resource-pool-id" + nameFlag = "name" + commentFlag = "comment" + snaplockRetentionHoursFlag = "snaplock-retention-hours" ) type inputModel struct { *globalflags.GlobalFlagModel - ResourcePoolId string - Name string - Comment *string + ResourcePoolId string + Name string + Comment *string + SnaplockRetentionHours *int32 } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -47,6 +49,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command { `Create a new snapshot with name "snapshot-name" and comment "snapshot-comment" of a resource pool with ID "xxx"`, `$ stackit beta sfs snapshot create --name snapshot-name --resource-pool-id xxx --comment "snapshot-comment"`, ), + examples.NewExample( + `Create a new snapshot with name "snapshot-name" and snaplock retention hours "24" of a resource pool with ID "xxx"`, + `$ stackit beta sfs snapshot create --name snapshot-name --resource-pool-id xxx --snaplock-retention-hours 24`, + ), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -92,6 +98,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().String(nameFlag, "", "Snapshot name") cmd.Flags().String(commentFlag, "", "A comment to add more information to the snapshot") + cmd.Flags().Int32(snaplockRetentionHoursFlag, 0, "Retention hours for the snaplock") cmd.Flags().Var(flags.UUIDFlag(), resourcePoolIdFlag, "The resource pool from which the snapshot should be created") err := flags.MarkFlagsRequired(cmd, resourcePoolIdFlag, nameFlag) @@ -101,8 +108,9 @@ func configureFlags(cmd *cobra.Command) { func buildRequest(ctx context.Context, model *inputModel, apiClient *sfs.APIClient) sfs.ApiCreateResourcePoolSnapshotRequest { req := apiClient.DefaultAPI.CreateResourcePoolSnapshot(ctx, model.ProjectId, model.Region, model.ResourcePoolId) req = req.CreateResourcePoolSnapshotPayload(sfs.CreateResourcePoolSnapshotPayload{ - Name: utils.Ptr(model.Name), - Comment: *sfs.NewNullableString(model.Comment), + Name: utils.Ptr(model.Name), + Comment: *sfs.NewNullableString(model.Comment), + SnaplockRetentionHours: *sfs.NewNullableInt32(model.SnaplockRetentionHours), }) return req } @@ -114,10 +122,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } model := inputModel{ - GlobalFlagModel: globalFlags, - Name: flags.FlagToStringValue(p, cmd, nameFlag), - ResourcePoolId: flags.FlagToStringValue(p, cmd, resourcePoolIdFlag), - Comment: flags.FlagToStringPointer(p, cmd, commentFlag), + GlobalFlagModel: globalFlags, + Name: flags.FlagToStringValue(p, cmd, nameFlag), + ResourcePoolId: flags.FlagToStringValue(p, cmd, resourcePoolIdFlag), + Comment: flags.FlagToStringPointer(p, cmd, commentFlag), + SnaplockRetentionHours: flags.FlagToInt32Pointer(p, cmd, snaplockRetentionHoursFlag), } p.DebugInputModel(model) diff --git a/internal/cmd/beta/sfs/snapshot/create/create_test.go b/internal/cmd/beta/sfs/snapshot/create/create_test.go index 94abf5712..bef3e6ed3 100644 --- a/internal/cmd/beta/sfs/snapshot/create/create_test.go +++ b/internal/cmd/beta/sfs/snapshot/create/create_test.go @@ -28,6 +28,7 @@ var testRegion = "eu01" var testName = "test-name" var testComment = "test-comment" +var testSnaplockRetentionHours int32 = 24 var testResourcePoolId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -35,9 +36,10 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st projectIdFlag: testProjectId, regionFlag: testRegion, - nameFlag: testName, - resourcePoolIdFlag: testResourcePoolId, - commentFlag: testComment, + nameFlag: testName, + resourcePoolIdFlag: testResourcePoolId, + commentFlag: testComment, + snaplockRetentionHoursFlag: "24", } for _, mod := range mods { mod(flagValues) @@ -52,9 +54,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - Name: testName, - ResourcePoolId: testResourcePoolId, - Comment: utils.Ptr(testComment), + Name: testName, + ResourcePoolId: testResourcePoolId, + Comment: utils.Ptr(testComment), + SnaplockRetentionHours: utils.Ptr(testSnaplockRetentionHours), } for _, mod := range mods { mod(model) @@ -77,6 +80,9 @@ func fixturePayload(mods ...func(request *sfs.CreateResourcePoolSnapshotPayload) Comment: *sfs.NewNullableString( utils.Ptr(testComment), ), + SnaplockRetentionHours: *sfs.NewNullableInt32( + utils.Ptr(testSnaplockRetentionHours), + ), } for _, mod := range mods { mod(&payload) @@ -102,10 +108,12 @@ func TestParseInput(t *testing.T) { description: "required only", flagValues: fixtureFlagValues(func(flagValues map[string]string) { delete(flagValues, commentFlag) + delete(flagValues, snaplockRetentionHoursFlag) }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { model.Comment = nil + model.SnaplockRetentionHours = nil }), }, {