Skip to content
Open
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
12 changes: 8 additions & 4 deletions docs/stackit_beta_sfs_snapshot_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 21 additions & 12 deletions internal/cmd/beta/sfs/snapshot/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the spec this is defined as integer or null <uint32>. The generator uses an int32 here, which does not cover all values of an uint32. Here it does not matter, but should we investigate this further?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, but isn't it already of type NullableInt32?

})
return req
}
Expand All @@ -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)
Expand Down
20 changes: 14 additions & 6 deletions internal/cmd/beta/sfs/snapshot/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ 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 {
flagValues := map[string]string{
projectIdFlag: testProjectId,
regionFlag: testRegion,

nameFlag: testName,
resourcePoolIdFlag: testResourcePoolId,
commentFlag: testComment,
nameFlag: testName,
resourcePoolIdFlag: testResourcePoolId,
commentFlag: testComment,
snaplockRetentionHoursFlag: "24",
}
for _, mod := range mods {
mod(flagValues)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
}),
},
{
Expand Down
Loading