2016-01-29 20:53:56 +01:00
|
|
|
package godo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
2017-05-15 15:54:16 +02:00
|
|
|
|
|
|
|
"github.com/digitalocean/godo/context"
|
2016-01-29 20:53:56 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// ActionRequest reprents DigitalOcean Action Request
|
|
|
|
type ActionRequest map[string]interface{}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// DropletActionsService is an interface for interfacing with the Droplet actions
|
2016-01-29 20:53:56 +01:00
|
|
|
// endpoints of the DigitalOcean API
|
|
|
|
// See: https://developers.digitalocean.com/documentation/v2#droplet-actions
|
|
|
|
type DropletActionsService interface {
|
2017-05-15 15:54:16 +02:00
|
|
|
Shutdown(context.Context, int) (*Action, *Response, error)
|
2017-06-06 18:16:43 +02:00
|
|
|
ShutdownByTag(context.Context, string) ([]Action, *Response, error)
|
2017-05-15 15:54:16 +02:00
|
|
|
PowerOff(context.Context, int) (*Action, *Response, error)
|
2017-06-06 18:16:43 +02:00
|
|
|
PowerOffByTag(context.Context, string) ([]Action, *Response, error)
|
2017-05-15 15:54:16 +02:00
|
|
|
PowerOn(context.Context, int) (*Action, *Response, error)
|
2017-06-06 18:16:43 +02:00
|
|
|
PowerOnByTag(context.Context, string) ([]Action, *Response, error)
|
2017-05-15 15:54:16 +02:00
|
|
|
PowerCycle(context.Context, int) (*Action, *Response, error)
|
2017-06-06 18:16:43 +02:00
|
|
|
PowerCycleByTag(context.Context, string) ([]Action, *Response, error)
|
2017-05-15 15:54:16 +02:00
|
|
|
Reboot(context.Context, int) (*Action, *Response, error)
|
|
|
|
Restore(context.Context, int, int) (*Action, *Response, error)
|
|
|
|
Resize(context.Context, int, string, bool) (*Action, *Response, error)
|
|
|
|
Rename(context.Context, int, string) (*Action, *Response, error)
|
|
|
|
Snapshot(context.Context, int, string) (*Action, *Response, error)
|
2017-06-06 18:16:43 +02:00
|
|
|
SnapshotByTag(context.Context, string, string) ([]Action, *Response, error)
|
2017-05-15 15:54:16 +02:00
|
|
|
EnableBackups(context.Context, int) (*Action, *Response, error)
|
2017-06-06 18:16:43 +02:00
|
|
|
EnableBackupsByTag(context.Context, string) ([]Action, *Response, error)
|
2017-05-15 15:54:16 +02:00
|
|
|
DisableBackups(context.Context, int) (*Action, *Response, error)
|
2017-06-06 18:16:43 +02:00
|
|
|
DisableBackupsByTag(context.Context, string) ([]Action, *Response, error)
|
2017-05-15 15:54:16 +02:00
|
|
|
PasswordReset(context.Context, int) (*Action, *Response, error)
|
|
|
|
RebuildByImageID(context.Context, int, int) (*Action, *Response, error)
|
|
|
|
RebuildByImageSlug(context.Context, int, string) (*Action, *Response, error)
|
|
|
|
ChangeKernel(context.Context, int, int) (*Action, *Response, error)
|
|
|
|
EnableIPv6(context.Context, int) (*Action, *Response, error)
|
2017-06-06 18:16:43 +02:00
|
|
|
EnableIPv6ByTag(context.Context, string) ([]Action, *Response, error)
|
2017-05-15 15:54:16 +02:00
|
|
|
EnablePrivateNetworking(context.Context, int) (*Action, *Response, error)
|
2017-06-06 18:16:43 +02:00
|
|
|
EnablePrivateNetworkingByTag(context.Context, string) ([]Action, *Response, error)
|
2017-05-15 15:54:16 +02:00
|
|
|
Upgrade(context.Context, int) (*Action, *Response, error)
|
|
|
|
Get(context.Context, int, int) (*Action, *Response, error)
|
|
|
|
GetByURI(context.Context, string) (*Action, *Response, error)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// DropletActionsServiceOp handles communication with the Droplet action related
|
2016-01-29 20:53:56 +01:00
|
|
|
// methods of the DigitalOcean API.
|
|
|
|
type DropletActionsServiceOp struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ DropletActionsService = &DropletActionsServiceOp{}
|
|
|
|
|
|
|
|
// Shutdown a Droplet
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) Shutdown(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "shutdown"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// ShutdownByTag shuts down Droplets matched by a Tag.
|
2017-06-06 18:16:43 +02:00
|
|
|
func (s *DropletActionsServiceOp) ShutdownByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
|
2016-07-11 13:09:06 +02:00
|
|
|
request := &ActionRequest{"type": "shutdown"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doActionByTag(ctx, tag, request)
|
2016-07-11 13:09:06 +02:00
|
|
|
}
|
|
|
|
|
2016-01-29 20:53:56 +01:00
|
|
|
// PowerOff a Droplet
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) PowerOff(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "power_off"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// PowerOffByTag powers off Droplets matched by a Tag.
|
2017-06-06 18:16:43 +02:00
|
|
|
func (s *DropletActionsServiceOp) PowerOffByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
|
2016-07-11 13:09:06 +02:00
|
|
|
request := &ActionRequest{"type": "power_off"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doActionByTag(ctx, tag, request)
|
2016-07-11 13:09:06 +02:00
|
|
|
}
|
|
|
|
|
2016-01-29 20:53:56 +01:00
|
|
|
// PowerOn a Droplet
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) PowerOn(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "power_on"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// PowerOnByTag powers on Droplets matched by a Tag.
|
2017-06-06 18:16:43 +02:00
|
|
|
func (s *DropletActionsServiceOp) PowerOnByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
|
2016-07-11 13:09:06 +02:00
|
|
|
request := &ActionRequest{"type": "power_on"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doActionByTag(ctx, tag, request)
|
2016-07-11 13:09:06 +02:00
|
|
|
}
|
|
|
|
|
2016-01-29 20:53:56 +01:00
|
|
|
// PowerCycle a Droplet
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) PowerCycle(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "power_cycle"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// PowerCycleByTag power cycles Droplets matched by a Tag.
|
2017-06-06 18:16:43 +02:00
|
|
|
func (s *DropletActionsServiceOp) PowerCycleByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
|
2016-07-11 13:09:06 +02:00
|
|
|
request := &ActionRequest{"type": "power_cycle"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doActionByTag(ctx, tag, request)
|
2016-07-11 13:09:06 +02:00
|
|
|
}
|
|
|
|
|
2016-01-29 20:53:56 +01:00
|
|
|
// Reboot a Droplet
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) Reboot(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "reboot"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restore an image to a Droplet
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) Restore(ctx context.Context, id, imageID int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
requestType := "restore"
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": requestType,
|
|
|
|
"image": float64(imageID),
|
|
|
|
}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Resize a Droplet
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) Resize(ctx context.Context, id int, sizeSlug string, resizeDisk bool) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
requestType := "resize"
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": requestType,
|
|
|
|
"size": sizeSlug,
|
|
|
|
"disk": resizeDisk,
|
|
|
|
}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rename a Droplet
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) Rename(ctx context.Context, id int, name string) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
requestType := "rename"
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": requestType,
|
|
|
|
"name": name,
|
|
|
|
}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Snapshot a Droplet.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) Snapshot(ctx context.Context, id int, name string) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
requestType := "snapshot"
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": requestType,
|
|
|
|
"name": name,
|
|
|
|
}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// SnapshotByTag snapshots Droplets matched by a Tag.
|
2017-06-06 18:16:43 +02:00
|
|
|
func (s *DropletActionsServiceOp) SnapshotByTag(ctx context.Context, tag string, name string) ([]Action, *Response, error) {
|
2016-07-11 13:09:06 +02:00
|
|
|
requestType := "snapshot"
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": requestType,
|
|
|
|
"name": name,
|
|
|
|
}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doActionByTag(ctx, tag, request)
|
2016-07-11 13:09:06 +02:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// EnableBackups enables backups for a Droplet.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) EnableBackups(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "enable_backups"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// EnableBackupsByTag enables backups for Droplets matched by a Tag.
|
2017-06-06 18:16:43 +02:00
|
|
|
func (s *DropletActionsServiceOp) EnableBackupsByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
|
2016-07-11 13:09:06 +02:00
|
|
|
request := &ActionRequest{"type": "enable_backups"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doActionByTag(ctx, tag, request)
|
2016-07-11 13:09:06 +02:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// DisableBackups disables backups for a Droplet.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) DisableBackups(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "disable_backups"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// DisableBackupsByTag disables backups for Droplet matched by a Tag.
|
2017-06-06 18:16:43 +02:00
|
|
|
func (s *DropletActionsServiceOp) DisableBackupsByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
|
2016-07-11 13:09:06 +02:00
|
|
|
request := &ActionRequest{"type": "disable_backups"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doActionByTag(ctx, tag, request)
|
2016-07-11 13:09:06 +02:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// PasswordReset resets the password for a Droplet.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) PasswordReset(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "password_reset"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// RebuildByImageID rebuilds a Droplet from an image with a given id.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) RebuildByImageID(ctx context.Context, id, imageID int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "rebuild", "image": imageID}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// RebuildByImageSlug rebuilds a Droplet from an Image matched by a given Slug.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) RebuildByImageSlug(ctx context.Context, id int, slug string) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "rebuild", "image": slug}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// ChangeKernel changes the kernel for a Droplet.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) ChangeKernel(ctx context.Context, id, kernelID int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "change_kernel", "kernel": kernelID}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// EnableIPv6 enables IPv6 for a Droplet.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) EnableIPv6(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "enable_ipv6"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// EnableIPv6ByTag enables IPv6 for Droplets matched by a Tag.
|
2017-06-06 18:16:43 +02:00
|
|
|
func (s *DropletActionsServiceOp) EnableIPv6ByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
|
2016-07-11 13:09:06 +02:00
|
|
|
request := &ActionRequest{"type": "enable_ipv6"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doActionByTag(ctx, tag, request)
|
2016-07-11 13:09:06 +02:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// EnablePrivateNetworking enables private networking for a Droplet.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) EnablePrivateNetworking(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "enable_private_networking"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// EnablePrivateNetworkingByTag enables private networking for Droplets matched by a Tag.
|
2017-06-06 18:16:43 +02:00
|
|
|
func (s *DropletActionsServiceOp) EnablePrivateNetworkingByTag(ctx context.Context, tag string) ([]Action, *Response, error) {
|
2016-07-11 13:09:06 +02:00
|
|
|
request := &ActionRequest{"type": "enable_private_networking"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doActionByTag(ctx, tag, request)
|
2016-07-11 13:09:06 +02:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// Upgrade a Droplet.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) Upgrade(ctx context.Context, id int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
request := &ActionRequest{"type": "upgrade"}
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.doAction(ctx, id, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) doAction(ctx context.Context, id int, request *ActionRequest) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
if id < 1 {
|
|
|
|
return nil, nil, NewArgError("id", "cannot be less than 1")
|
|
|
|
}
|
|
|
|
|
|
|
|
if request == nil {
|
|
|
|
return nil, nil, NewArgError("request", "request can't be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
path := dropletActionPath(id)
|
|
|
|
|
2017-05-15 15:54:16 +02:00
|
|
|
req, err := s.client.NewRequest(ctx, "POST", path, request)
|
2016-01-29 20:53:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
root := new(actionRoot)
|
2017-05-15 15:54:16 +02:00
|
|
|
resp, err := s.client.Do(ctx, req, root)
|
2016-01-29 20:53:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
return root.Event, resp, err
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 18:16:43 +02:00
|
|
|
func (s *DropletActionsServiceOp) doActionByTag(ctx context.Context, tag string, request *ActionRequest) ([]Action, *Response, error) {
|
2016-07-11 13:09:06 +02:00
|
|
|
if tag == "" {
|
|
|
|
return nil, nil, NewArgError("tag", "cannot be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if request == nil {
|
|
|
|
return nil, nil, NewArgError("request", "request can't be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
path := dropletActionPathByTag(tag)
|
|
|
|
|
2017-05-15 15:54:16 +02:00
|
|
|
req, err := s.client.NewRequest(ctx, "POST", path, request)
|
2016-07-11 13:09:06 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2017-06-06 18:16:43 +02:00
|
|
|
root := new(actionsRoot)
|
2017-05-15 15:54:16 +02:00
|
|
|
resp, err := s.client.Do(ctx, req, root)
|
2016-07-11 13:09:06 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
2017-06-06 18:16:43 +02:00
|
|
|
return root.Actions, resp, err
|
2016-07-11 13:09:06 +02:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// Get an action for a particular Droplet by id.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) Get(ctx context.Context, dropletID, actionID int) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
if dropletID < 1 {
|
|
|
|
return nil, nil, NewArgError("dropletID", "cannot be less than 1")
|
|
|
|
}
|
|
|
|
|
|
|
|
if actionID < 1 {
|
|
|
|
return nil, nil, NewArgError("actionID", "cannot be less than 1")
|
|
|
|
}
|
|
|
|
|
|
|
|
path := fmt.Sprintf("%s/%d", dropletActionPath(dropletID), actionID)
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.get(ctx, path)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
// GetByURI gets an action for a particular Droplet by id.
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) GetByURI(ctx context.Context, rawurl string) (*Action, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
u, err := url.Parse(rawurl)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2017-05-15 15:54:16 +02:00
|
|
|
return s.get(ctx, u.Path)
|
2016-01-29 20:53:56 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *DropletActionsServiceOp) get(ctx context.Context, path string) (*Action, *Response, error) {
|
|
|
|
req, err := s.client.NewRequest(ctx, "GET", path, nil)
|
2016-01-29 20:53:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
root := new(actionRoot)
|
2017-05-15 15:54:16 +02:00
|
|
|
resp, err := s.client.Do(ctx, req, root)
|
2016-01-29 20:53:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
2017-02-15 15:35:41 +01:00
|
|
|
return root.Event, resp, err
|
2016-01-29 20:53:56 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func dropletActionPath(dropletID int) string {
|
|
|
|
return fmt.Sprintf("v2/droplets/%d/actions", dropletID)
|
|
|
|
}
|
2016-07-11 13:09:06 +02:00
|
|
|
|
|
|
|
func dropletActionPathByTag(tag string) string {
|
|
|
|
return fmt.Sprintf("v2/droplets/actions?tag_name=%s", tag)
|
|
|
|
}
|