Skip to content

Commit d583439

Browse files
authored
chore(server): regional adjustment for server update (#662)
relates to STACKITCLI-128
1 parent 88dc956 commit d583439

File tree

24 files changed

+148
-109
lines changed

24 files changed

+148
-109
lines changed

docs/stackit_server_os-update_create.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ stackit server os-update create [flags]
1414

1515
```
1616
Create a Server os-update with name "myupdate"
17-
$ stackit server os-update create --server-id xxx --name=myupdate
17+
$ stackit server os-update create --server-id xxx
1818
1919
Create a Server os-update with name "myupdate" and maintenance window for 13 o'clock.
20-
$ stackit server os-update create --server-id xxx --name=mybupdate --maintenance-window=13
20+
$ stackit server os-update create --server-id xxx --maintenance-window=13
2121
```
2222

2323
### Options

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.0.0
2727
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.2
2828
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v0.6.0
29-
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v0.5.0
29+
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.0.0
3030
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.6.1
3131
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.0.1
3232
github.com/stackitcloud/stackit-sdk-go/services/ske v0.22.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.2 h1:SZoWUD
147147
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.2/go.mod h1:PrD0nNG94Dd5D9pu7HJ0bAg8ccDz6/7KaIts7K9p7as=
148148
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v0.6.0 h1:cESGAkm0ftADRBfdbiyx3pp/KVQ8JgmUQdRzpwG61wE=
149149
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v0.6.0/go.mod h1:aYPLsiImzWaYXEfYIZ0wJnV56PwcR+buy8Xu9jjbfGA=
150-
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v0.5.0 h1:TMUxDh8XGgWUpnWo7GsawVq2ICDsy/r8dMlfC26MR5g=
151-
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v0.5.0/go.mod h1:giHnHz3kHeLY8Av9MZLsyJlaTXYz+BuGqdP/SKB5Vo0=
150+
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.0.0 h1:a8logPoRcMCgwa9rCtuzWF6DLiuCIdJgcacZKThFsks=
151+
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.0.0/go.mod h1:zDdYYQVHGlju9cnMISX/Ty73Yh/qYcZGcJSOYWRZCbw=
152152
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.6.1 h1:VKgxgjsbaUVMCnntq+MLQ/c1Emn5crVr11B3gJnyHN4=
153153
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.6.1/go.mod h1:vn6xmMRxYgEoBhYEy6i2SY2qbeDKjs4IVNdnQHcQpBc=
154154
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.0.1 h1:7yY68QuntatwRG6ri65FlfeewACChLVbLp67wHCS8Go=

internal/cmd/server/os-update/create/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ func NewCmd(p *print.Printer) *cobra.Command {
4343
Example: examples.Build(
4444
examples.NewExample(
4545
`Create a Server os-update with name "myupdate"`,
46-
`$ stackit server os-update create --server-id xxx --name=myupdate`),
46+
`$ stackit server os-update create --server-id xxx`),
4747
examples.NewExample(
4848
`Create a Server os-update with name "myupdate" and maintenance window for 13 o'clock.`,
49-
`$ stackit server os-update create --server-id xxx --name=mybupdate --maintenance-window=13`),
49+
`$ stackit server os-update create --server-id xxx --maintenance-window=13`),
5050
),
5151
RunE: func(cmd *cobra.Command, _ []string) error {
5252
ctx := context.Background()
@@ -128,7 +128,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
128128
}
129129

130130
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) (serverupdate.ApiCreateUpdateRequest, error) {
131-
req := apiClient.CreateUpdate(ctx, model.ProjectId, model.ServerId)
131+
req := apiClient.CreateUpdate(ctx, model.ProjectId, model.ServerId, model.Region)
132132
payload := serverupdate.CreateUpdatePayload{
133133
MaintenanceWindow: &model.MaintenanceWindow,
134134
}

internal/cmd/server/os-update/create/create_test.go

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

17-
var projectIdFlag = globalflags.ProjectIdFlag
17+
const (
18+
testRegion = "eu02"
19+
)
1820

1921
type testCtxKey struct{}
2022

@@ -26,9 +28,10 @@ var testServerId = uuid.NewString()
2628

2729
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2830
flagValues := map[string]string{
29-
projectIdFlag: testProjectId,
30-
serverIdFlag: testServerId,
31-
maintenanceWindowFlag: "13",
31+
globalflags.ProjectIdFlag: testProjectId,
32+
globalflags.RegionFlag: testRegion,
33+
serverIdFlag: testServerId,
34+
maintenanceWindowFlag: "13",
3235
}
3336
for _, mod := range mods {
3437
mod(flagValues)
@@ -40,6 +43,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4043
model := &inputModel{
4144
GlobalFlagModel: &globalflags.GlobalFlagModel{
4245
ProjectId: testProjectId,
46+
Region: testRegion,
4347
Verbosity: globalflags.VerbosityDefault,
4448
},
4549
ServerId: testServerId,
@@ -52,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5256
}
5357

5458
func fixtureRequest(mods ...func(request *serverupdate.ApiCreateUpdateRequest)) serverupdate.ApiCreateUpdateRequest {
55-
request := testClient.CreateUpdate(testCtx, testProjectId, testServerId)
59+
request := testClient.CreateUpdate(testCtx, testProjectId, testServerId, testRegion)
5660
request = request.CreateUpdatePayload(fixturePayload())
5761
for _, mod := range mods {
5862
mod(&request)
@@ -102,21 +106,21 @@ func TestParseInput(t *testing.T) {
102106
{
103107
description: "project id missing",
104108
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
105-
delete(flagValues, projectIdFlag)
109+
delete(flagValues, globalflags.ProjectIdFlag)
106110
}),
107111
isValid: false,
108112
},
109113
{
110114
description: "project id invalid 1",
111115
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
112-
flagValues[projectIdFlag] = ""
116+
flagValues[globalflags.ProjectIdFlag] = ""
113117
}),
114118
isValid: false,
115119
},
116120
{
117121
description: "project id invalid 2",
118122
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
119-
flagValues[projectIdFlag] = "invalid-uuid"
123+
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
120124
}),
121125
isValid: false,
122126
},

internal/cmd/server/os-update/describe/describe.go

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

106106
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiGetUpdateRequest {
107-
req := apiClient.GetUpdate(ctx, model.ProjectId, model.ServerId, model.UpdateId)
107+
req := apiClient.GetUpdate(ctx, model.ProjectId, model.ServerId, model.UpdateId, model.Region)
108108
return req
109109
}
110110

internal/cmd/server/os-update/describe/describe_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
1414
)
1515

16-
var projectIdFlag = globalflags.ProjectIdFlag
16+
const (
17+
testRegion = "eu02"
18+
)
1719

1820
type testCtxKey struct{}
1921

@@ -35,8 +37,9 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3537

3638
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3739
flagValues := map[string]string{
38-
projectIdFlag: testProjectId,
39-
serverIdFlag: testServerId,
40+
globalflags.ProjectIdFlag: testProjectId,
41+
globalflags.RegionFlag: testRegion,
42+
serverIdFlag: testServerId,
4043
}
4144
for _, mod := range mods {
4245
mod(flagValues)
@@ -48,6 +51,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4851
model := &inputModel{
4952
GlobalFlagModel: &globalflags.GlobalFlagModel{
5053
ProjectId: testProjectId,
54+
Region: testRegion,
5155
Verbosity: globalflags.VerbosityDefault,
5256
},
5357
ServerId: testServerId,
@@ -60,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6064
}
6165

6266
func fixtureRequest(mods ...func(request *serverupdate.ApiGetUpdateRequest)) serverupdate.ApiGetUpdateRequest {
63-
request := testClient.GetUpdate(testCtx, testProjectId, testServerId, testUpdateId)
67+
request := testClient.GetUpdate(testCtx, testProjectId, testServerId, testUpdateId, testRegion)
6468
for _, mod := range mods {
6569
mod(&request)
6670
}
@@ -104,23 +108,23 @@ func TestParseInput(t *testing.T) {
104108
description: "project id missing",
105109
argValues: fixtureArgValues(),
106110
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
107-
delete(flagValues, projectIdFlag)
111+
delete(flagValues, globalflags.ProjectIdFlag)
108112
}),
109113
isValid: false,
110114
},
111115
{
112116
description: "project id invalid 1",
113117
argValues: fixtureArgValues(),
114118
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
115-
flagValues[projectIdFlag] = ""
119+
flagValues[globalflags.ProjectIdFlag] = ""
116120
}),
117121
isValid: false,
118122
},
119123
{
120124
description: "project id invalid 2",
121125
argValues: fixtureArgValues(),
122126
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
123-
flagValues[projectIdFlag] = "invalid-uuid"
127+
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
124128
}),
125129
isValid: false,
126130
},

internal/cmd/server/os-update/disable/disable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
115115
return &model, nil
116116
}
117117

118-
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiDisableServiceRequest {
119-
req := apiClient.DisableService(ctx, model.ProjectId, model.ServerId)
118+
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiDisableServiceResourceRequest {
119+
req := apiClient.DisableServiceResource(ctx, model.ProjectId, model.ServerId, model.Region)
120120
return req
121121
}

internal/cmd/server/os-update/disable/disable_test.go

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

17-
var projectIdFlag = globalflags.ProjectIdFlag
17+
const (
18+
testRegion = "eu02"
19+
)
1820

1921
type testCtxKey struct{}
2022

@@ -25,7 +27,8 @@ var testServerId = uuid.NewString()
2527

2628
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2729
flagValues := map[string]string{
28-
projectIdFlag: testProjectId,
30+
globalflags.ProjectIdFlag: testProjectId,
31+
globalflags.RegionFlag: testRegion,
2932
}
3033
for _, mod := range mods {
3134
mod(flagValues)
@@ -37,6 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
3740
model := &inputModel{
3841
GlobalFlagModel: &globalflags.GlobalFlagModel{
3942
ProjectId: testProjectId,
43+
Region: testRegion,
4044
Verbosity: globalflags.VerbosityDefault,
4145
},
4246
ServerId: testServerId,
@@ -47,8 +51,8 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4751
return model
4852
}
4953

50-
func fixtureRequest(mods ...func(request *serverupdate.ApiDisableServiceRequest)) serverupdate.ApiDisableServiceRequest {
51-
request := testClient.DisableService(testCtx, testProjectId, testServerId)
54+
func fixtureRequest(mods ...func(request *serverupdate.ApiDisableServiceResourceRequest)) serverupdate.ApiDisableServiceResourceRequest {
55+
request := testClient.DisableServiceResource(testCtx, testProjectId, testServerId, testRegion)
5256
for _, mod := range mods {
5357
mod(&request)
5458
}
@@ -78,21 +82,21 @@ func TestParseInput(t *testing.T) {
7882
{
7983
description: "project id missing",
8084
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
81-
delete(flagValues, projectIdFlag)
85+
delete(flagValues, globalflags.ProjectIdFlag)
8286
}),
8387
isValid: false,
8488
},
8589
{
8690
description: "project id invalid 1",
8791
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
88-
flagValues[projectIdFlag] = ""
92+
flagValues[globalflags.ProjectIdFlag] = ""
8993
}),
9094
isValid: false,
9195
},
9296
{
9397
description: "project id invalid 2",
9498
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
95-
flagValues[projectIdFlag] = "invalid-uuid"
99+
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
96100
}),
97101
isValid: false,
98102
},
@@ -148,7 +152,7 @@ func TestBuildRequest(t *testing.T) {
148152
tests := []struct {
149153
description string
150154
model *inputModel
151-
expectedRequest serverupdate.ApiDisableServiceRequest
155+
expectedRequest serverupdate.ApiDisableServiceResourceRequest
152156
}{
153157
{
154158
description: "base",

internal/cmd/server/os-update/enable/enable.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
118118
return &model, nil
119119
}
120120

121-
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiEnableServiceRequest {
122-
payload := serverupdate.EnableServicePayload{}
123-
req := apiClient.EnableService(ctx, model.ProjectId, model.ServerId).EnableServicePayload(payload)
121+
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiEnableServiceResourceRequest {
122+
payload := serverupdate.EnableServiceResourcePayload{}
123+
req := apiClient.EnableServiceResource(ctx, model.ProjectId, model.ServerId, model.Region).EnableServiceResourcePayload(payload)
124124
return req
125125
}

0 commit comments

Comments
 (0)