Skip to content

Commit

Permalink
support resource tier migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Overglazed committed Jul 14, 2022
1 parent 2defcca commit f134175
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/service/ecloud/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ type Instance struct {
VolumeCapacity int `json:"volume_capacity"`
VolumeGroupID string `json:"volume_group_id"`
HostGroupID string `json:"host_group_id"`
ResourceTierID string `json:"resource_tier_id"`
Sync ResourceSync `json:"sync"`
Online *bool `json:"online"`
AgentRunning *bool `json:"agent_running"`
Expand Down
3 changes: 2 additions & 1 deletion pkg/service/ecloud/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ type PatchVPNServiceRequest struct {

// MigrateInstanceRequest represents a request to migrate an instance
type MigrateInstanceRequest struct {
HostGroupID string `json:"host_group_id,omitempty"`
HostGroupID string `json:"host_group_id,omitempty"`
ResourceTierID string `json:"resource_tier_id,omitempty"`
}

// CreateVolumeGroupRequest represents a request to create a volume group
Expand Down
27 changes: 27 additions & 0 deletions pkg/service/ecloud/service_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,33 @@ func TestMigrateInstance(t *testing.T) {
assert.Equal(t, "task-abcdef12", taskID)
})

t.Run("ValidResourceTier", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

c := mocks.NewMockConnection(mockCtrl)

s := Service{
connection: c,
}

req := MigrateInstanceRequest{
ResourceTierID: "rt-abcdef12",
}

c.EXPECT().Post("/ecloud/v2/instances/i-abcdef12/migrate", &req).Return(&connection.APIResponse{
Response: &http.Response{
Body: ioutil.NopCloser(bytes.NewReader([]byte("{\"data\":{\"task_id\":\"task-abcdef12\"},\"meta\":{\"location\":\"\"}}"))),
StatusCode: 202,
},
}, nil).Times(1)

taskID, err := s.MigrateInstance("i-abcdef12", req)

assert.Nil(t, err)
assert.Equal(t, "task-abcdef12", taskID)
})

t.Run("ConnectionError_ReturnsError", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
Expand Down

0 comments on commit f134175

Please sign in to comment.