blob: ee67823f7a61d47f2616d8af008b2f7ce1f3ef14 [file] [log] [blame]
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -07001// TODO(sfalvo): Remove Rackspace-specific Server structure fields and refactor them into a provider-specific access method.
2// Be sure to update godocs accordingly.
3
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -07004package gophercloud
5
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -07006import (
7 "github.com/racker/perigee"
8)
9
Samuel A. Falvo II1dd740a2013-07-08 15:48:40 -070010// genericServersProvider structures provide the implementation for generic OpenStack-compatible
11// CloudServersProvider interfaces.
12type genericServersProvider struct {
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -070013 // endpoint refers to the provider's API endpoint base URL. This will be used to construct
14 // and issue queries.
15 endpoint string
16
17 // Test context (if any) in which to issue requests.
18 context *Context
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -070019
20 // access associates this API provider with a set of credentials,
21 // which may be automatically renewed if they near expiration.
22 access AccessProvider
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -070023}
24
Samuel A. Falvo II1dd740a2013-07-08 15:48:40 -070025// See the CloudServersProvider interface for details.
26func (gcp *genericServersProvider) ListServers() ([]Server, error) {
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -070027 var ss []Server
28
29 url := gcp.endpoint + "/servers"
30 err := perigee.Get(url, perigee.Options{
31 CustomClient: gcp.context.httpClient,
32 Results: &struct{ Servers *[]Server }{&ss},
33 MoreHeaders: map[string]string{
34 "X-Auth-Token": gcp.access.AuthToken(),
35 },
36 })
37 return ss, err
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -070038}
39
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -070040// See the CloudServersProvider interface for details.
41func (gsp *genericServersProvider) ServerById(id string) (*Server, error) {
42 var s *Server
43
44 url := gsp.endpoint + "/servers/" + id
45 err := perigee.Get(url, perigee.Options{
46 Results: &struct{ Server **Server }{&s},
47 MoreHeaders: map[string]string{
48 "X-Auth-Token": gsp.access.AuthToken(),
49 },
50 })
51 return s, err
52}
53
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -070054// RaxBandwidth provides measurement of server bandwidth consumed over a given audit interval.
55type RaxBandwidth struct {
56 AuditPeriodEnd string `json:"audit_period_end"`
57 AuditPeriodStart string `json:"audit_period_start"`
58 BandwidthInbound int64 `json:"bandwidth_inbound"`
59 BandwidthOutbound int64 `json:"bandwidth_outbound"`
60 Interface string `json:"interface"`
61}
62
63// A VersionedAddress denotes either an IPv4 or IPv6 (depending on version indicated)
64// address.
65type VersionedAddress struct {
66 Addr string `json:"addr"`
67 Version int `json:"version"`
68}
69
70// An AddressSet provides a set of public and private IP addresses for a resource.
71// Each address has a version to identify if IPv4 or IPv6.
72type AddressSet struct {
73 Public []VersionedAddress `json:"public"`
74 Private []VersionedAddress `json:"private"`
75}
76
77// Server records represent (virtual) hardware instances (not configurations) accessible by the user.
78//
79// The AccessIPv4 / AccessIPv6 fields provides IP addresses for the server in the IPv4 or IPv6 format, respectively.
80//
81// Addresses provides addresses for any attached isolated networks.
82// The version field indicates whether the IP address is version 4 or 6.
83//
84// Created tells when the server entity was created.
85//
86// The Flavor field includes the flavor ID and flavor links.
87//
88// The compute provisioning algorithm has an anti-affinity property that
89// attempts to spread customer VMs across hosts.
90// Under certain situations,
91// VMs from the same customer might be placed on the same host.
92// The HostId field represents the host your server runs on and
93// can be used to determine this scenario if it is relevant to your application.
94// Note that HostId is unique only per account; it is not globally unique.
95//
96// Id provides the server's unique identifier.
97// This field must be treated opaquely.
98//
99// Image indicates which image is installed on the server.
100//
101// Links provides one or more means of accessing the server.
102//
103// Metadata provides a small key-value store for application-specific information.
104//
105// Name provides a human-readable name for the server.
106//
107// Progress indicates how far along it is towards being provisioned.
108// 100 represents complete, while 0 represents just beginning.
109//
110// Status provides an indication of what the server's doing at the moment.
111// A server will be in ACTIVE state if it's ready for use.
112//
113// OsDcfDiskConfig indicates the server's boot volume configuration.
114// Valid values are:
115// AUTO
116// ----
117// The server is built with a single partition the size of the target flavor disk.
118// The file system is automatically adjusted to fit the entire partition.
119// This keeps things simple and automated.
120// AUTO is valid only for images and servers with a single partition that use the EXT3 file system.
121// This is the default setting for applicable Rackspace base images.
122//
123// MANUAL
124// ------
125// The server is built using whatever partition scheme and file system is in the source image.
126// If the target flavor disk is larger,
127// the remaining disk space is left unpartitioned.
128// This enables images to have non-EXT3 file systems, multiple partitions, and so on,
129// and enables you to manage the disk configuration.
130//
131// RaxBandwidth provides measures of the server's inbound and outbound bandwidth per interface.
132//
133// OsExtStsPowerState provides an indication of the server's power.
134// This field appears to be a set of flag bits:
135//
136// ... 4 3 2 1 0
137// +--//--+---+---+---+---+
138// | .... | 0 | S | 0 | I |
139// +--//--+---+---+---+---+
140// | |
141// | +--- 0=Instance is down.
142// | 1=Instance is up.
143// |
144// +----------- 0=Server is switched ON.
145// 1=Server is switched OFF.
146// (note reverse logic.)
147//
148// Unused bits should be ignored when read, and written as 0 for future compatibility.
149//
150// OsExtStsTaskState and OsExtStsVmState work together
151// to provide visibility in the provisioning process for the instance.
152// Consult Rackspace documentation at
153// http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#ext_status
154// for more details. It's too lengthy to include here.
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -0700155type Server struct {
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -0700156 AccessIPv4 string `json:"accessIPv4"`
157 AccessIPv6 string `json:"accessIPv6"`
158 Addresses AddressSet `json:"addresses"`
159 Created string `json:"created"`
160 Flavor FlavorLink `json:"flavor"`
161 HostId string `json:"hostId"`
162 Id string `json:"id"`
163 Image ImageLink `json:"image"`
164 Links []Link `json:"links"`
165 Metadata interface{} `json:"metadata"`
166 Name string `json:"name"`
167 Progress int `json:"progress"`
168 Status string `json:"status"`
169 TenantId string `json:"tenant_id"`
170 Updated string `json:"updated"`
171 UserId string `json:"user_id"`
172 OsDcfDiskConfig string `json:"OS-DCF:diskConfig"`
173 RaxBandwidth []RaxBandwidth `json:"rax-bandwidth:bandwidth"`
174 OsExtStsPowerState int `json:"OS-EXT-STS:power_state"`
175 OsExtStsTaskState string `json:"OS-EXT-STS:task_state"`
176 OsExtStsVmState string `json:"OS-EXT-STS:vm_state"`
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -0700177}