File: packages.go

package info (click to toggle)
golang-github-joyent-gosdc 0.0~git20161202.ec8b350-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 472 kB
  • sloc: makefile: 3
file content (53 lines) | stat: -rw-r--r-- 1,837 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package cloudapi

import (
	"github.com/joyent/gocommon/client"
	"github.com/joyent/gocommon/errors"
)

// Package represents a named collections of resources that are used to describe the 'sizes'
// of either a smart machine or a virtual machine.
type Package struct {
	Name        string // Name for the package
	Memory      int    // Memory available (in Mb)
	Disk        int    // Disk space available (in Gb)
	Swap        int    // Swap memory available (in Mb)
	VCPUs       int    // Number of VCPUs for the package
	Default     bool   // Indicates whether this is the default package in the datacenter
	Id          string // Unique identifier for the package
	Version     string // Version for the package
	Group       string // Group this package belongs to
	Description string // Human friendly description for the package
}

// ListPackages provides a list of packages available in the datacenter.
// See API docs: http://apidocs.joyent.com/cloudapi/#ListPackages
func (c *Client) ListPackages(filter *Filter) ([]Package, error) {
	var resp []Package
	req := request{
		method: client.GET,
		url:    apiPackages,
		filter: filter,
		resp:   &resp,
	}
	if _, err := c.sendRequest(req); err != nil {
		return nil, errors.Newf(err, "failed to get list of packages")
	}
	return resp, nil
}

// GetPackage returns the package specified by packageName. NOTE: packageName can
// specify either the package name or package ID.
// See API docs: http://apidocs.joyent.com/cloudapi/#GetPackage
func (c *Client) GetPackage(packageName string) (*Package, error) {
	var resp Package
	req := request{
		method: client.GET,
		url:    makeURL(apiPackages, packageName),
		resp:   &resp,
	}
	if _, err := c.sendRequest(req); err != nil {
		return nil, errors.Newf(err, "failed to get package with name: %s", packageName)
	}
	return &resp, nil
}