Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for missing Instance-related endpoints #605

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions instance_disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type InstanceDiskUpdateOptions struct {
Label string `json:"label"`
}

type InstanceDiskCloneOptions struct{}

// ListInstanceDisks lists InstanceDisks
func (c *Client) ListInstanceDisks(ctx context.Context, linodeID int, opts *ListOptions) ([]InstanceDisk, error) {
response, err := getPaginatedResults[InstanceDisk](ctx, c, formatAPIPath("linode/instances/%d/disks", linodeID), opts)
Expand Down Expand Up @@ -165,3 +167,9 @@ func (c *Client) DeleteInstanceDisk(ctx context.Context, linodeID int, diskID in
err := doDELETERequest(ctx, c, e)
return err
}

// CloneInstanceDisk clones the given InstanceDisk for the given Instance
func (c *Client) CloneInstanceDisk(ctx context.Context, linodeID, diskID int, opts InstanceDiskCloneOptions) (*InstanceDisk, error) {
e := formatAPIPath("linode/instances/%d/disks/%d/clone", linodeID, diskID)
return doPOSTRequest[InstanceDisk](ctx, c, e, opts)
}
10 changes: 10 additions & 0 deletions instance_nodebalancers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package linodego

import (
"context"
)

// ListInstanceNodeBalancers lists NodeBalancers that the provided instance is a node in
func (c *Client) ListInstanceNodeBalancers(ctx context.Context, linodeID int, opts *ListOptions) ([]NodeBalancer, error) {
return getPaginatedResults[NodeBalancer](ctx, c, formatAPIPath("linode/instances/%d/nodebalancers", linodeID), opts)
}
33 changes: 32 additions & 1 deletion instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ type InstanceTransfer struct {
Quota int `json:"quota"`
}

// MonthlyInstanceTransferStats pool stats for a Linode Instance network transfer statistics for a specific month
type MonthlyInstanceTransferStats struct {
// The amount of inbound public network traffic received by this Linode, in bytes, for a specific year/month.
BytesIn int `json:"bytes_in"`

// The amount of outbound public network traffic sent by this Linode, in bytes, for a specific year/month.
BytesOut int `json:"bytes_out"`

// The total amount of public network traffic sent and received by this Linode, in bytes, for a specific year/month.
BytesTotal int `json:"bytes_total"`
}

// InstancePlacementGroup represents information about the placement group
// this Linode is a part of.
type InstancePlacementGroup struct {
Expand All @@ -133,6 +145,11 @@ type InstanceMetadataOptions struct {
UserData string `json:"user_data,omitempty"`
}

// InstancePasswordResetOptions specifies the new password for the Linode
type InstancePasswordResetOptions struct {
RootPass string `json:"root_pass"`
}

// InstanceCreateOptions require only Region and Type
type InstanceCreateOptions struct {
Region string `json:"region"`
Expand Down Expand Up @@ -278,7 +295,7 @@ func (c *Client) GetInstance(ctx context.Context, linodeID int) (*Instance, erro
return response, nil
}

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

// GetInstanceTransferMonthly gets the instance's network transfer pool statistics for a specific month.
func (c *Client) GetInstanceTransferMonthly(ctx context.Context, linodeID, year, month int) (*MonthlyInstanceTransferStats, error) {
e := formatAPIPath("linode/instances/%d/transfer/%d/%d", linodeID, year, month)
return doGETRequest[MonthlyInstanceTransferStats](ctx, c, e)
}

// CreateInstance creates a Linode instance
func (c *Client) CreateInstance(ctx context.Context, opts InstanceCreateOptions) (*Instance, error) {
e := "linode/instances"
Expand Down Expand Up @@ -348,6 +371,14 @@ func (c *Client) CloneInstance(ctx context.Context, linodeID int, opts InstanceC
return response, nil
}

// ResetInstancePassword resets a Linode instance's root password
func (c *Client) ResetInstancePassword(ctx context.Context, linodeID int, opts InstancePasswordResetOptions) error {
e := formatAPIPath("linode/instances/%d/password", linodeID)
_, err := doPOSTRequest[Instance](ctx, c, e, opts)

return err
}

// RebootInstance reboots a Linode instance
// A configID of 0 will cause Linode to choose the last/best config
func (c *Client) RebootInstance(ctx context.Context, linodeID int, configID int) error {
Expand Down
2 changes: 1 addition & 1 deletion network_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (c *Client) ListIPAddresses(ctx context.Context, opts *ListOptions) ([]Inst
return response, nil
}

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