Skip to content

Commit d3028f7

Browse files
Added support for missing Instance-related endpoints (#605)
* Added support for missing instance endpoints * Updated setupNodeBalancerNode to use one client * Addressed PR comments
1 parent 400777a commit d3028f7

23 files changed

+7837
-1243
lines changed

instance_disks.go

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ type InstanceDiskUpdateOptions struct {
6565
Label string `json:"label"`
6666
}
6767

68+
type InstanceDiskCloneOptions struct{}
69+
6870
// ListInstanceDisks lists InstanceDisks
6971
func (c *Client) ListInstanceDisks(ctx context.Context, linodeID int, opts *ListOptions) ([]InstanceDisk, error) {
7072
response, err := getPaginatedResults[InstanceDisk](ctx, c, formatAPIPath("linode/instances/%d/disks", linodeID), opts)
@@ -165,3 +167,9 @@ func (c *Client) DeleteInstanceDisk(ctx context.Context, linodeID int, diskID in
165167
err := doDELETERequest(ctx, c, e)
166168
return err
167169
}
170+
171+
// CloneInstanceDisk clones the given InstanceDisk for the given Instance
172+
func (c *Client) CloneInstanceDisk(ctx context.Context, linodeID, diskID int, opts InstanceDiskCloneOptions) (*InstanceDisk, error) {
173+
e := formatAPIPath("linode/instances/%d/disks/%d/clone", linodeID, diskID)
174+
return doPOSTRequest[InstanceDisk](ctx, c, e, opts)
175+
}

instance_nodebalancers.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package linodego
2+
3+
import (
4+
"context"
5+
)
6+
7+
// ListInstanceNodeBalancers lists NodeBalancers that the provided instance is a node in
8+
func (c *Client) ListInstanceNodeBalancers(ctx context.Context, linodeID int, opts *ListOptions) ([]NodeBalancer, error) {
9+
return getPaginatedResults[NodeBalancer](ctx, c, formatAPIPath("linode/instances/%d/nodebalancers", linodeID), opts)
10+
}

instances.go

+32-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ type InstanceTransfer struct {
117117
Quota int `json:"quota"`
118118
}
119119

120+
// MonthlyInstanceTransferStats pool stats for a Linode Instance network transfer statistics for a specific month
121+
type MonthlyInstanceTransferStats struct {
122+
// The amount of inbound public network traffic received by this Linode, in bytes, for a specific year/month.
123+
BytesIn int `json:"bytes_in"`
124+
125+
// The amount of outbound public network traffic sent by this Linode, in bytes, for a specific year/month.
126+
BytesOut int `json:"bytes_out"`
127+
128+
// The total amount of public network traffic sent and received by this Linode, in bytes, for a specific year/month.
129+
BytesTotal int `json:"bytes_total"`
130+
}
131+
120132
// InstancePlacementGroup represents information about the placement group
121133
// this Linode is a part of.
122134
type InstancePlacementGroup struct {
@@ -133,6 +145,11 @@ type InstanceMetadataOptions struct {
133145
UserData string `json:"user_data,omitempty"`
134146
}
135147

148+
// InstancePasswordResetOptions specifies the new password for the Linode
149+
type InstancePasswordResetOptions struct {
150+
RootPass string `json:"root_pass"`
151+
}
152+
136153
// InstanceCreateOptions require only Region and Type
137154
type InstanceCreateOptions struct {
138155
Region string `json:"region"`
@@ -278,7 +295,7 @@ func (c *Client) GetInstance(ctx context.Context, linodeID int) (*Instance, erro
278295
return response, nil
279296
}
280297

281-
// GetInstanceTransfer gets the instance with the provided ID
298+
// GetInstanceTransfer gets the instance's network transfer pool statistics for the current month.
282299
func (c *Client) GetInstanceTransfer(ctx context.Context, linodeID int) (*InstanceTransfer, error) {
283300
e := formatAPIPath("linode/instances/%d/transfer", linodeID)
284301
response, err := doGETRequest[InstanceTransfer](ctx, c, e)
@@ -289,6 +306,12 @@ func (c *Client) GetInstanceTransfer(ctx context.Context, linodeID int) (*Instan
289306
return response, nil
290307
}
291308

309+
// GetInstanceTransferMonthly gets the instance's network transfer pool statistics for a specific month.
310+
func (c *Client) GetInstanceTransferMonthly(ctx context.Context, linodeID, year, month int) (*MonthlyInstanceTransferStats, error) {
311+
e := formatAPIPath("linode/instances/%d/transfer/%d/%d", linodeID, year, month)
312+
return doGETRequest[MonthlyInstanceTransferStats](ctx, c, e)
313+
}
314+
292315
// CreateInstance creates a Linode instance
293316
func (c *Client) CreateInstance(ctx context.Context, opts InstanceCreateOptions) (*Instance, error) {
294317
e := "linode/instances"
@@ -348,6 +371,14 @@ func (c *Client) CloneInstance(ctx context.Context, linodeID int, opts InstanceC
348371
return response, nil
349372
}
350373

374+
// ResetInstancePassword resets a Linode instance's root password
375+
func (c *Client) ResetInstancePassword(ctx context.Context, linodeID int, opts InstancePasswordResetOptions) error {
376+
e := formatAPIPath("linode/instances/%d/password", linodeID)
377+
_, err := doPOSTRequest[Instance](ctx, c, e, opts)
378+
379+
return err
380+
}
381+
351382
// RebootInstance reboots a Linode instance
352383
// A configID of 0 will cause Linode to choose the last/best config
353384
func (c *Client) RebootInstance(ctx context.Context, linodeID int, configID int) error {

network_ips.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (c *Client) ListIPAddresses(ctx context.Context, opts *ListOptions) ([]Inst
5151
return response, nil
5252
}
5353

54-
// GetIPAddress gets the template with the provided ID
54+
// GetIPAddress gets the IPAddress with the provided IP
5555
func (c *Client) GetIPAddress(ctx context.Context, id string) (*InstanceIP, error) {
5656
e := formatAPIPath("networking/ips/%s", id)
5757
response, err := doGETRequest[InstanceIP](ctx, c, e)

0 commit comments

Comments
 (0)