Ash Wilson | 3d89f20 | 2014-10-31 10:23:29 -0400 | [diff] [blame] | 1 | /* |
| 2 | Package gophercloud provides a multi-vendor interface to OpenStack-compatible |
| 3 | clouds. The library has a three-level hierarchy: providers, services, and |
| 4 | resources. |
| 5 | |
| 6 | Provider structs represent the service providers that offer and manage a |
Monty Taylor | 9a5595b | 2017-03-13 13:04:29 -0500 | [diff] [blame] | 7 | collection of services. The IdentityEndpoint is typically refered to as |
| 8 | "auth_url" in information provided by the cloud operator. Additionally, |
| 9 | the cloud may refer to TenantID or TenantName as project_id and project_name. |
| 10 | These are defined like so: |
Ash Wilson | 3d89f20 | 2014-10-31 10:23:29 -0400 | [diff] [blame] | 11 | |
| 12 | opts := gophercloud.AuthOptions{ |
Monty Taylor | 9a5595b | 2017-03-13 13:04:29 -0500 | [diff] [blame] | 13 | IdentityEndpoint: "https://openstack.example.com:5000/v2.0", |
Ash Wilson | 3d89f20 | 2014-10-31 10:23:29 -0400 | [diff] [blame] | 14 | Username: "{username}", |
| 15 | Password: "{password}", |
| 16 | TenantID: "{tenant_id}", |
| 17 | } |
| 18 | |
| 19 | provider, err := openstack.AuthenticatedClient(opts) |
| 20 | |
| 21 | Service structs are specific to a provider and handle all of the logic and |
| 22 | operations for a particular OpenStack service. Examples of services include: |
| 23 | Compute, Object Storage, Block Storage. In order to define one, you need to |
| 24 | pass in the parent provider, like so: |
| 25 | |
| 26 | opts := gophercloud.EndpointOpts{Region: "RegionOne"} |
| 27 | |
| 28 | client := openstack.NewComputeV2(provider, opts) |
| 29 | |
| 30 | Resource structs are the domain models that services make use of in order |
| 31 | to work with and represent the state of API resources: |
| 32 | |
| 33 | server, err := servers.Get(client, "{serverId}").Extract() |
| 34 | |
| 35 | Intermediate Result structs are returned for API operations, which allow |
| 36 | generic access to the HTTP headers, response body, and any errors associated |
| 37 | with the network transaction. To turn a result into a usable resource struct, |
| 38 | you must call the Extract method which is chained to the response, or an |
| 39 | Extract function from an applicable extension: |
| 40 | |
| 41 | result := servers.Get(client, "{serverId}") |
| 42 | |
| 43 | // Attempt to extract the disk configuration from the OS-DCF disk config |
| 44 | // extension: |
| 45 | config, err := diskconfig.ExtractGet(result) |
| 46 | |
| 47 | All requests that enumerate a collection return a Pager struct that is used to |
| 48 | iterate through the results one page at a time. Use the EachPage method on that |
| 49 | Pager to handle each successive Page in a closure, then use the appropriate |
Ash Wilson | aa88fd9 | 2014-10-31 16:11:57 -0400 | [diff] [blame] | 50 | extraction method from that request's package to interpret that Page as a slice |
Ash Wilson | 3d89f20 | 2014-10-31 10:23:29 -0400 | [diff] [blame] | 51 | of results: |
| 52 | |
| 53 | err := servers.List(client, nil).EachPage(func (page pagination.Page) (bool, error) { |
| 54 | s, err := servers.ExtractServers(page) |
| 55 | if err != nil { |
| 56 | return false, err |
| 57 | } |
| 58 | |
| 59 | // Handle the []servers.Server slice. |
| 60 | |
| 61 | // Return "false" or an error to prematurely stop fetching new pages. |
| 62 | return true, nil |
| 63 | }) |
| 64 | |
| 65 | This top-level package contains utility functions and data types that are used |
| 66 | throughout the provider and service packages. Of particular note for end users |
| 67 | are the AuthOptions and EndpointOpts structs. |
| 68 | */ |
| 69 | package gophercloud |