Skip to content

Commit d1f8baa

Browse files
committed
adjust volume commands
1 parent 64562d8 commit d1f8baa

38 files changed

+237
-129
lines changed

internal/cmd/volume/backup/create/create.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
7878
// Get source name for label (use ID if name not available)
7979
sourceLabel := model.SourceID
8080
if model.SourceType == "volume" {
81-
name, err := iaasutils.GetVolumeName(ctx, apiClient, model.ProjectId, model.SourceID)
81+
name, err := iaasutils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, model.SourceID)
8282
if err != nil {
8383
params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err)
8484
} else if name != "" {
8585
sourceLabel = name
8686
}
8787
} else if model.SourceType == "snapshot" {
88-
name, err := iaasutils.GetSnapshotName(ctx, apiClient, model.ProjectId, model.SourceID)
88+
name, err := iaasutils.GetSnapshotName(ctx, apiClient, model.ProjectId, model.Region, model.SourceID)
8989
if err != nil {
9090
params.Printer.Debug(print.ErrorLevel, "get snapshot name: %v", err)
9191
} else if name != "" {
@@ -107,12 +107,16 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
107107
if err != nil {
108108
return fmt.Errorf("create volume backup: %w", err)
109109
}
110+
if resp == nil || resp.Id == nil {
111+
return fmt.Errorf("create volume: empty response")
112+
}
113+
volumeId := *resp.Id
110114

111115
// Wait for async operation, if async mode not enabled
112116
if !model.Async {
113117
s := spinner.New(params.Printer)
114118
s.Start("Creating backup")
115-
resp, err = wait.CreateBackupWaitHandler(ctx, apiClient, model.ProjectId, *resp.Id).WaitWithContext(ctx)
119+
resp, err = wait.CreateBackupWaitHandler(ctx, apiClient, model.ProjectId, model.Region, volumeId).WaitWithContext(ctx)
116120
if err != nil {
117121
return fmt.Errorf("wait for backup creation: %w", err)
118122
}
@@ -169,7 +173,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
169173
}
170174

171175
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateBackupRequest {
172-
req := apiClient.CreateBackup(ctx, model.ProjectId)
176+
req := apiClient.CreateBackup(ctx, model.ProjectId, model.Region)
173177

174178
payload := iaas.CreateBackupPayload{
175179
Name: model.Name,

internal/cmd/volume/backup/create/create_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import (
1616
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1717
)
1818

19-
type testCtxKey struct{}
20-
2119
const (
20+
testRegion = "eu01"
2221
testName = "my-backup"
2322
testSourceType = "volume"
2423
)
2524

25+
type testCtxKey struct{}
26+
2627
var (
2728
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2829
testClient = &iaas.APIClient{}
@@ -34,10 +35,12 @@ var (
3435
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3536
flagValues := map[string]string{
3637
globalflags.ProjectIdFlag: testProjectId,
37-
sourceIdFlag: testSourceId,
38-
sourceTypeFlag: testSourceType,
39-
nameFlag: testName,
40-
labelsFlag: "key1=value1",
38+
globalflags.RegionFlag: testRegion,
39+
40+
sourceIdFlag: testSourceId,
41+
sourceTypeFlag: testSourceType,
42+
nameFlag: testName,
43+
labelsFlag: "key1=value1",
4144
}
4245
for _, mod := range mods {
4346
mod(flagValues)
@@ -50,6 +53,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5053
GlobalFlagModel: &globalflags.GlobalFlagModel{
5154
ProjectId: testProjectId,
5255
Verbosity: globalflags.VerbosityDefault,
56+
Region: testRegion,
5357
},
5458
SourceID: testSourceId,
5559
SourceType: testSourceType,
@@ -63,7 +67,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6367
}
6468

6569
func fixtureRequest(mods ...func(request *iaas.ApiCreateBackupRequest)) iaas.ApiCreateBackupRequest {
66-
request := testClient.CreateBackup(testCtx, testProjectId)
70+
request := testClient.CreateBackup(testCtx, testProjectId, testRegion)
6771

6872
createPayload := iaas.NewCreateBackupPayloadWithDefaults()
6973
createPayload.Name = utils.Ptr(testName)

internal/cmd/volume/backup/delete/delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
5252
return err
5353
}
5454

55-
backupLabel, err := iaasutils.GetBackupName(ctx, apiClient, model.ProjectId, model.BackupId)
55+
backupLabel, err := iaasutils.GetBackupName(ctx, apiClient, model.ProjectId, model.Region, model.BackupId)
5656
if err != nil {
5757
params.Printer.Debug(print.ErrorLevel, "get backup name: %v", err)
5858
}
@@ -76,7 +76,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
7676
if !model.Async {
7777
s := spinner.New(params.Printer)
7878
s.Start("Deleting backup")
79-
_, err = wait.DeleteBackupWaitHandler(ctx, apiClient, model.ProjectId, model.BackupId).WaitWithContext(ctx)
79+
_, err = wait.DeleteBackupWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.BackupId).WaitWithContext(ctx)
8080
if err != nil {
8181
return fmt.Errorf("wait for backup deletion: %w", err)
8282
}
@@ -112,6 +112,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
112112
}
113113

114114
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteBackupRequest {
115-
req := apiClient.DeleteBackup(ctx, model.ProjectId, model.BackupId)
115+
req := apiClient.DeleteBackup(ctx, model.ProjectId, model.Region, model.BackupId)
116116
return req
117117
}

internal/cmd/volume/backup/delete/delete_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1414
)
1515

16+
const (
17+
testRegion = "eu01"
18+
)
19+
1620
type testCtxKey struct{}
1721

1822
var (
@@ -35,6 +39,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3539
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3640
flagValues := map[string]string{
3741
globalflags.ProjectIdFlag: testProjectId,
42+
globalflags.RegionFlag: testRegion,
3843
}
3944
for _, mod := range mods {
4045
mod(flagValues)
@@ -47,6 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4752
GlobalFlagModel: &globalflags.GlobalFlagModel{
4853
ProjectId: testProjectId,
4954
Verbosity: globalflags.VerbosityDefault,
55+
Region: testRegion,
5056
},
5157
BackupId: testBackupId,
5258
}
@@ -57,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5763
}
5864

5965
func fixtureRequest(mods ...func(request *iaas.ApiDeleteBackupRequest)) iaas.ApiDeleteBackupRequest {
60-
request := testClient.DeleteBackup(testCtx, testProjectId, testBackupId)
66+
request := testClient.DeleteBackup(testCtx, testProjectId, testRegion, testBackupId)
6167
for _, mod := range mods {
6268
mod(&request)
6369
}

internal/cmd/volume/backup/describe/describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
8686
}
8787

8888
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetBackupRequest {
89-
req := apiClient.GetBackup(ctx, model.ProjectId, model.BackupId)
89+
req := apiClient.GetBackup(ctx, model.ProjectId, model.Region, model.BackupId)
9090
return req
9191
}
9292

internal/cmd/volume/backup/describe/describe_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1616
)
1717

18+
const (
19+
testRegion = "eu01"
20+
)
21+
1822
type testCtxKey struct{}
1923

2024
var (
@@ -37,6 +41,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3741
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3842
flagValues := map[string]string{
3943
globalflags.ProjectIdFlag: testProjectId,
44+
globalflags.RegionFlag: testRegion,
4045
}
4146
for _, mod := range mods {
4247
mod(flagValues)
@@ -49,6 +54,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4954
GlobalFlagModel: &globalflags.GlobalFlagModel{
5055
ProjectId: testProjectId,
5156
Verbosity: globalflags.VerbosityDefault,
57+
Region: testRegion,
5258
},
5359
BackupId: testBackupId,
5460
}
@@ -59,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5965
}
6066

6167
func fixtureRequest(mods ...func(request *iaas.ApiGetBackupRequest)) iaas.ApiGetBackupRequest {
62-
request := testClient.GetBackup(testCtx, testProjectId, testBackupId)
68+
request := testClient.GetBackup(testCtx, testProjectId, testRegion, testBackupId)
6369
for _, mod := range mods {
6470
mod(&request)
6571
}

internal/cmd/volume/backup/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
126126
}
127127

128128
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListBackupsRequest {
129-
req := apiClient.ListBackups(ctx, model.ProjectId)
129+
req := apiClient.ListBackups(ctx, model.ProjectId, model.Region)
130130

131131
if model.LabelSelector != nil {
132132
req = req.LabelSelector(*model.LabelSelector)

internal/cmd/volume/backup/list/list_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import (
1616
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1717
)
1818

19+
const (
20+
testRegion = "eu01"
21+
)
22+
1923
type testCtxKey struct{}
2024

2125
var (
@@ -27,8 +31,10 @@ var (
2731
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2832
flagValues := map[string]string{
2933
globalflags.ProjectIdFlag: testProjectId,
30-
limitFlag: "10",
31-
labelSelectorFlag: "key1=value1",
34+
globalflags.RegionFlag: testRegion,
35+
36+
limitFlag: "10",
37+
labelSelectorFlag: "key1=value1",
3238
}
3339
for _, mod := range mods {
3440
mod(flagValues)
@@ -40,6 +46,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4046
model := &inputModel{
4147
GlobalFlagModel: &globalflags.GlobalFlagModel{
4248
ProjectId: testProjectId,
49+
Region: testRegion,
4350
Verbosity: globalflags.VerbosityDefault,
4451
},
4552
Limit: utils.Ptr(int64(10)),
@@ -52,7 +59,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5259
}
5360

5461
func fixtureRequest(mods ...func(request *iaas.ApiListBackupsRequest)) iaas.ApiListBackupsRequest {
55-
request := testClient.ListBackups(testCtx, testProjectId)
62+
request := testClient.ListBackups(testCtx, testProjectId, testRegion)
5663
request = request.LabelSelector("key1=value1")
5764
for _, mod := range mods {
5865
mod(&request)

internal/cmd/volume/backup/restore/restore.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
5252
return err
5353
}
5454

55-
backupLabel, err := iaasutils.GetBackupName(ctx, apiClient, model.ProjectId, model.BackupId)
55+
backupLabel, err := iaasutils.GetBackupName(ctx, apiClient, model.ProjectId, model.Region, model.BackupId)
5656
if err != nil {
5757
params.Printer.Debug(print.ErrorLevel, "get backup details: %v", err)
5858
}
5959

6060
// Get source details for labels
6161
var sourceLabel string
62-
backup, err := apiClient.GetBackup(ctx, model.ProjectId, model.BackupId).Execute()
62+
backup, err := apiClient.GetBackup(ctx, model.ProjectId, model.Region, model.BackupId).Execute()
6363
if err == nil && backup != nil && backup.VolumeId != nil {
6464
sourceLabel = *backup.VolumeId
65-
name, err := iaasutils.GetVolumeName(ctx, apiClient, model.ProjectId, *backup.VolumeId)
65+
name, err := iaasutils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, *backup.VolumeId)
6666
if err != nil {
6767
params.Printer.Debug(print.ErrorLevel, "get volume details: %v", err)
6868
} else if name != "" {
@@ -89,7 +89,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
8989
if !model.Async {
9090
s := spinner.New(params.Printer)
9191
s.Start("Restoring backup")
92-
_, err = wait.RestoreBackupWaitHandler(ctx, apiClient, model.ProjectId, model.BackupId).WaitWithContext(ctx)
92+
_, err = wait.RestoreBackupWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.BackupId).WaitWithContext(ctx)
9393
if err != nil {
9494
return fmt.Errorf("wait for backup restore: %w", err)
9595
}
@@ -125,6 +125,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
125125
}
126126

127127
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiRestoreBackupRequest {
128-
req := apiClient.RestoreBackup(ctx, model.ProjectId, model.BackupId)
128+
req := apiClient.RestoreBackup(ctx, model.ProjectId, model.Region, model.BackupId)
129129
return req
130130
}

internal/cmd/volume/backup/restore/restore_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1414
)
1515

16+
const (
17+
testRegion = "eu01"
18+
)
19+
1620
type testCtxKey struct{}
1721

1822
var (
@@ -35,6 +39,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3539
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3640
flagValues := map[string]string{
3741
globalflags.ProjectIdFlag: testProjectId,
42+
globalflags.RegionFlag: testRegion,
3843
}
3944
for _, mod := range mods {
4045
mod(flagValues)
@@ -47,6 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4752
GlobalFlagModel: &globalflags.GlobalFlagModel{
4853
ProjectId: testProjectId,
4954
Verbosity: globalflags.VerbosityDefault,
55+
Region: testRegion,
5056
},
5157
BackupId: testBackupId,
5258
}
@@ -57,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5763
}
5864

5965
func fixtureRequest(mods ...func(request *iaas.ApiRestoreBackupRequest)) iaas.ApiRestoreBackupRequest {
60-
request := testClient.RestoreBackup(testCtx, testProjectId, testBackupId)
66+
request := testClient.RestoreBackup(testCtx, testProjectId, testRegion, testBackupId)
6167
for _, mod := range mods {
6268
mod(&request)
6369
}

0 commit comments

Comments
 (0)