Debian Codegraph @

cloudapi/datacenters.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 // ListDatacenters provides a list of all datacenters this cloud is aware of.
11 // See API docs: http://apidocs.joyent.com/cloudapi/#ListDatacenters
12 func (c *Client) ListDatacenters() (map[string]interface{}, error) {
13 var resp map[string]interface{}
14 req := request{
15 method: client.GET,
16 url: apiDatacenters,
17 resp: &resp,
18 }
19 if _, err := c.sendRequest(req); err != nil {
20 return nil, errors.Newf(err, "failed to get list of datcenters")
21 }
22 return resp, nil
23 }
24
25 // GetDatacenter gets an individual datacenter by name. Returns an HTTP redirect
26 // to your client, the datacenter URL is in the Location header.
27 // See API docs: http://apidocs.joyent.com/cloudapi/#GetDatacenter
28 func (c *Client) GetDatacenter(datacenterName string) (string, error) {
29 var respHeader http.Header
30 req := request{
31 method: client.GET,
32 url: makeURL(apiDatacenters, datacenterName),
33 respHeader: &respHeader,
34 expectedStatus: http.StatusFound,
35 }
36 respData, err := c.sendRequest(req)
37 if err != nil {
38 return "", errors.Newf(err, "failed to get datacenter with name: %s", datacenterName)
39 }
40 return respData.RespHeaders.Get("Location"), nil
41 }