Skip to content
Merged
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
6 changes: 3 additions & 3 deletions docs/stackit_server_os-update_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ stackit server os-update create [flags]
### Options

```
-h, --help Help for "stackit server os-update create"
-m, --maintenance-window int Maintenance window (in hours, 1-24) (default 23)
-s, --server-id string Server ID
-h, --help Help for "stackit server os-update create"
-m, --maintenance-window int32 Maintenance window (in hours, 1-24) (default 23)
-s, --server-id string Server ID
```

### Options inherited from parent commands
Expand Down
12 changes: 6 additions & 6 deletions docs/stackit_server_os-update_schedule_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ stackit server os-update schedule create [flags]
### Options

```
-e, --enabled Is the server os-update schedule enabled (default true)
-h, --help Help for "stackit server os-update schedule create"
-d, --maintenance-window int os-update maintenance window (in hours, 1-24) (default 23)
-n, --name string os-update schedule name
-r, --rrule string os-update RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
-s, --server-id string Server ID
-e, --enabled Is the server os-update schedule enabled (default true)
-h, --help Help for "stackit server os-update schedule create"
-d, --maintenance-window int32 os-update maintenance window (in hours, 1-24) (default 23)
-n, --name string os-update schedule name
-r, --rrule string os-update RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
-s, --server-id string Server ID
```

### Options inherited from parent commands
Expand Down
12 changes: 6 additions & 6 deletions docs/stackit_server_os-update_schedule_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ stackit server os-update schedule update SCHEDULE_ID [flags]
### Options

```
-e, --enabled Is the server os-update schedule enabled (default true)
-h, --help Help for "stackit server os-update schedule update"
-d, --maintenance-window int Maintenance window (in hours, 1-24) (default 23)
-n, --name string os-update schedule name
-r, --rrule string os-update RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
-s, --server-id string Server ID
-e, --enabled Is the server os-update schedule enabled (default true)
-h, --help Help for "stackit server os-update schedule update"
-d, --maintenance-window int32 Maintenance window (in hours, 1-24) (default 23)
-n, --name string os-update schedule name
-r, --rrule string os-update RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
-s, --server-id string Server ID
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.8.0
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.2
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7
github.com/stackitcloud/stackit-sdk-go/services/ske v1.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1 h1:U5rstX
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1/go.mod h1:2XA8PE05Qg6BL2YXO4XgfGI9qskJ3cicLE5Qq0aqDdY=
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8 h1:LLyANBzE8sQa0/49tQBqq4sVLhNgwdqCeQm76srJHWw=
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8/go.mod h1:/bmg57XZu+bGczzcoumrukiGMPGzI2mOyTT4BVIQUBs=
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6 h1:sQ3fdtUjgIL2Ul8nRYVVacHOwi5aSMTGGbYVL30oQBU=
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6/go.mod h1:3fjlL+9YtuI9Oocl1ZeYIK48ImtY4DwPggFhqAygr7o=
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.2 h1:6C/iTPoYPCrZOc3JMmvyDNs4hm+JR5p9O3DIfFGgnbo=
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.2/go.mod h1:/OHYZXQb9KXDdZK5J9C2YS6DJUD2i6ednZ1rK7zpDZ0=
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0 h1:l1EDIlXce2C8JcbBDHVa6nZ4SjPTqmnALTgrhms+NKI=
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0/go.mod h1:EXq8/J7t9p8zPmdIq+atuxyAbnQwxrQT18fI+Qpv98k=
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7 h1:M2PYLF8k3zmAwYWSKfUiCTNTXr7ROGuJganVVEQA3YI=
Expand Down
27 changes: 15 additions & 12 deletions internal/cmd/server/os-update/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (

iaasClient "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"

"github.com/spf13/cobra"
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
Expand All @@ -16,10 +19,6 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
)

const (
Expand All @@ -32,7 +31,7 @@ type inputModel struct {
*globalflags.GlobalFlagModel

ServerId string
MaintenanceWindow int64
MaintenanceWindow int32
}

func NewCmd(params *types.CmdParams) *cobra.Command {
Expand Down Expand Up @@ -90,7 +89,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return fmt.Errorf("create Server os-update: %w", err)
}

return outputResult(params.Printer, model.OutputFormat, serverLabel, *resp)
return outputResult(params.Printer, model.OutputFormat, serverLabel, resp)
},
}
configureFlags(cmd)
Expand All @@ -99,7 +98,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {

func configureFlags(cmd *cobra.Command) {
cmd.Flags().VarP(flags.UUIDFlag(), serverIdFlag, "s", "Server ID")
cmd.Flags().Int64P(maintenanceWindowFlag, "m", defaultMaintenanceWindow, "Maintenance window (in hours, 1-24)")
cmd.Flags().Int32P(maintenanceWindowFlag, "m", defaultMaintenanceWindow, "Maintenance window (in hours, 1-24)")
}

func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
Expand All @@ -111,25 +110,29 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
model := inputModel{
GlobalFlagModel: globalFlags,
ServerId: flags.FlagToStringValue(p, cmd, serverIdFlag),
MaintenanceWindow: flags.FlagWithDefaultToInt64Value(p, cmd, maintenanceWindowFlag),
MaintenanceWindow: flags.FlagWithDefaultToInt32Value(p, cmd, maintenanceWindowFlag),
}

p.DebugInputModel(model)
return &model, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) (serverupdate.ApiCreateUpdateRequest, error) {
req := apiClient.CreateUpdate(ctx, model.ProjectId, model.ServerId, model.Region)
req := apiClient.DefaultAPI.CreateUpdate(ctx, model.ProjectId, model.ServerId, model.Region)
payload := serverupdate.CreateUpdatePayload{
MaintenanceWindow: &model.MaintenanceWindow,
MaintenanceWindow: model.MaintenanceWindow,
}
req = req.CreateUpdatePayload(payload)
return req, nil
}

func outputResult(p *print.Printer, outputFormat, serverLabel string, resp serverupdate.Update) error {
func outputResult(p *print.Printer, outputFormat, serverLabel string, resp *serverupdate.Update) error {
return p.OutputResult(outputFormat, resp, func() error {
p.Outputf("Triggered creation of server os-update for server %s. Update ID: %s\n", serverLabel, utils.PtrString(resp.Id))
if resp == nil {
return fmt.Errorf("response is nil")
}

p.Outputf("Triggered creation of server os-update for server %s. Update ID: %d\n", serverLabel, resp.Id)
return nil
})
}
39 changes: 25 additions & 14 deletions internal/cmd/server/os-update/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"context"
"testing"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
)

const (
Expand All @@ -22,7 +22,7 @@ const (
type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serverupdate.APIClient{}
var testClient = &serverupdate.APIClient{DefaultAPI: &serverupdate.DefaultAPIService{}}

var testProjectId = uuid.NewString()
var testServerId = uuid.NewString()
Expand All @@ -48,7 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
Verbosity: globalflags.VerbosityDefault,
},
ServerId: testServerId,
MaintenanceWindow: int64(13),
MaintenanceWindow: int32(13),
}
for _, mod := range mods {
mod(model)
Expand All @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *serverupdate.ApiCreateUpdateRequest)) serverupdate.ApiCreateUpdateRequest {
request := testClient.CreateUpdate(testCtx, testProjectId, testServerId, testRegion)
request := testClient.DefaultAPI.CreateUpdate(testCtx, testProjectId, testServerId, testRegion)
request = request.CreateUpdatePayload(fixturePayload())
for _, mod := range mods {
mod(&request)
Expand All @@ -67,7 +67,7 @@ func fixtureRequest(mods ...func(request *serverupdate.ApiCreateUpdateRequest))

func fixturePayload(mods ...func(payload *serverupdate.CreateUpdatePayload)) serverupdate.CreateUpdatePayload {
payload := serverupdate.CreateUpdatePayload{
MaintenanceWindow: utils.Ptr(int64(13)),
MaintenanceWindow: int32(13),
}
for _, mod := range mods {
mod(&payload)
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, serverupdate.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand All @@ -175,18 +175,29 @@ func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
serverLabel string
resp serverupdate.Update
resp *serverupdate.Update
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
name: "empty",
args: args{
outputFormat: print.PrettyOutputFormat,
resp: &serverupdate.Update{},
},
wantErr: false,
},
{
name: "nil",
args: args{
outputFormat: print.PrettyOutputFormat,
resp: nil,
},
wantErr: true,
},
}
params := testparams.NewTestParams()
for _, tt := range tests {
Expand Down
18 changes: 11 additions & 7 deletions internal/cmd/server/os-update/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/types"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
Expand Down Expand Up @@ -64,7 +64,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return fmt.Errorf("read server os-update: %w", err)
}

return outputResult(params.Printer, model.OutputFormat, *resp)
return outputResult(params.Printer, model.OutputFormat, resp)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -97,24 +97,28 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiGetUpdateRequest {
req := apiClient.GetUpdate(ctx, model.ProjectId, model.ServerId, model.UpdateId, model.Region)
req := apiClient.DefaultAPI.GetUpdate(ctx, model.ProjectId, model.ServerId, model.UpdateId, model.Region)
return req
}

func outputResult(p *print.Printer, outputFormat string, update serverupdate.Update) error {
func outputResult(p *print.Printer, outputFormat string, update *serverupdate.Update) error {
return p.OutputResult(outputFormat, update, func() error {
if update == nil {
return fmt.Errorf("update is nil")
}

table := tables.NewTable()
table.AddRow("ID", utils.PtrString(update.Id))
table.AddRow("ID", update.Id)
table.AddSeparator()
table.AddRow("STATUS", utils.PtrString(update.Status))
table.AddRow("STATUS", update.Status)
table.AddSeparator()
installedUpdates := utils.PtrStringDefault(update.InstalledUpdates, "n/a")
table.AddRow("INSTALLED UPDATES", installedUpdates)
table.AddSeparator()
failedUpdates := utils.PtrStringDefault(update.FailedUpdates, "n/a")
table.AddRow("FAILED UPDATES", failedUpdates)

table.AddRow("START DATE", utils.PtrString(update.StartDate))
table.AddRow("START DATE", update.StartDate)
table.AddSeparator()
table.AddRow("END DATE", utils.PtrString(update.EndDate))
table.AddSeparator()
Expand Down
27 changes: 20 additions & 7 deletions internal/cmd/server/os-update/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/print"
)

const (
Expand All @@ -21,7 +23,7 @@ const (
type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serverupdate.APIClient{}
var testClient = &serverupdate.APIClient{DefaultAPI: &serverupdate.DefaultAPIService{}}
var testProjectId = uuid.NewString()
var testServerId = uuid.NewString()
var testUpdateId = uuid.NewString()
Expand Down Expand Up @@ -65,7 +67,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *serverupdate.ApiGetUpdateRequest)) serverupdate.ApiGetUpdateRequest {
request := testClient.GetUpdate(testCtx, testProjectId, testServerId, testUpdateId, testRegion)
request := testClient.DefaultAPI.GetUpdate(testCtx, testProjectId, testServerId, testUpdateId, testRegion)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -159,7 +161,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, serverupdate.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand All @@ -171,18 +173,29 @@ func TestBuildRequest(t *testing.T) {
func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
update serverupdate.Update
update *serverupdate.Update
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
name: "empty",
args: args{
outputFormat: print.PrettyOutputFormat,
update: &serverupdate.Update{},
},
wantErr: false,
},
{
name: "nil",
args: args{
outputFormat: print.PrettyOutputFormat,
update: nil,
},
wantErr: true,
},
}
params := testparams.NewTestParams()
for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/server/os-update/disable/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"
)

const (
Expand Down Expand Up @@ -108,6 +108,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiDisableServiceResourceRequest {
req := apiClient.DisableServiceResource(ctx, model.ProjectId, model.ServerId, model.Region)
req := apiClient.DefaultAPI.DisableServiceResource(ctx, model.ProjectId, model.ServerId, model.Region)
return req
}
Loading
Loading