| 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 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 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 |
|
| 29 |
|
| 30 |
|
| 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 |
|
| 45 |
|
| 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 |
|
| 59 |
|
| 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 |
} |