Debian Codegraph @

cloudapi/networks.go

raw symbols SCIP
1 package cloudapi
2
3 import (
4 "github.com/joyent/gocommon/client"
5 "github.com/joyent/gocommon/errors"
6 )
7
8 // Network represents a network available to a given account
9 type Network struct {
10 Id string // Unique identifier for the network
11 Name string // Network name
12 Public bool // Whether this a public or private (rfc1918) network
13 Description string // Optional description for this network, when name is not enough
14 }
15
16 // ListNetworks lists all the networks which can be used by the given account.
17 // See API docs: http://apidocs.joyent.com/cloudapi/#ListNetworks
18 func (c *Client) ListNetworks() ([]Network, error) {
19 var resp []Network
20 req := request{
21 method: client.GET,
22 url: apiNetworks,
23 resp: &resp,
24 }
25 if _, err := c.sendRequest(req); err != nil {
26 return nil, errors.Newf(err, "failed to get list of networks")
27 }
28 return resp, nil
29 }
30
31 // GetNetwork retrieves an individual network record.
32 // See API docs: http://apidocs.joyent.com/cloudapi/#GetNetwork
33 func (c *Client) GetNetwork(networkID string) (*Network, error) {
34 var resp Network
35 req := request{
36 method: client.GET,
37 url: makeURL(apiNetworks, networkID),
38 resp: &resp,
39 }
40 if _, err := c.sendRequest(req); err != nil {
41 return nil, errors.Newf(err, "failed to get network with id %s", networkID)
42 }
43 return &resp, nil
44 }