Skip to content

Commit 95cf0d1

Browse files
committed
adjust images commands
1 parent b131ac3 commit 95cf0d1

File tree

10 files changed

+125
-76
lines changed

10 files changed

+125
-76
lines changed

internal/cmd/image/create/create.go

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

334334
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateImageRequest {
335-
request := apiClient.CreateImage(ctx, model.ProjectId).
335+
request := apiClient.CreateImage(ctx, model.ProjectId, model.Region).
336336
CreateImagePayload(createPayload(ctx, model))
337337
return request
338338
}

internal/cmd/image/create/create_test.go

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ import (
1717
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1818
)
1919

20-
var projectIdFlag = globalflags.ProjectIdFlag
21-
22-
type testCtxKey struct{}
23-
24-
var (
25-
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
26-
testClient = &iaas.APIClient{}
27-
testProjectId = uuid.NewString()
20+
const (
21+
projectIdFlag = globalflags.ProjectIdFlag
22+
regionFlag = globalflags.RegionFlag
2823

24+
testRegion = "eu01"
2925
testLocalImagePath = "/does/not/exist"
3026
testDiskFormat = "raw"
3127
testDiskSize int64 = 16 * 1024 * 1024 * 1024
@@ -49,9 +45,18 @@ var (
4945
testLabels = "foo=FOO,bar=BAR,baz=BAZ"
5046
)
5147

48+
type testCtxKey struct{}
49+
50+
var (
51+
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
52+
testClient = &iaas.APIClient{}
53+
testProjectId = uuid.NewString()
54+
)
55+
5256
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
5357
flagValues := map[string]string{
5458
projectIdFlag: testProjectId,
59+
regionFlag: testRegion,
5560

5661
nameFlag: testName,
5762
diskFormatFlag: testDiskFormat,
@@ -93,30 +98,34 @@ func parseLabels(labelstring string) map[string]string {
9398

9499
func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
95100
model := &inputModel{
96-
GlobalFlagModel: &globalflags.GlobalFlagModel{ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault},
97-
Name: testName,
98-
DiskFormat: testDiskFormat,
99-
LocalFilePath: testLocalImagePath,
100-
Labels: utils.Ptr(parseLabels(testLabels)),
101+
GlobalFlagModel: &globalflags.GlobalFlagModel{
102+
ProjectId: testProjectId,
103+
Verbosity: globalflags.VerbosityDefault,
104+
Region: testRegion,
105+
},
106+
Name: testName,
107+
DiskFormat: testDiskFormat,
108+
LocalFilePath: testLocalImagePath,
109+
Labels: utils.Ptr(parseLabels(testLabels)),
101110
Config: &imageConfig{
102-
Architecture: &testArchitecture,
103-
BootMenu: &testBootmenu,
104-
CdromBus: &testCdRomBus,
105-
DiskBus: &testDiskBus,
106-
NicModel: &testNicModel,
107-
OperatingSystem: &testOperatingSystem,
108-
OperatingSystemDistro: &testOperatingSystemDistro,
109-
OperatingSystemVersion: &testOperatingSystemVersion,
110-
RescueBus: &testRescueBus,
111-
RescueDevice: &testRescueDevice,
112-
SecureBoot: &testSecureBoot,
111+
Architecture: utils.Ptr(testArchitecture),
112+
BootMenu: utils.Ptr(testBootmenu),
113+
CdromBus: utils.Ptr(testCdRomBus),
114+
DiskBus: utils.Ptr(testDiskBus),
115+
NicModel: utils.Ptr(testNicModel),
116+
OperatingSystem: utils.Ptr(testOperatingSystem),
117+
OperatingSystemDistro: utils.Ptr(testOperatingSystemDistro),
118+
OperatingSystemVersion: utils.Ptr(testOperatingSystemVersion),
119+
RescueBus: utils.Ptr(testRescueBus),
120+
RescueDevice: utils.Ptr(testRescueDevice),
121+
SecureBoot: utils.Ptr(testSecureBoot),
113122
Uefi: testUefi,
114-
VideoModel: &testVideoModel,
115-
VirtioScsi: &testVirtioScsi,
123+
VideoModel: utils.Ptr(testVideoModel),
124+
VirtioScsi: utils.Ptr(testVirtioScsi),
116125
},
117-
MinDiskSize: &testDiskSize,
118-
MinRam: &testRamSize,
119-
Protected: &testProtected,
126+
MinDiskSize: utils.Ptr(testDiskSize),
127+
MinRam: utils.Ptr(testRamSize),
128+
Protected: utils.Ptr(testProtected),
120129
}
121130
for _, mod := range mods {
122131
mod(model)
@@ -127,31 +136,31 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
127136
func fixtureCreatePayload(mods ...func(payload *iaas.CreateImagePayload)) (payload iaas.CreateImagePayload) {
128137
payload = iaas.CreateImagePayload{
129138
Config: &iaas.ImageConfig{
130-
Architecture: &testArchitecture,
131-
BootMenu: &testBootmenu,
132-
CdromBus: iaas.NewNullableString(&testCdRomBus),
133-
DiskBus: iaas.NewNullableString(&testDiskBus),
134-
NicModel: iaas.NewNullableString(&testNicModel),
135-
OperatingSystem: &testOperatingSystem,
136-
OperatingSystemDistro: iaas.NewNullableString(&testOperatingSystemDistro),
137-
OperatingSystemVersion: iaas.NewNullableString(&testOperatingSystemVersion),
138-
RescueBus: iaas.NewNullableString(&testRescueBus),
139-
RescueDevice: iaas.NewNullableString(&testRescueDevice),
140-
SecureBoot: &testSecureBoot,
141-
Uefi: &testUefi,
142-
VideoModel: iaas.NewNullableString(&testVideoModel),
143-
VirtioScsi: &testVirtioScsi,
139+
Architecture: utils.Ptr(testArchitecture),
140+
BootMenu: utils.Ptr(testBootmenu),
141+
CdromBus: iaas.NewNullableString(utils.Ptr(testCdRomBus)),
142+
DiskBus: iaas.NewNullableString(utils.Ptr(testDiskBus)),
143+
NicModel: iaas.NewNullableString(utils.Ptr(testNicModel)),
144+
OperatingSystem: utils.Ptr(testOperatingSystem),
145+
OperatingSystemDistro: iaas.NewNullableString(utils.Ptr(testOperatingSystemDistro)),
146+
OperatingSystemVersion: iaas.NewNullableString(utils.Ptr(testOperatingSystemVersion)),
147+
RescueBus: iaas.NewNullableString(utils.Ptr(testRescueBus)),
148+
RescueDevice: iaas.NewNullableString(utils.Ptr(testRescueDevice)),
149+
SecureBoot: utils.Ptr(testSecureBoot),
150+
Uefi: utils.Ptr(testUefi),
151+
VideoModel: iaas.NewNullableString(utils.Ptr(testVideoModel)),
152+
VirtioScsi: utils.Ptr(testVirtioScsi),
144153
},
145-
DiskFormat: &testDiskFormat,
154+
DiskFormat: utils.Ptr(testDiskFormat),
146155
Labels: &map[string]interface{}{
147156
"foo": "FOO",
148157
"bar": "BAR",
149158
"baz": "BAZ",
150159
},
151-
MinDiskSize: &testDiskSize,
152-
MinRam: &testRamSize,
153-
Name: &testName,
154-
Protected: &testProtected,
160+
MinDiskSize: utils.Ptr(testDiskSize),
161+
MinRam: utils.Ptr(testRamSize),
162+
Name: utils.Ptr(testName),
163+
Protected: utils.Ptr(testProtected),
155164
}
156165
for _, mod := range mods {
157166
mod(&payload)
@@ -160,7 +169,7 @@ func fixtureCreatePayload(mods ...func(payload *iaas.CreateImagePayload)) (paylo
160169
}
161170

162171
func fixtureRequest(mods ...func(request *iaas.ApiCreateImageRequest)) iaas.ApiCreateImageRequest {
163-
request := testClient.CreateImage(testCtx, testProjectId)
172+
request := testClient.CreateImage(testCtx, testProjectId, testRegion)
164173

165174
request = request.CreateImagePayload(fixtureCreatePayload())
166175

internal/cmd/image/delete/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
5353
projectLabel = model.ProjectId
5454
}
5555

56-
imageName, err := iaasUtils.GetImageName(ctx, apiClient, model.ProjectId, model.ImageId)
56+
imageName, err := iaasUtils.GetImageName(ctx, apiClient, model.ProjectId, model.Region, model.ImageId)
5757
if err != nil {
5858
params.Printer.Debug(print.ErrorLevel, "get image name: %v", err)
5959
imageName = model.ImageId
@@ -98,6 +98,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM
9898
}
9999

100100
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteImageRequest {
101-
request := apiClient.DeleteImage(ctx, model.ProjectId, model.ImageId)
101+
request := apiClient.DeleteImage(ctx, model.ProjectId, model.Region, model.ImageId)
102102
return request
103103
}

internal/cmd/image/delete/delete_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import (
1414
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1515
)
1616

17-
var projectIdFlag = globalflags.ProjectIdFlag
17+
const (
18+
projectIdFlag = globalflags.ProjectIdFlag
19+
regionFlag = globalflags.RegionFlag
20+
21+
testRegion = "eu01"
22+
)
1823

1924
type testCtxKey struct{}
2025

@@ -28,6 +33,7 @@ var (
2833
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2934
flagValues := map[string]string{
3035
projectIdFlag: testProjectId,
36+
regionFlag: testRegion,
3137
}
3238
for _, mod := range mods {
3339
mod(flagValues)
@@ -37,8 +43,12 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
3743

3844
func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
3945
model := &inputModel{
40-
GlobalFlagModel: &globalflags.GlobalFlagModel{ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault},
41-
ImageId: testImageId,
46+
GlobalFlagModel: &globalflags.GlobalFlagModel{
47+
ProjectId: testProjectId,
48+
Verbosity: globalflags.VerbosityDefault,
49+
Region: testRegion,
50+
},
51+
ImageId: testImageId,
4252
}
4353
for _, mod := range mods {
4454
mod(model)
@@ -47,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4757
}
4858

4959
func fixtureRequest(mods ...func(request *iaas.ApiDeleteImageRequest)) iaas.ApiDeleteImageRequest {
50-
request := testClient.DeleteImage(testCtx, testProjectId, testImageId)
60+
request := testClient.DeleteImage(testCtx, testProjectId, testRegion, testImageId)
5161
for _, mod := range mods {
5262
mod(&request)
5363
}

internal/cmd/image/describe/describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
6767
}
6868

6969
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetImageRequest {
70-
request := apiClient.GetImage(ctx, model.ProjectId, model.ImageId)
70+
request := apiClient.GetImage(ctx, model.ProjectId, model.Region, model.ImageId)
7171
return request
7272
}
7373

internal/cmd/image/describe/describe_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import (
1414
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1515
)
1616

17-
var projectIdFlag = globalflags.ProjectIdFlag
17+
const (
18+
projectIdFlag = globalflags.ProjectIdFlag
19+
regionFlag = globalflags.RegionFlag
20+
21+
testRegion = "eu01"
22+
)
1823

1924
type testCtxKey struct{}
2025

@@ -28,6 +33,7 @@ var (
2833
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2934
flagValues := map[string]string{
3035
projectIdFlag: testProjectId,
36+
regionFlag: testRegion,
3137
}
3238
for _, mod := range mods {
3339
mod(flagValues)
@@ -37,8 +43,12 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
3743

3844
func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
3945
model := &inputModel{
40-
GlobalFlagModel: &globalflags.GlobalFlagModel{ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault},
41-
ImageId: testImageId[0],
46+
GlobalFlagModel: &globalflags.GlobalFlagModel{
47+
ProjectId: testProjectId,
48+
Verbosity: globalflags.VerbosityDefault,
49+
Region: testRegion,
50+
},
51+
ImageId: testImageId[0],
4252
}
4353
for _, mod := range mods {
4454
mod(model)
@@ -47,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4757
}
4858

4959
func fixtureRequest(mods ...func(request *iaas.ApiGetImageRequest)) iaas.ApiGetImageRequest {
50-
request := testClient.GetImage(testCtx, testProjectId, testImageId[0])
60+
request := testClient.GetImage(testCtx, testProjectId, testRegion, testImageId[0])
5161
for _, mod := range mods {
5262
mod(&request)
5363
}

internal/cmd/image/list/list.go

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

130130
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListImagesRequest {
131-
request := apiClient.ListImages(ctx, model.ProjectId)
131+
request := apiClient.ListImages(ctx, model.ProjectId, model.Region)
132132
if model.LabelSelector != nil {
133133
request = request.LabelSelector(*model.LabelSelector)
134134
}

internal/cmd/image/list/list_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ import (
1717
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1818
)
1919

20-
var projectIdFlag = globalflags.ProjectIdFlag
20+
const (
21+
projectIdFlag = globalflags.ProjectIdFlag
22+
regionFlag = globalflags.RegionFlag
23+
24+
testRegion = "eu01"
25+
)
2126

2227
type testCtxKey struct{}
2328

@@ -34,6 +39,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
3439
projectIdFlag: testProjectId,
3540
labelSelectorFlag: testLabels,
3641
limitFlag: strconv.Itoa(int(testLimit)),
42+
regionFlag: testRegion,
3743
}
3844
for _, mod := range mods {
3945
mod(flagValues)
@@ -43,9 +49,13 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
4349

4450
func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4551
model := &inputModel{
46-
GlobalFlagModel: &globalflags.GlobalFlagModel{ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault},
47-
LabelSelector: utils.Ptr(testLabels),
48-
Limit: &testLimit,
52+
GlobalFlagModel: &globalflags.GlobalFlagModel{
53+
ProjectId: testProjectId,
54+
Verbosity: globalflags.VerbosityDefault,
55+
Region: testRegion,
56+
},
57+
LabelSelector: utils.Ptr(testLabels),
58+
Limit: &testLimit,
4959
}
5060
for _, mod := range mods {
5161
mod(model)
@@ -54,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5464
}
5565

5666
func fixtureRequest(mods ...func(request *iaas.ApiListImagesRequest)) iaas.ApiListImagesRequest {
57-
request := testClient.ListImages(testCtx, testProjectId)
67+
request := testClient.ListImages(testCtx, testProjectId, testRegion)
5868
request = request.LabelSelector(testLabels)
5969
for _, mod := range mods {
6070
mod(&request)

internal/cmd/image/update/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
132132
projectLabel = model.ProjectId
133133
}
134134

135-
imageLabel, err := iaasUtils.GetImageName(ctx, apiClient, model.ProjectId, model.Id)
135+
imageLabel, err := iaasUtils.GetImageName(ctx, apiClient, model.ProjectId, model.Region, model.Id)
136136
if err != nil {
137137
params.Printer.Debug(print.WarningLevel, "cannot retrieve image name: %v", err)
138138
imageLabel = model.Id
@@ -238,7 +238,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM
238238
}
239239

240240
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateImageRequest {
241-
request := apiClient.UpdateImage(ctx, model.ProjectId, model.Id)
241+
request := apiClient.UpdateImage(ctx, model.ProjectId, model.Region, model.Id)
242242
payload := iaas.NewUpdateImagePayload()
243243

244244
// Config *ImageConfig `json:"config,omitempty"`

0 commit comments

Comments
 (0)