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
9 changes: 9 additions & 0 deletions internal/core/arg_specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ func (s ArgSpecs) GetByName(name string) *ArgSpec {
return nil
}

func (s *ArgSpecs) DeleteByName(name string) {
for i, spec := range *s {
if spec.Name == name {
*s = append((*s)[:i], (*s)[i+1:]...)
return
}
}
}

type ArgSpec struct {
// Name of the argument.
Name string
Expand Down
6 changes: 6 additions & 0 deletions internal/namespaces/instance/v1/custom_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func serverUpdateBuilder(c *core.Command) *core.Command {
*instance.UpdateServerRequest
IP *instance.NullableStringValue
PlacementGroupID *instance.NullableStringValue
SecurityGroupID string
}

IPArgSpec := &core.ArgSpec{
Expand All @@ -189,12 +190,17 @@ func serverUpdateBuilder(c *core.Command) *core.Command {
c.ArgsType = reflect.TypeOf(instanceUpdateServerRequestCustom{})

c.ArgSpecs = append(c.ArgSpecs, IPArgSpec)
c.ArgSpecs.DeleteByName("security-group.name")
c.ArgSpecs.GetByName("security-group.id").Name = "security-group-id"

c.Run = func(ctx context.Context, argsI interface{}) (i interface{}, e error) {
customRequest := argsI.(*instanceUpdateServerRequestCustom)

updateServerRequest := customRequest.UpdateServerRequest
updateServerRequest.PlacementGroup = customRequest.PlacementGroupID
updateServerRequest.SecurityGroup = &instance.SecurityGroupTemplate{
ID: customRequest.SecurityGroupID,
}

attachIPRequest := (*instance.UpdateIPRequest)(nil)

Expand Down
25 changes: 25 additions & 0 deletions internal/namespaces/instance/v1/custom_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,29 @@ func Test_ServerUpdateCustom(t *testing.T) {
return nil
},
}))

t.Run("Update server security-group-id from server with security-group-id", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: func(ctx *core.BeforeFuncCtx) error {
ctx.Meta["SecurityGroupResponse"] = ctx.ExecuteCmd("scw instance security-group create")
ctx.Meta["SecurityGroupResponse2"] = ctx.ExecuteCmd("scw instance security-group create")
ctx.Meta["Server"] = ctx.ExecuteCmd("scw instance server create stopped=true image=ubuntu-bionic security-group-id={{ .SecurityGroupResponse.SecurityGroup.ID }}")
return nil
},
Cmd: "scw instance server update server-id={{ .Server.ID }} security-group-id={{ .SecurityGroupResponse2.SecurityGroup.ID }}",
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.Equal(t,
ctx.Meta["SecurityGroupResponse2"].(*instance.CreateSecurityGroupResponse).SecurityGroup.ID,
ctx.Result.(*instance.UpdateServerResponse).Server.SecurityGroup.ID)
},
),
AfterFunc: func(ctx *core.AfterFuncCtx) error {
ctx.ExecuteCmd("scw instance server delete server-id={{ .Server.ID }} delete-ip=true delete-volumes=true")
ctx.ExecuteCmd("scw instance security-group delete security-group-id={{ .SecurityGroupResponse.SecurityGroup.ID }}")
ctx.ExecuteCmd("scw instance security-group delete security-group-id={{ .SecurityGroupResponse2.SecurityGroup.ID }}")
return nil
},
}))
}
Loading