Skip to content

Commit

Permalink
update linodego for API v4.0.23
Browse files Browse the repository at this point in the history
Breaking Changes
----------------

* `ResizeInstance` now takes `ResizeInstanceOptions` to support `AllowAutoDiskResize` (API v4.0.23)
* `ResizeInstanceOptions` renamed to `InstanceResizeOptions` to fit convention
* `RescueInstanceOptions` renamed to `InstanceRescueOptions` to fit convention

Features
--------

* Adds new `EventAction` constants: `ActionLinodeMutateCreate`, `ActionLinodeResizeCreate`, `ActionLishBoot` (API v4.0.23)
* Adds `GetInstanceTransfer` which returns an `InstanceTransfer` (API v4.0.23)
  • Loading branch information
displague committed May 22, 2019
1 parent 0f7302d commit c4069c3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Change Log

## Unreleased
## Unreleased (Unknown)

## [v0.9.0](https://github.com/linode/linodego/compare/v0.8.1..v0.9.0) (Unknown)

### Breaking Changes

* `ResizeInstance` now takes `ResizeInstanceOptions` to support `AllowAutoDiskResize` (API v4.0.23)
* `ResizeInstanceOptions` renamed to `InstanceResizeOptions` to fit convention
* `RescueInstanceOptions` renamed to `InstanceRescueOptions` to fit convention

### Features

* Adds new `EventAction` constants: `ActionLinodeMutateCreate`, `ActionLinodeResizeCreate`, `ActionLishBoot` (API v4.0.23)
* Adds `GetInstanceTransfer` which returns an `InstanceTransfer` (API v4.0.23)

## [v0.8.1](https://github.com/linode/linodego/compare/v0.8.0..v0.8.1) (2019-05-20)

Expand Down
3 changes: 3 additions & 0 deletions account_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ const (
ActionLinodeDeleteIP EventAction = "linode_deleteip"
ActionLinodeMigrate EventAction = "linode_migrate"
ActionLinodeMutate EventAction = "linode_mutate"
ActionLinodeMutateCreate EventAction = "linode_mutate_create"
ActionLinodeReboot EventAction = "linode_reboot"
ActionLinodeRebuild EventAction = "linode_rebuild"
ActionLinodeResize EventAction = "linode_resize"
ActionLinodeResizeCreate EventAction = "linode_resize_create"
ActionLinodeShutdown EventAction = "linode_shutdown"
ActionLinodeSnapshot EventAction = "linode_snapshot"
ActionLinodeConfigCreate EventAction = "linode_config_create"
ActionLinodeConfigDelete EventAction = "linode_config_delete"
ActionLinodeConfigUpdate EventAction = "linode_config_update"
ActionLishBoot EventAction = "lish_boot"
ActionLongviewClientCreate EventAction = "longviewclient_create"
ActionLongviewClientDelete EventAction = "longviewclient_delete"
ActionLongviewClientUpdate EventAction = "longviewclient_update"
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
// APIProto connect to API with http(s)
APIProto = "https"
// Version of linodego
Version = "0.8.1"
Version = "0.9.0"
// APIEnvVar environment var to check for API token
APIEnvVar = "LINODE_TOKEN"
// APISecondsPerPoll how frequently to poll for new Events or Status in WaitFor functions
Expand Down
57 changes: 48 additions & 9 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ type InstanceBackup struct {
}
}

// InstanceTransfer pool stats for a Linode Instance during the current billing month
type InstanceTransfer struct {
// Bytes of transfer this instance has consumed
Used int `json:"used"`

// GB of billable transfer this instance has consumed
Billable int `json:"billable"`

// GB of transfer this instance adds to the Transfer pool
Quota int `json:"quota"`
}

// InstanceCreateOptions require only Region and Type
type InstanceCreateOptions struct {
Region string `json:"region"`
Expand Down Expand Up @@ -139,6 +151,14 @@ type InstanceCloneOptions struct {
Configs []int `json:"configs,omitempty"`
}

// InstanceResizeOptions
type InstanceResizeOptions struct {
Type string `json:"type"`

// 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"`
}

func (l *Instance) fixDates() *Instance {
l.Created, _ = parseDates(l.CreatedStr)
l.Updated, _ = parseDates(l.UpdatedStr)
Expand Down Expand Up @@ -194,6 +214,22 @@ func (c *Client) GetInstance(ctx context.Context, linodeID int) (*Instance, erro
return r.Result().(*Instance).fixDates(), nil
}

// GetInstance gets the instance with the provided ID
func (c *Client) GetInstanceTransfer(ctx context.Context, linodeID int) (*InstanceTransfer, error) {
e, err := c.Instances.Endpoint()
if err != nil {
return nil, err
}
e = fmt.Sprintf("%s/%d/transfer", e, linodeID)
r, err := coupleAPIErrors(c.R(ctx).
SetResult(InstanceTransfer{}).
Get(e))
if err != nil {
return nil, err
}
return r.Result().(*InstanceTransfer), nil
}

// CreateInstance creates a Linode instance
func (c *Client) CreateInstance(ctx context.Context, instance InstanceCreateOptions) (*Instance, error) {
var body string
Expand Down Expand Up @@ -347,8 +383,8 @@ func (c *Client) RebootInstance(ctx context.Context, id int, configID int) error
return err
}

// RebuildInstanceOptions is a struct representing the options to send to the rebuild linode endpoint
type RebuildInstanceOptions struct {
// InstanceRebuildOptions is a struct representing the options to send to the rebuild linode endpoint
type InstanceRebuildOptions struct {
Image string `json:"image"`
RootPass string `json:"root_pass"`
AuthorizedKeys []string `json:"authorized_keys"`
Expand All @@ -360,7 +396,7 @@ type RebuildInstanceOptions struct {

// RebuildInstance Deletes all Disks and Configs on this Linode,
// then deploys a new Image to this Linode with the given attributes.
func (c *Client) RebuildInstance(ctx context.Context, id int, opts RebuildInstanceOptions) (*Instance, error) {
func (c *Client) RebuildInstance(ctx context.Context, id int, opts InstanceRebuildOptions) (*Instance, error) {
o, err := json.Marshal(opts)
if err != nil {
return nil, NewError(err)
Expand All @@ -381,16 +417,16 @@ func (c *Client) RebuildInstance(ctx context.Context, id int, opts RebuildInstan
return r.Result().(*Instance).fixDates(), nil
}

// RescueInstanceOptions fields are those accepted by RescueInstance
type RescueInstanceOptions struct {
// InstanceRescueOptions fields are those accepted by RescueInstance
type InstanceRescueOptions struct {
Devices InstanceConfigDeviceMap `json:"devices"`
}

// RescueInstance reboots an instance into a safe environment for performing many system recovery and disk management tasks.
// Rescue Mode is based on the Finnix recovery distribution, a self-contained and bootable Linux distribution.
// You can also use Rescue Mode for tasks other than disaster recovery, such as formatting disks to use different filesystems,
// copying data between disks, and downloading files from a disk via SSH and SFTP.
func (c *Client) RescueInstance(ctx context.Context, id int, opts RescueInstanceOptions) error {
func (c *Client) RescueInstance(ctx context.Context, id int, opts InstanceRescueOptions) error {
o, err := json.Marshal(opts)
if err != nil {
return NewError(err)
Expand All @@ -410,9 +446,12 @@ func (c *Client) RescueInstance(ctx context.Context, id int, opts RescueInstance
}

// ResizeInstance resizes an instance to new Linode type
func (c *Client) ResizeInstance(ctx context.Context, id int, linodeType string) error {
body := fmt.Sprintf("{\"type\":\"%s\"}", linodeType)

func (c *Client) ResizeInstance(ctx context.Context, id int, opts InstanceResizeOptions) error {
o, err := json.Marshal(opts)
if err != nil {
return NewError(err)
}
body := string(o)
e, err := c.Instances.Endpoint()
if err != nil {
return err
Expand Down

0 comments on commit c4069c3

Please sign in to comment.