Skip to content

Commit c4069c3

Browse files
committed
update linodego for API v4.0.23
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)
1 parent 0f7302d commit c4069c3

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

CHANGELOG.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# Change Log
22

3-
## Unreleased
3+
## Unreleased (Unknown)
4+
5+
## [v0.9.0](https://github.com/linode/linodego/compare/v0.8.1..v0.9.0) (Unknown)
6+
7+
### Breaking Changes
8+
9+
* `ResizeInstance` now takes `ResizeInstanceOptions` to support `AllowAutoDiskResize` (API v4.0.23)
10+
* `ResizeInstanceOptions` renamed to `InstanceResizeOptions` to fit convention
11+
* `RescueInstanceOptions` renamed to `InstanceRescueOptions` to fit convention
12+
13+
### Features
14+
15+
* Adds new `EventAction` constants: `ActionLinodeMutateCreate`, `ActionLinodeResizeCreate`, `ActionLishBoot` (API v4.0.23)
16+
* Adds `GetInstanceTransfer` which returns an `InstanceTransfer` (API v4.0.23)
417

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

account_events.go

+3
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,17 @@ const (
8787
ActionLinodeDeleteIP EventAction = "linode_deleteip"
8888
ActionLinodeMigrate EventAction = "linode_migrate"
8989
ActionLinodeMutate EventAction = "linode_mutate"
90+
ActionLinodeMutateCreate EventAction = "linode_mutate_create"
9091
ActionLinodeReboot EventAction = "linode_reboot"
9192
ActionLinodeRebuild EventAction = "linode_rebuild"
9293
ActionLinodeResize EventAction = "linode_resize"
94+
ActionLinodeResizeCreate EventAction = "linode_resize_create"
9395
ActionLinodeShutdown EventAction = "linode_shutdown"
9496
ActionLinodeSnapshot EventAction = "linode_snapshot"
9597
ActionLinodeConfigCreate EventAction = "linode_config_create"
9698
ActionLinodeConfigDelete EventAction = "linode_config_delete"
9799
ActionLinodeConfigUpdate EventAction = "linode_config_update"
100+
ActionLishBoot EventAction = "lish_boot"
98101
ActionLongviewClientCreate EventAction = "longviewclient_create"
99102
ActionLongviewClientDelete EventAction = "longviewclient_delete"
100103
ActionLongviewClientUpdate EventAction = "longviewclient_update"

client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
// APIProto connect to API with http(s)
2323
APIProto = "https"
2424
// Version of linodego
25-
Version = "0.8.1"
25+
Version = "0.9.0"
2626
// APIEnvVar environment var to check for API token
2727
APIEnvVar = "LINODE_TOKEN"
2828
// APISecondsPerPoll how frequently to poll for new Events or Status in WaitFor functions

instances.go

+48-9
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ type InstanceBackup struct {
8181
}
8282
}
8383

84+
// InstanceTransfer pool stats for a Linode Instance during the current billing month
85+
type InstanceTransfer struct {
86+
// Bytes of transfer this instance has consumed
87+
Used int `json:"used"`
88+
89+
// GB of billable transfer this instance has consumed
90+
Billable int `json:"billable"`
91+
92+
// GB of transfer this instance adds to the Transfer pool
93+
Quota int `json:"quota"`
94+
}
95+
8496
// InstanceCreateOptions require only Region and Type
8597
type InstanceCreateOptions struct {
8698
Region string `json:"region"`
@@ -139,6 +151,14 @@ type InstanceCloneOptions struct {
139151
Configs []int `json:"configs,omitempty"`
140152
}
141153

154+
// InstanceResizeOptions
155+
type InstanceResizeOptions struct {
156+
Type string `json:"type"`
157+
158+
// 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
159+
AllowAutoDiskResize bool `json:allow_auto_disk_resize,omitempty"`
160+
}
161+
142162
func (l *Instance) fixDates() *Instance {
143163
l.Created, _ = parseDates(l.CreatedStr)
144164
l.Updated, _ = parseDates(l.UpdatedStr)
@@ -194,6 +214,22 @@ func (c *Client) GetInstance(ctx context.Context, linodeID int) (*Instance, erro
194214
return r.Result().(*Instance).fixDates(), nil
195215
}
196216

217+
// GetInstance gets the instance with the provided ID
218+
func (c *Client) GetInstanceTransfer(ctx context.Context, linodeID int) (*InstanceTransfer, error) {
219+
e, err := c.Instances.Endpoint()
220+
if err != nil {
221+
return nil, err
222+
}
223+
e = fmt.Sprintf("%s/%d/transfer", e, linodeID)
224+
r, err := coupleAPIErrors(c.R(ctx).
225+
SetResult(InstanceTransfer{}).
226+
Get(e))
227+
if err != nil {
228+
return nil, err
229+
}
230+
return r.Result().(*InstanceTransfer), nil
231+
}
232+
197233
// CreateInstance creates a Linode instance
198234
func (c *Client) CreateInstance(ctx context.Context, instance InstanceCreateOptions) (*Instance, error) {
199235
var body string
@@ -347,8 +383,8 @@ func (c *Client) RebootInstance(ctx context.Context, id int, configID int) error
347383
return err
348384
}
349385

350-
// RebuildInstanceOptions is a struct representing the options to send to the rebuild linode endpoint
351-
type RebuildInstanceOptions struct {
386+
// InstanceRebuildOptions is a struct representing the options to send to the rebuild linode endpoint
387+
type InstanceRebuildOptions struct {
352388
Image string `json:"image"`
353389
RootPass string `json:"root_pass"`
354390
AuthorizedKeys []string `json:"authorized_keys"`
@@ -360,7 +396,7 @@ type RebuildInstanceOptions struct {
360396

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

384-
// RescueInstanceOptions fields are those accepted by RescueInstance
385-
type RescueInstanceOptions struct {
420+
// InstanceRescueOptions fields are those accepted by RescueInstance
421+
type InstanceRescueOptions struct {
386422
Devices InstanceConfigDeviceMap `json:"devices"`
387423
}
388424

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

412448
// ResizeInstance resizes an instance to new Linode type
413-
func (c *Client) ResizeInstance(ctx context.Context, id int, linodeType string) error {
414-
body := fmt.Sprintf("{\"type\":\"%s\"}", linodeType)
415-
449+
func (c *Client) ResizeInstance(ctx context.Context, id int, opts InstanceResizeOptions) error {
450+
o, err := json.Marshal(opts)
451+
if err != nil {
452+
return NewError(err)
453+
}
454+
body := string(o)
416455
e, err := c.Instances.Endpoint()
417456
if err != nil {
418457
return err

0 commit comments

Comments
 (0)