Debian Codegraph @

cloudapi/packages.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 // Package represents a named collections of resources that are used to describe the 'sizes'
9 // of either a smart machine or a virtual machine.
10 type Package struct {
11 Name string // Name for the package
12 Memory int // Memory available (in Mb)
13 Disk int // Disk space available (in Gb)
14 Swap int // Swap memory available (in Mb)
15 VCPUs int // Number of VCPUs for the package
16 Default bool // Indicates whether this is the default package in the datacenter
17 Id string // Unique identifier for the package
18 Version string // Version for the package
19 Group string // Group this package belongs to
20 Description string // Human friendly description for the package
21 }
22
23 // ListPackages provides a list of packages available in the datacenter.
24 // See API docs: http://apidocs.joyent.com/cloudapi/#ListPackages
25 func (c *Client) ListPackages(filter *Filter) ([]Package, error) {
26 var resp []Package
27 req := request{
28 method: client.GET,
29 url: apiPackages,
30 filter: filter,
31 resp: &resp,
32 }
33 if _, err := c.sendRequest(req); err != nil {
34 return nil, errors.Newf(err, "failed to get list of packages")
35 }
36 return resp, nil
37 }
38
39 // GetPackage returns the package specified by packageName. NOTE: packageName can
40 // specify either the package name or package ID.
41 // See API docs: http://apidocs.joyent.com/cloudapi/#GetPackage
42 func (c *Client) GetPackage(packageName string) (*Package, error) {
43 var resp Package
44 req := request{
45 method: client.GET,
46 url: makeURL(apiPackages, packageName),
47 resp: &resp,
48 }
49 if _, err := c.sendRequest(req); err != nil {
50 return nil, errors.Newf(err, "failed to get package with name: %s", packageName)
51 }
52 return &resp, nil
53 }