@@ -81,6 +81,18 @@ type InstanceBackup struct {
81
81
}
82
82
}
83
83
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
+
84
96
// InstanceCreateOptions require only Region and Type
85
97
type InstanceCreateOptions struct {
86
98
Region string `json:"region"`
@@ -139,6 +151,14 @@ type InstanceCloneOptions struct {
139
151
Configs []int `json:"configs,omitempty"`
140
152
}
141
153
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
+
142
162
func (l * Instance ) fixDates () * Instance {
143
163
l .Created , _ = parseDates (l .CreatedStr )
144
164
l .Updated , _ = parseDates (l .UpdatedStr )
@@ -194,6 +214,22 @@ func (c *Client) GetInstance(ctx context.Context, linodeID int) (*Instance, erro
194
214
return r .Result ().(* Instance ).fixDates (), nil
195
215
}
196
216
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
+
197
233
// CreateInstance creates a Linode instance
198
234
func (c * Client ) CreateInstance (ctx context.Context , instance InstanceCreateOptions ) (* Instance , error ) {
199
235
var body string
@@ -347,8 +383,8 @@ func (c *Client) RebootInstance(ctx context.Context, id int, configID int) error
347
383
return err
348
384
}
349
385
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 {
352
388
Image string `json:"image"`
353
389
RootPass string `json:"root_pass"`
354
390
AuthorizedKeys []string `json:"authorized_keys"`
@@ -360,7 +396,7 @@ type RebuildInstanceOptions struct {
360
396
361
397
// RebuildInstance Deletes all Disks and Configs on this Linode,
362
398
// 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 ) {
364
400
o , err := json .Marshal (opts )
365
401
if err != nil {
366
402
return nil , NewError (err )
@@ -381,16 +417,16 @@ func (c *Client) RebuildInstance(ctx context.Context, id int, opts RebuildInstan
381
417
return r .Result ().(* Instance ).fixDates (), nil
382
418
}
383
419
384
- // RescueInstanceOptions fields are those accepted by RescueInstance
385
- type RescueInstanceOptions struct {
420
+ // InstanceRescueOptions fields are those accepted by RescueInstance
421
+ type InstanceRescueOptions struct {
386
422
Devices InstanceConfigDeviceMap `json:"devices"`
387
423
}
388
424
389
425
// RescueInstance reboots an instance into a safe environment for performing many system recovery and disk management tasks.
390
426
// Rescue Mode is based on the Finnix recovery distribution, a self-contained and bootable Linux distribution.
391
427
// You can also use Rescue Mode for tasks other than disaster recovery, such as formatting disks to use different filesystems,
392
428
// 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 {
394
430
o , err := json .Marshal (opts )
395
431
if err != nil {
396
432
return NewError (err )
@@ -410,9 +446,12 @@ func (c *Client) RescueInstance(ctx context.Context, id int, opts RescueInstance
410
446
}
411
447
412
448
// 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 )
416
455
e , err := c .Instances .Endpoint ()
417
456
if err != nil {
418
457
return err
0 commit comments