blob: fb81a9d8f174a270677b05e96222914948ae5016 [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
7collection of services. Examples of providers include: OpenStack, Rackspace,
8HP. These are defined like so:
9
10 opts := gophercloud.AuthOptions{
11 IdentityEndpoint: "https://my-openstack.com:5000/v2.0",
12 Username: "{username}",
13 Password: "{password}",
14 TenantID: "{tenant_id}",
15 }
16
17 provider, err := openstack.AuthenticatedClient(opts)
18
19Service structs are specific to a provider and handle all of the logic and
20operations for a particular OpenStack service. Examples of services include:
21Compute, Object Storage, Block Storage. In order to define one, you need to
22pass in the parent provider, like so:
23
24 opts := gophercloud.EndpointOpts{Region: "RegionOne"}
25
26 client := openstack.NewComputeV2(provider, opts)
27
28Resource structs are the domain models that services make use of in order
29to work with and represent the state of API resources:
30
31 server, err := servers.Get(client, "{serverId}").Extract()
32
33Intermediate Result structs are returned for API operations, which allow
34generic access to the HTTP headers, response body, and any errors associated
35with the network transaction. To turn a result into a usable resource struct,
36you must call the Extract method which is chained to the response, or an
37Extract function from an applicable extension:
38
39 result := servers.Get(client, "{serverId}")
40
41 // Attempt to extract the disk configuration from the OS-DCF disk config
42 // extension:
43 config, err := diskconfig.ExtractGet(result)
44
45All requests that enumerate a collection return a Pager struct that is used to
46iterate through the results one page at a time. Use the EachPage method on that
47Pager to handle each successive Page in a closure, then use the appropriate
Ash Wilsonaa88fd92014-10-31 16:11:57 -040048extraction method from that request's package to interpret that Page as a slice
Ash Wilson3d89f202014-10-31 10:23:29 -040049of results:
50
51 err := servers.List(client, nil).EachPage(func (page pagination.Page) (bool, error) {
52 s, err := servers.ExtractServers(page)
53 if err != nil {
54 return false, err
55 }
56
57 // Handle the []servers.Server slice.
58
59 // Return "false" or an error to prematurely stop fetching new pages.
60 return true, nil
61 })
62
63This top-level package contains utility functions and data types that are used
64throughout the provider and service packages. Of particular note for end users
65are the AuthOptions and EndpointOpts structs.
66*/
67package gophercloud