diff --git a/go.mod b/go.mod index 33042cb..975c3a4 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/sacloud/ftps v1.2.0 - github.com/sacloud/iaas-api-go v1.11.1 + github.com/sacloud/iaas-api-go v1.11.2-0.20230808040020-104bc72d03c1 github.com/sacloud/packages-go v0.0.9 github.com/stretchr/testify v1.8.4 golang.org/x/crypto v0.10.0 diff --git a/go.sum b/go.sum index 0ecbfde..b745c0f 100644 --- a/go.sum +++ b/go.sum @@ -45,8 +45,8 @@ github.com/sacloud/ftps v1.2.0 h1:7UlSWd7cnm1J+sANz7IiBV9ffVcS+4g6ZV5UHVVbvaw= github.com/sacloud/ftps v1.2.0/go.mod h1:h4awhOi3PEyhKLj1FpXjoVV5yVkmRUU+d5L95EwX2JU= github.com/sacloud/go-http v0.1.6 h1:lJGXDt9xrxJiDszRPaN9NIP8MVj10YKMzmnyzdSfI8w= github.com/sacloud/go-http v0.1.6/go.mod h1:oLAHoDJRkptf8sq4fE8oERLkdCh0kJWfWu+paoJY7I0= -github.com/sacloud/iaas-api-go v1.11.1 h1:2MsFZ4H1uRdRVx2nVXuERWQ3swoFc3XreIV5hJ3Nsws= -github.com/sacloud/iaas-api-go v1.11.1/go.mod h1:uBDSa06F/V0OnoR66jGdbH0PVnCJw+NeE9RVbVgMfss= +github.com/sacloud/iaas-api-go v1.11.2-0.20230808040020-104bc72d03c1 h1:fp1Fov10J3VSDKfihMQ8b2DD9Zg6R0gev72Cme2im5g= +github.com/sacloud/iaas-api-go v1.11.2-0.20230808040020-104bc72d03c1/go.mod h1:mpKNVufkYwbkRT5zsmOYR42G8Q3lcohSRAhXHIzjTuI= github.com/sacloud/packages-go v0.0.9 h1:GbinkBLC/eirFhHpLjoDW6JV7+95Rnd2d8RWj7Afeks= github.com/sacloud/packages-go v0.0.9/go.mod h1:k+EEUMF2LlncjbNIJNOqLyZ9wjTESPIWIk1OA7x9j2Q= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/server/apply_request.go b/server/apply_request.go index 8ff3349..e4e215c 100644 --- a/server/apply_request.go +++ b/server/apply_request.go @@ -36,6 +36,7 @@ type ApplyRequest struct { CPU int MemoryGB int GPU int + CPUModel string Commitment types.ECommitment Generation types.EPlanGeneration InterfaceDriver types.EInterfaceDriver @@ -100,6 +101,7 @@ func (req *ApplyRequest) Builder(caller iaas.APICaller) (*server.Builder, error) CPU: req.CPU, MemoryGB: req.MemoryGB, GPU: req.GPU, + CPUModel: req.CPUModel, Commitment: req.Commitment, Generation: req.Generation, InterfaceDriver: req.InterfaceDriver, diff --git a/server/apply_test.go b/server/apply_test.go index 5028587..288278f 100644 --- a/server/apply_test.go +++ b/server/apply_test.go @@ -43,6 +43,7 @@ func TestServerService_convertApplyRequest(t *testing.T) { CPU: 2, MemoryGB: 4, GPU: 0, + CPUModel: "uncategorized", Commitment: types.Commitments.DedicatedCPU, Generation: types.PlanGenerations.Default, InterfaceDriver: types.InterfaceDrivers.VirtIO, @@ -69,6 +70,7 @@ func TestServerService_convertApplyRequest(t *testing.T) { Name: "name", CPU: 2, MemoryGB: 4, + CPUModel: "uncategorized", Commitment: types.Commitments.DedicatedCPU, Generation: types.PlanGenerations.Default, InterfaceDriver: types.InterfaceDrivers.VirtIO, diff --git a/server/builder/builder.go b/server/builder/builder.go index e7cd3a9..971dec6 100644 --- a/server/builder/builder.go +++ b/server/builder/builder.go @@ -36,6 +36,7 @@ type Builder struct { CPU int MemoryGB int GPU int + CPUModel string Commitment types.ECommitment Generation types.EPlanGeneration InterfaceDriver types.EInterfaceDriver @@ -127,6 +128,7 @@ func BuilderFromResource(ctx context.Context, caller iaas.APICaller, zone string CPU: current.CPU, MemoryGB: current.MemoryMB * size.GiB, GPU: current.GPU, + CPUModel: current.ServerPlanCPUModel, Commitment: current.ServerPlanCommitment, Generation: current.ServerPlanGeneration, InterfaceDriver: current.InterfaceDriver, @@ -155,6 +157,7 @@ var ( defaultCPU = 1 defaultMemoryGB = 1 defaultGPU = 0 + defaultCPUModel = "" defaultCommitment = types.Commitments.Standard defaultGeneration = types.PlanGenerations.Default defaultInterfaceDriver = types.InterfaceDrivers.VirtIO @@ -200,6 +203,7 @@ func (b *Builder) Validate(ctx context.Context, zone string) error { CPU: b.CPU, MemoryGB: b.MemoryGB, GPU: b.GPU, + CPUModel: b.CPUModel, Commitment: b.Commitment, Generation: b.Generation, }) @@ -387,6 +391,7 @@ func (b *Builder) Update(ctx context.Context, zone string) (*BuildResult, error) GPU: b.GPU, ServerPlanGeneration: b.Generation, ServerPlanCommitment: b.Commitment, + ServerPlanCPUModel: b.CPUModel, }) if err != nil { return result, err @@ -442,6 +447,9 @@ func (b *Builder) setDefaults() { if b.GPU == 0 { b.GPU = defaultGPU } + if b.CPUModel == "" { + b.CPUModel = defaultCPUModel + } if b.Commitment == types.ECommitment("") { b.Commitment = defaultCommitment } @@ -459,6 +467,7 @@ type serverState struct { memoryGB int cpu int gpu int + cpuModel string commitment types.ECommitment nic *nicState // hash additionalNICs []*nicState // hash @@ -481,6 +490,7 @@ func (b *Builder) desiredState() *serverState { memoryGB: b.MemoryGB, cpu: b.CPU, gpu: b.GPU, + cpuModel: b.CPUModel, commitment: b.Commitment, nic: nic, additionalNICs: additionalNICs, @@ -535,6 +545,7 @@ func (b *Builder) currentState(server *iaas.Server) *serverState { memoryGB: server.GetMemoryGB(), cpu: server.CPU, gpu: server.GPU, + cpuModel: server.ServerPlanCPUModel, commitment: server.ServerPlanCommitment, nic: nic, additionalNICs: additionalNICs, @@ -548,6 +559,7 @@ func (b *Builder) createServer(ctx context.Context, zone string) (*iaas.Server, CPU: b.CPU, MemoryMB: b.MemoryGB * size.GiB, GPU: b.GPU, + ServerPlanCPUModel: b.CPUModel, ServerPlanCommitment: b.Commitment, ServerPlanGeneration: b.Generation, InterfaceDriver: b.InterfaceDriver, @@ -798,6 +810,7 @@ func (b *Builder) isPlanChanged(server *iaas.Server) bool { return b.CPU != server.CPU || b.MemoryGB != server.GetMemoryGB() || b.GPU != server.GPU || + (b.CPUModel != "" && b.CPUModel != server.ServerPlanCPUModel) || b.Commitment != server.ServerPlanCommitment || (b.Generation != types.PlanGenerations.Default && b.Generation != server.ServerPlanGeneration) // b.Generation != server.ServerPlanGeneration diff --git a/server/builder/builder_test.go b/server/builder/builder_test.go index 72e551f..b204365 100644 --- a/server/builder/builder_test.go +++ b/server/builder/builder_test.go @@ -47,6 +47,8 @@ func TestBuilder_setDefaults(t *testing.T) { expected := &Builder{ CPU: defaultCPU, MemoryGB: defaultMemoryGB, + GPU: defaultGPU, + CPUModel: defaultCPUModel, Commitment: defaultCommitment, Generation: defaultGeneration, InterfaceDriver: defaultInterfaceDriver, @@ -770,6 +772,7 @@ func TestBuilder_UpdateWithPreviousID(t *testing.T) { Name: testutil.ResourceName("server-builder"), CPU: 1, MemoryGB: 1, + CPUModel: "uncategorized", Commitment: types.Commitments.Standard, Generation: types.PlanGenerations.Default, Tags: types.Tags{"tag1", "tag2"}, diff --git a/server/change_plan_request.go b/server/change_plan_request.go index 3257bc7..0166923 100644 --- a/server/change_plan_request.go +++ b/server/change_plan_request.go @@ -25,6 +25,8 @@ type ChangePlanRequest struct { CPU int MemoryMB int + GPU int + ServerPlanCPUModel string ServerPlanCommitment types.ECommitment ServerPlanGeneration types.EPlanGeneration } diff --git a/server/change_plan_service.go b/server/change_plan_service.go index f38f192..9d21a5f 100644 --- a/server/change_plan_service.go +++ b/server/change_plan_service.go @@ -43,7 +43,9 @@ func (s *Service) ChangePlanWithContext(ctx context.Context, req *ChangePlanRequ changeReq := &iaas.ServerChangePlanRequest{ CPU: current.CPU, + GPU: current.GPU, MemoryMB: current.MemoryMB, + ServerPlanCPUModel: current.ServerPlanCPUModel, ServerPlanGeneration: current.ServerPlanGeneration, ServerPlanCommitment: current.ServerPlanCommitment, } @@ -53,6 +55,12 @@ func (s *Service) ChangePlanWithContext(ctx context.Context, req *ChangePlanRequ if req.MemoryMB > 0 { changeReq.MemoryMB = req.MemoryMB } + if req.GPU > 0 { + changeReq.GPU = req.GPU + } + if req.ServerPlanCPUModel != "" { + changeReq.ServerPlanCPUModel = req.ServerPlanCPUModel + } if req.ServerPlanGeneration != types.PlanGenerations.Default { changeReq.ServerPlanGeneration = req.ServerPlanGeneration } @@ -60,7 +68,5 @@ func (s *Service) ChangePlanWithContext(ctx context.Context, req *ChangePlanRequ changeReq.ServerPlanCommitment = req.ServerPlanCommitment } - return plans.ChangeServerPlan(ctx, s.caller, req.Zone, req.ID, - changeReq.CPU, changeReq.GetMemoryGB(), - changeReq.ServerPlanCommitment, changeReq.ServerPlanGeneration) + return plans.ChangeServerPlan(ctx, s.caller, req.Zone, req.ID, changeReq) } diff --git a/server/create_request.go b/server/create_request.go index 1689ce1..fffd195 100644 --- a/server/create_request.go +++ b/server/create_request.go @@ -30,6 +30,7 @@ type CreateRequest struct { CPU int MemoryGB int GPU int + CPUModel string Commitment types.ECommitment Generation types.EPlanGeneration InterfaceDriver types.EInterfaceDriver @@ -57,6 +58,7 @@ func (req *CreateRequest) ApplyRequest() *ApplyRequest { CPU: req.CPU, MemoryGB: req.MemoryGB, GPU: req.GPU, + CPUModel: req.CPUModel, Commitment: req.Commitment, Generation: req.Generation, InterfaceDriver: req.InterfaceDriver, diff --git a/server/create_test.go b/server/create_test.go index ea2b636..cf9c90c 100644 --- a/server/create_test.go +++ b/server/create_test.go @@ -40,6 +40,7 @@ func TestServerService_convertCreateRequest(t *testing.T) { IconID: 101, CPU: 22, MemoryGB: 4, + CPUModel: "uncategorized", Commitment: types.Commitments.DedicatedCPU, Generation: types.PlanGenerations.Default, InterfaceDriver: types.InterfaceDrivers.VirtIO, @@ -73,6 +74,7 @@ func TestServerService_convertCreateRequest(t *testing.T) { CPU: 22, MemoryGB: 4, GPU: 0, + CPUModel: "uncategorized", Commitment: types.Commitments.DedicatedCPU, Generation: types.PlanGenerations.Default, InterfaceDriver: types.InterfaceDrivers.VirtIO, diff --git a/server/update_request.go b/server/update_request.go index fbf668a..05d7de2 100644 --- a/server/update_request.go +++ b/server/update_request.go @@ -36,6 +36,7 @@ type UpdateRequest struct { CPU *int `service:",omitempty"` MemoryGB *int `service:",omitempty"` GPU *int `service:",omitempty"` + CPUModel *string `service:",omitempty"` Commitment *types.ECommitment `service:",omitempty"` Generation *types.EPlanGeneration `service:",omitempty"` InterfaceDriver *types.EInterfaceDriver `service:",omitempty"` @@ -123,6 +124,7 @@ func (req *UpdateRequest) applyRequestFromResource(ctx context.Context, caller i CPU: current.CPU, MemoryGB: current.GetMemoryGB(), GPU: current.GPU, + CPUModel: current.ServerPlanCPUModel, Commitment: current.ServerPlanCommitment, Generation: current.ServerPlanGeneration, InterfaceDriver: current.InterfaceDriver, diff --git a/server/update_test.go b/server/update_test.go index fab7c96..c5ac4c1 100644 --- a/server/update_test.go +++ b/server/update_test.go @@ -55,6 +55,7 @@ func TestServerService_convertUpdateRequest(t *testing.T) { Tags: types.Tags{"tag1", "tag2"}, CPU: 1, MemoryGB: 1, + CPUModel: "uncategorized", Commitment: types.Commitments.Standard, Generation: types.PlanGenerations.G100, InterfaceDriver: types.InterfaceDrivers.VirtIO, @@ -100,6 +101,7 @@ func TestServerService_convertUpdateRequest(t *testing.T) { Tags: &types.Tags{"tag1-upd", "tag2-upd"}, CPU: pointer.NewInt(2), MemoryGB: pointer.NewInt(4), + CPUModel: pointer.NewString("uncategorized"), Commitment: &types.Commitments.DedicatedCPU, Generation: &types.PlanGenerations.G200, InterfaceDriver: &types.InterfaceDrivers.E1000, @@ -134,6 +136,7 @@ func TestServerService_convertUpdateRequest(t *testing.T) { CPU: 2, MemoryGB: 4, GPU: 0, + CPUModel: "uncategorized", Commitment: types.Commitments.DedicatedCPU, Generation: types.PlanGenerations.G200, InterfaceDriver: types.InterfaceDrivers.E1000,