blob: b559516f91a1ca604df131d722b46b8969fd2215 [file] [log] [blame]
Ash Wilson3d89f202014-10-31 10:23:29 -04001/*
2Package gophercloud provides a multi-vendor interface to OpenStack-compatible
3clouds. The library has a three-level hierarchy: providers, services, and
4resources.
5
6Provider structs represent the service providers that offer and manage a
Monty Taylor9a5595b2017-03-13 13:04:29 -05007collection of services. The IdentityEndpoint is typically refered to as
8"auth_url" in information provided by the cloud operator. Additionally,
9the cloud may refer to TenantID or TenantName as project_id and project_name.
10These are defined like so:
Ash Wilson3d89f202014-10-31 10:23:29 -040011
12 opts := gophercloud.AuthOptions{
Monty Taylor9a5595b2017-03-13 13:04:29 -050013 IdentityEndpoint: "https://openstack.example.com:5000/v2.0",
Ash Wilson3d89f202014-10-31 10:23:29 -040014 Username: "{username}",
15 Password: "{password}",
16 TenantID: "{tenant_id}",
17 }
18
19 provider, err := openstack.AuthenticatedClient(opts)
20
21Service structs are specific to a provider and handle all of the logic and
22operations for a particular OpenStack service. Examples of services include:
23Compute, Object Storage, Block Storage. In order to define one, you need to
24pass in the parent provider, like so:
25
26 opts := gophercloud.EndpointOpts{Region: "RegionOne"}
27
28 client := openstack.NewComputeV2(provider, opts)
29
30Resource structs are the domain models that services make use of in order
31to work with and represent the state of API resources:
32
33 server, err := servers.Get(client, "{serverId}").Extract()
34
35Intermediate Result structs are returned for API operations, which allow
36generic access to the HTTP headers, response body, and any errors associated
37with the network transaction. To turn a result into a usable resource struct,
38you must call the Extract method which is chained to the response, or an
39Extract 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
47All requests that enumerate a collection return a Pager struct that is used to
48iterate through the results one page at a time. Use the EachPage method on that
49Pager to handle each successive Page in a closure, then use the appropriate
Ash Wilsonaa88fd92014-10-31 16:11:57 -040050extraction method from that request's package to interpret that Page as a slice
Ash Wilson3d89f202014-10-31 10:23:29 -040051of 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
65This top-level package contains utility functions and data types that are used
66throughout the provider and service packages. Of particular note for end users
67are the AuthOptions and EndpointOpts structs.
68*/
69package gophercloud