Skip to content

Commit

Permalink
Project: Unified Migration (#445)
Browse files Browse the repository at this point in the history
* Add fields for unified migration (#428)

* Add fixture for TestInstance_Resize
  • Loading branch information
zliang-akamai committed Dec 18, 2023
1 parent 17895ae commit 659e0a1
Show file tree
Hide file tree
Showing 3 changed files with 693 additions and 3 deletions.
26 changes: 23 additions & 3 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ const (
InstanceResizing InstanceStatus = "resizing"
)

type InstanceMigrationType string

const (
WarmMigration InstanceMigrationType = "warm"
ColdMigration InstanceMigrationType = "cold"
)

// Instance represents a linode object
type Instance struct {
ID int `json:"id"`
Expand Down Expand Up @@ -192,12 +199,19 @@ type InstanceCloneOptions struct {

// InstanceResizeOptions is an options struct used when resizing an instance
type InstanceResizeOptions struct {
Type string `json:"type"`
Type string `json:"type"`
MigrationType InstanceMigrationType `json:"migration_type,omitempty"`

// When enabled, an instance resize will also resize a data disk if the instance has no more than one data disk and one swap disk
AllowAutoDiskResize *bool `json:"allow_auto_disk_resize,omitempty"`
}

// InstanceResizeOptions is an options struct used when resizing an instance
type InstanceMigrateOptions struct {
Type InstanceMigrationType `json:"type,omitempty"`
Region string `json:"region,omitempty"`
}

// InstancesPagedResponse represents a linode API response for listing
type InstancesPagedResponse struct {
*PageOptions
Expand Down Expand Up @@ -417,8 +431,14 @@ func (c *Client) MutateInstance(ctx context.Context, id int) error {
}

// MigrateInstance - Migrate an instance
func (c *Client) MigrateInstance(ctx context.Context, id int) error {
return c.simpleInstanceAction(ctx, "migrate", id)
func (c *Client) MigrateInstance(ctx context.Context, linodeID int, opts InstanceMigrateOptions) error {
body, err := json.Marshal(opts)
if err != nil {
return err
}
e := fmt.Sprintf("linode/instances/%d/migrate", linodeID)
_, err = coupleAPIErrors(c.R(ctx).SetBody(string(body)).Post(e))
return err
}

// simpleInstanceAction is a helper for Instance actions that take no parameters
Expand Down
Loading

0 comments on commit 659e0a1

Please sign in to comment.