Skip to content

Commit

Permalink
AMDプラン (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamamoto-febc authored Aug 8, 2023
1 parent 959ddee commit efad52d
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 2 additions & 0 deletions server/apply_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type ApplyRequest struct {
CPU int
MemoryGB int
GPU int
CPUModel string
Commitment types.ECommitment
Generation types.EPlanGeneration
InterfaceDriver types.EInterfaceDriver
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions server/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions server/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Builder struct {
CPU int
MemoryGB int
GPU int
CPUModel string
Commitment types.ECommitment
Generation types.EPlanGeneration
InterfaceDriver types.EInterfaceDriver
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -155,6 +157,7 @@ var (
defaultCPU = 1
defaultMemoryGB = 1
defaultGPU = 0
defaultCPUModel = ""
defaultCommitment = types.Commitments.Standard
defaultGeneration = types.PlanGenerations.Default
defaultInterfaceDriver = types.InterfaceDrivers.VirtIO
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -459,6 +467,7 @@ type serverState struct {
memoryGB int
cpu int
gpu int
cpuModel string
commitment types.ECommitment
nic *nicState // hash
additionalNICs []*nicState // hash
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions server/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"},
Expand Down
2 changes: 2 additions & 0 deletions server/change_plan_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type ChangePlanRequest struct {

CPU int
MemoryMB int
GPU int
ServerPlanCPUModel string
ServerPlanCommitment types.ECommitment
ServerPlanGeneration types.EPlanGeneration
}
Expand Down
12 changes: 9 additions & 3 deletions server/change_plan_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -53,14 +55,18 @@ 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
}
if req.ServerPlanCommitment != types.Commitments.Unknown {
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)
}
2 changes: 2 additions & 0 deletions server/create_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type CreateRequest struct {
CPU int
MemoryGB int
GPU int
CPUModel string
Commitment types.ECommitment
Generation types.EPlanGeneration
InterfaceDriver types.EInterfaceDriver
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions server/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions server/update_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions server/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit efad52d

Please sign in to comment.