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