Skip to content

Commit dbf5bea

Browse files
committed
adjust volume commands
1 parent 620d67a commit dbf5bea

38 files changed

+277
-112
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: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ import (
1616
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1717
)
1818

19-
type testCtxKey struct{}
20-
2119
const (
20+
projectIdFlag = globalflags.ProjectIdFlag
21+
regionFlag = globalflags.RegionFlag
22+
23+
testRegion = "eu01"
2224
testName = "my-backup"
2325
testSourceType = "volume"
2426
)
2527

28+
type testCtxKey struct{}
29+
2630
var (
2731
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2832
testClient = &iaas.APIClient{}
@@ -33,11 +37,13 @@ var (
3337

3438
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3539
flagValues := map[string]string{
36-
globalflags.ProjectIdFlag: testProjectId,
37-
sourceIdFlag: testSourceId,
38-
sourceTypeFlag: testSourceType,
39-
nameFlag: testName,
40-
labelsFlag: "key1=value1",
40+
projectIdFlag: testProjectId,
41+
regionFlag: testRegion,
42+
43+
sourceIdFlag: testSourceId,
44+
sourceTypeFlag: testSourceType,
45+
nameFlag: testName,
46+
labelsFlag: "key1=value1",
4147
}
4248
for _, mod := range mods {
4349
mod(flagValues)
@@ -50,6 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5056
GlobalFlagModel: &globalflags.GlobalFlagModel{
5157
ProjectId: testProjectId,
5258
Verbosity: globalflags.VerbosityDefault,
59+
Region: testRegion,
5360
},
5461
SourceID: testSourceId,
5562
SourceType: testSourceType,
@@ -63,7 +70,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6370
}
6471

6572
func fixtureRequest(mods ...func(request *iaas.ApiCreateBackupRequest)) iaas.ApiCreateBackupRequest {
66-
request := testClient.CreateBackup(testCtx, testProjectId)
73+
request := testClient.CreateBackup(testCtx, testProjectId, testRegion)
6774

6875
createPayload := iaas.NewCreateBackupPayloadWithDefaults()
6976
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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import (
1313
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1414
)
1515

16+
const (
17+
projectIdFlag = globalflags.ProjectIdFlag
18+
regionFlag = globalflags.RegionFlag
19+
20+
testRegion = "eu01"
21+
)
22+
1623
type testCtxKey struct{}
1724

1825
var (
@@ -34,7 +41,8 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3441

3542
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3643
flagValues := map[string]string{
37-
globalflags.ProjectIdFlag: testProjectId,
44+
projectIdFlag: testProjectId,
45+
regionFlag: testRegion,
3846
}
3947
for _, mod := range mods {
4048
mod(flagValues)
@@ -47,6 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4755
GlobalFlagModel: &globalflags.GlobalFlagModel{
4856
ProjectId: testProjectId,
4957
Verbosity: globalflags.VerbosityDefault,
58+
Region: testRegion,
5059
},
5160
BackupId: testBackupId,
5261
}
@@ -57,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5766
}
5867

5968
func fixtureRequest(mods ...func(request *iaas.ApiDeleteBackupRequest)) iaas.ApiDeleteBackupRequest {
60-
request := testClient.DeleteBackup(testCtx, testProjectId, testBackupId)
69+
request := testClient.DeleteBackup(testCtx, testProjectId, testRegion, testBackupId)
6170
for _, mod := range mods {
6271
mod(&request)
6372
}

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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import (
1515
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1616
)
1717

18+
const (
19+
projectIdFlag = globalflags.ProjectIdFlag
20+
regionFlag = globalflags.RegionFlag
21+
22+
testRegion = "eu01"
23+
)
24+
1825
type testCtxKey struct{}
1926

2027
var (
@@ -36,7 +43,8 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3643

3744
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3845
flagValues := map[string]string{
39-
globalflags.ProjectIdFlag: testProjectId,
46+
projectIdFlag: testProjectId,
47+
regionFlag: testRegion,
4048
}
4149
for _, mod := range mods {
4250
mod(flagValues)
@@ -49,6 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4957
GlobalFlagModel: &globalflags.GlobalFlagModel{
5058
ProjectId: testProjectId,
5159
Verbosity: globalflags.VerbosityDefault,
60+
Region: testRegion,
5261
},
5362
BackupId: testBackupId,
5463
}
@@ -59,7 +68,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5968
}
6069

6170
func fixtureRequest(mods ...func(request *iaas.ApiGetBackupRequest)) iaas.ApiGetBackupRequest {
62-
request := testClient.GetBackup(testCtx, testProjectId, testBackupId)
71+
request := testClient.GetBackup(testCtx, testProjectId, testRegion, testBackupId)
6372
for _, mod := range mods {
6473
mod(&request)
6574
}

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: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ import (
1616
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1717
)
1818

19+
const (
20+
projectIdFlag = globalflags.ProjectIdFlag
21+
regionFlag = globalflags.RegionFlag
22+
23+
testRegion = "eu01"
24+
)
25+
1926
type testCtxKey struct{}
2027

2128
var (
@@ -26,9 +33,11 @@ var (
2633

2734
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2835
flagValues := map[string]string{
29-
globalflags.ProjectIdFlag: testProjectId,
30-
limitFlag: "10",
31-
labelSelectorFlag: "key1=value1",
36+
projectIdFlag: testProjectId,
37+
regionFlag: testRegion,
38+
39+
limitFlag: "10",
40+
labelSelectorFlag: "key1=value1",
3241
}
3342
for _, mod := range mods {
3443
mod(flagValues)
@@ -40,6 +49,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4049
model := &inputModel{
4150
GlobalFlagModel: &globalflags.GlobalFlagModel{
4251
ProjectId: testProjectId,
52+
Region: testRegion,
4353
Verbosity: globalflags.VerbosityDefault,
4454
},
4555
Limit: utils.Ptr(int64(10)),
@@ -52,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5262
}
5363

5464
func fixtureRequest(mods ...func(request *iaas.ApiListBackupsRequest)) iaas.ApiListBackupsRequest {
55-
request := testClient.ListBackups(testCtx, testProjectId)
65+
request := testClient.ListBackups(testCtx, testProjectId, testRegion)
5666
request = request.LabelSelector("key1=value1")
5767
for _, mod := range mods {
5868
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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import (
1313
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1414
)
1515

16+
const (
17+
projectIdFlag = globalflags.ProjectIdFlag
18+
regionFlag = globalflags.RegionFlag
19+
20+
testRegion = "eu01"
21+
)
22+
1623
type testCtxKey struct{}
1724

1825
var (
@@ -34,7 +41,8 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3441

3542
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3643
flagValues := map[string]string{
37-
globalflags.ProjectIdFlag: testProjectId,
44+
projectIdFlag: testProjectId,
45+
regionFlag: testRegion,
3846
}
3947
for _, mod := range mods {
4048
mod(flagValues)
@@ -47,6 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4755
GlobalFlagModel: &globalflags.GlobalFlagModel{
4856
ProjectId: testProjectId,
4957
Verbosity: globalflags.VerbosityDefault,
58+
Region: testRegion,
5059
},
5160
BackupId: testBackupId,
5261
}
@@ -57,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5766
}
5867

5968
func fixtureRequest(mods ...func(request *iaas.ApiRestoreBackupRequest)) iaas.ApiRestoreBackupRequest {
60-
request := testClient.RestoreBackup(testCtx, testProjectId, testBackupId)
69+
request := testClient.RestoreBackup(testCtx, testProjectId, testRegion, testBackupId)
6170
for _, mod := range mods {
6271
mod(&request)
6372
}

0 commit comments

Comments
 (0)