@@ -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
8597type 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+
142162func (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
198234func (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