blob: 29a1fc577130ff7216ba96136c474e7a74aff2c1 [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 IIe91ff6d2013-07-11 15:46:10 -070054// See the CloudServersProvider interface for details.
55func (gsp *genericServersProvider) CreateServer(ns NewServer) (*NewServer, error) {
56 var s *NewServer
57
58 ep := gsp.endpoint + "/servers"
59 err := perigee.Post(ep, perigee.Options{
60 ReqBody: &struct {
61 Server *NewServer `json:"server"`
62 }{&ns},
63 Results: &struct{ Server **NewServer }{&s},
64 MoreHeaders: map[string]string{
65 "X-Auth-Token": gsp.access.AuthToken(),
66 },
67 OkCodes: []int{202},
68 })
69 return s, err
70}
71
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -070072// RaxBandwidth provides measurement of server bandwidth consumed over a given audit interval.
73type RaxBandwidth struct {
74 AuditPeriodEnd string `json:"audit_period_end"`
75 AuditPeriodStart string `json:"audit_period_start"`
76 BandwidthInbound int64 `json:"bandwidth_inbound"`
77 BandwidthOutbound int64 `json:"bandwidth_outbound"`
78 Interface string `json:"interface"`
79}
80
81// A VersionedAddress denotes either an IPv4 or IPv6 (depending on version indicated)
82// address.
83type VersionedAddress struct {
84 Addr string `json:"addr"`
85 Version int `json:"version"`
86}
87
88// An AddressSet provides a set of public and private IP addresses for a resource.
89// Each address has a version to identify if IPv4 or IPv6.
90type AddressSet struct {
91 Public []VersionedAddress `json:"public"`
92 Private []VersionedAddress `json:"private"`
93}
94
95// Server records represent (virtual) hardware instances (not configurations) accessible by the user.
96//
97// The AccessIPv4 / AccessIPv6 fields provides IP addresses for the server in the IPv4 or IPv6 format, respectively.
98//
99// Addresses provides addresses for any attached isolated networks.
100// The version field indicates whether the IP address is version 4 or 6.
101//
102// Created tells when the server entity was created.
103//
104// The Flavor field includes the flavor ID and flavor links.
105//
106// The compute provisioning algorithm has an anti-affinity property that
107// attempts to spread customer VMs across hosts.
108// Under certain situations,
109// VMs from the same customer might be placed on the same host.
110// The HostId field represents the host your server runs on and
111// can be used to determine this scenario if it is relevant to your application.
112// Note that HostId is unique only per account; it is not globally unique.
113//
114// Id provides the server's unique identifier.
115// This field must be treated opaquely.
116//
117// Image indicates which image is installed on the server.
118//
119// Links provides one or more means of accessing the server.
120//
121// Metadata provides a small key-value store for application-specific information.
122//
123// Name provides a human-readable name for the server.
124//
125// Progress indicates how far along it is towards being provisioned.
126// 100 represents complete, while 0 represents just beginning.
127//
128// Status provides an indication of what the server's doing at the moment.
129// A server will be in ACTIVE state if it's ready for use.
130//
131// OsDcfDiskConfig indicates the server's boot volume configuration.
132// Valid values are:
133// AUTO
134// ----
135// The server is built with a single partition the size of the target flavor disk.
136// The file system is automatically adjusted to fit the entire partition.
137// This keeps things simple and automated.
138// AUTO is valid only for images and servers with a single partition that use the EXT3 file system.
139// This is the default setting for applicable Rackspace base images.
140//
141// MANUAL
142// ------
143// The server is built using whatever partition scheme and file system is in the source image.
144// If the target flavor disk is larger,
145// the remaining disk space is left unpartitioned.
146// This enables images to have non-EXT3 file systems, multiple partitions, and so on,
147// and enables you to manage the disk configuration.
148//
149// RaxBandwidth provides measures of the server's inbound and outbound bandwidth per interface.
150//
151// OsExtStsPowerState provides an indication of the server's power.
152// This field appears to be a set of flag bits:
153//
154// ... 4 3 2 1 0
155// +--//--+---+---+---+---+
156// | .... | 0 | S | 0 | I |
157// +--//--+---+---+---+---+
158// | |
159// | +--- 0=Instance is down.
160// | 1=Instance is up.
161// |
162// +----------- 0=Server is switched ON.
163// 1=Server is switched OFF.
164// (note reverse logic.)
165//
166// Unused bits should be ignored when read, and written as 0 for future compatibility.
167//
168// OsExtStsTaskState and OsExtStsVmState work together
169// to provide visibility in the provisioning process for the instance.
170// Consult Rackspace documentation at
171// http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#ext_status
172// for more details. It's too lengthy to include here.
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -0700173type Server struct {
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -0700174 AccessIPv4 string `json:"accessIPv4"`
175 AccessIPv6 string `json:"accessIPv6"`
176 Addresses AddressSet `json:"addresses"`
177 Created string `json:"created"`
178 Flavor FlavorLink `json:"flavor"`
179 HostId string `json:"hostId"`
180 Id string `json:"id"`
181 Image ImageLink `json:"image"`
182 Links []Link `json:"links"`
183 Metadata interface{} `json:"metadata"`
184 Name string `json:"name"`
185 Progress int `json:"progress"`
186 Status string `json:"status"`
187 TenantId string `json:"tenant_id"`
188 Updated string `json:"updated"`
189 UserId string `json:"user_id"`
190 OsDcfDiskConfig string `json:"OS-DCF:diskConfig"`
191 RaxBandwidth []RaxBandwidth `json:"rax-bandwidth:bandwidth"`
192 OsExtStsPowerState int `json:"OS-EXT-STS:power_state"`
193 OsExtStsTaskState string `json:"OS-EXT-STS:task_state"`
194 OsExtStsVmState string `json:"OS-EXT-STS:vm_state"`
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -0700195}
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -0700196
197// NewServer structures are used for both requests and responses.
198// The fields discussed below are relevent for server-creation purposes.
199//
200// The Name field contains the desired name of the server.
201// Note that (at present) Rackspace permits more than one server with the same name;
202// however, software should not depend on this.
203// Not only will Rackspace support thank you, so will your own devops engineers.
204// A name is required.
205//
206// The ImageRef field contains the ID of the desired software image to place on the server.
207// This ID must be found in the image slice returned by the Images() function.
208// This field is required.
209//
210// The FlavorRef field contains the ID of the server configuration desired for deployment.
211// This ID must be found in the flavor slice returned by the Flavors() function.
212// This field is required.
213//
214// For OsDcfDiskConfig, refer to the Image or Server structure documentation.
215// This field defaults to "AUTO" if not explicitly provided.
216//
217// Metadata contains a small key/value association of arbitrary data.
218// Neither Rackspace nor OpenStack places significance on this field in any way.
219// This field defaults to an empty map if not provided.
220//
221// Personality specifies the contents of certain files in the server's filesystem.
222// The files and their contents are mapped through a slice of FileConfig structures.
223// If not provided, all filesystem entities retain their image-specific configuration.
224//
225// Networks specifies an affinity for the server's various networks and interfaces.
226// Networks are identified through UUIDs; see NetworkConfig structure documentation for more details.
227// If not provided, network affinity is determined automatically.
228//
229// The AdminPass field may be used to provide a root- or administrator-password
230// during the server provisioning process.
231// If not provided, a random password will be automatically generated and returned in this field.
232//
233// The following fields are intended to be used to communicate certain results about the server being provisioned.
234// When attempting to create a new server, these fields MUST not be provided.
235// They'll be filled in by the response received from the Rackspace APIs.
236//
237// The Id field contains the server's unique identifier.
238// The identifier's scope is best assumed to be bound by the user's account, unless other arrangements have been made with Rackspace.
239//
240// Any Links provided are used to refer to the server specifically by URL.
241// These links are useful for making additional REST calls not explicitly supported by Gorax.
242type NewServer struct {
243 Name string `json:"name",omitempty`
244 ImageRef string `json:"imageRef,omitempty"`
245 FlavorRef string `json:"flavorRef,omitempty"`
246 Metadata interface{} `json:"metadata,omitempty"`
247 Personality []FileConfig `json:"personality,omitempty"`
248 Networks []NetworkConfig `json:"networks,omitempty"`
249 AdminPass string `json:"adminPass,omitempty"`
250 Id string `json:"id,omitempty"`
251 Links []Link `json:"links,omitempty"`
252 OsDcfDiskConfig string `json:"OS-DCF:diskConfig,omitempty"`
253}