Debian Codegraph @

cloudapi/machine_metadata.go

raw symbols SCIP
1 package cloudapi
2
3 import (
4 "net/http"
5
6 "github.com/joyent/gocommon/client"
7 "github.com/joyent/gocommon/errors"
8 )
9
10 // UpdateMachineMetadata updates the metadata for a given machine.
11 // Any metadata keys passed in here are created if they do not exist, and
12 // overwritten if they do.
13 // See API docs: http://apidocs.joyent.com/cloudapi/#UpdateMachineMetadata
14 func (c *Client) UpdateMachineMetadata(machineID string, metadata map[string]string) (map[string]interface{}, error) {
15 var resp map[string]interface{}
16 req := request{
17 method: client.POST,
18 url: makeURL(apiMachines, machineID, apiMetadata),
19 reqValue: metadata,
20 resp: &resp,
21 }
22 if _, err := c.sendRequest(req); err != nil {
23 return nil, errors.Newf(err, "failed to update metadata for machine with id %s", machineID)
24 }
25 return resp, nil
26 }
27
28 // GetMachineMetadata returns the complete set of metadata associated with the
29 // specified machine.
30 // See API docs: http://apidocs.joyent.com/cloudapi/#GetMachineMetadata
31 func (c *Client) GetMachineMetadata(machineID string) (map[string]interface{}, error) {
32 var resp map[string]interface{}
33 req := request{
34 method: client.GET,
35 url: makeURL(apiMachines, machineID, apiMetadata),
36 resp: &resp,
37 }
38 if _, err := c.sendRequest(req); err != nil {
39 return nil, errors.Newf(err, "failed to get list of metadata for machine with id %s", machineID)
40 }
41 return resp, nil
42 }
43
44 // DeleteMachineMetadata deletes a single metadata key from the specified machine.
45 // See API docs: http://apidocs.joyent.com/cloudapi/#DeleteMachineMetadata
46 func (c *Client) DeleteMachineMetadata(machineID, metadataKey string) error {
47 req := request{
48 method: client.DELETE,
49 url: makeURL(apiMachines, machineID, apiMetadata, metadataKey),
50 expectedStatus: http.StatusNoContent,
51 }
52 if _, err := c.sendRequest(req); err != nil {
53 return errors.Newf(err, "failed to delete metadata with key %s for machine with id %s", metadataKey, machineID)
54 }
55 return nil
56 }
57
58 // DeleteAllMachineMetadata deletes all metadata keys from the specified machine.
59 // See API docs: http://apidocs.joyent.com/cloudapi/#DeleteAllMachineMetadata
60 func (c *Client) DeleteAllMachineMetadata(machineID string) error {
61 req := request{
62 method: client.DELETE,
63 url: makeURL(apiMachines, machineID, apiMetadata),
64 expectedStatus: http.StatusNoContent,
65 }
66 if _, err := c.sendRequest(req); err != nil {
67 return errors.Newf(err, "failed to delete metadata for machine with id %s", machineID)
68 }
69 return nil
70 }