blob: a731b9575c2932a9b7a4d52bec8b7ad2bb4996bf [file] [log] [blame] [view]
Jamie Hannaford4eb3f962014-10-07 11:50:00 +02001# gophercloud
2
3gophercloud is a flexible SDK that allows you to consume and work with OpenStack
4clouds in a simple and idiomatic way using golang. Many services are supported,
5including Compute, Block Storage, Object Storage, Networking, and Identity.
6Each service API is backed with documentation, code samples, unit tests and
7acceptance tests.
8
9## How to install
10
11Before installing, you need to ensure that your [GOPATH environment variable](https://golang.org/doc/code.html#GOPATH)
12is pointing to an appropriate directory where you want to install gophercloud:
13
14```bash
15mkdir $HOME/go
16export GOPATH=$HOME/go
17```
18
19Once this is set up, you can install the gophercloud package like so:
20
21```bash
22go get github.com/rackspace/gophercloud
23```
24
25This will install all the source files you need into a `pkg` directory, which is
26referenceable from your own source files.
27
28## Getting started
29
30### Credentials
31
32Because you'll be hitting an API, you will need to retrieve your OpenStack
33credentials and either store them as environment variables or in your local Go
34files. The first method is recommended because it decouples credential
35information from source code, allowing you to push the latter to your version
36control system without any security risk.
37
38You will need to retrieve the following:
39
40* username
41* password
42* tenant name or tenant ID
43* a valid Keystone identity URL
44
45For users that have the OpenStack dashboard installed, there's a shortcut. If
46you visit the `project/access_and_security` path in Horizon and click on the
47"Download OpenStack RC File" button at the top right hand corner, you will
48download a bash file that exports all of your access details to environment
49variables. To execute the file, run `source admin-openrc.sh` and you will be
50prompted for your password.
51
52### Authentication
53
54Once you have access to your credentials, you can begin plugging them into
55gophercloud. The next step is authentication, and this is handled by a base
56"Provider" struct. To get one, you can either pass in your credentials
57explicitly, or tell gophercloud to use environment variables:
58
59```go
60// Option 1: Pass in the values yourself
61opts := gophercloud.AuthOptions{
62 IdentityEndpoint: "https://my-openstack.com:5000/v2.0",
63 Username: "{username}",
64 Password: "{password}",
65 TenantID: "{tenant_id}",
66}
67
68// Option 2: Use a utility function to retrieve all your environment variables
69import "github.com/rackspace/gophercloud/openstack/utils"
70opts, err := utils.AuthOptions()
71```
72
73Once you have the `opts` variable, you can pass it in and get back a
74`ProviderClient` struct:
75
76```go
77import "github.com/rackspace/gophercloud/openstack"
78
79provider, err := openstack.AuthenticatedClient(opts)
80```
81
82The `ProviderClient` is the top-level client that all of your OpenStack services
83derive from. The provider contains all of the authentication details that allow
84your Go code to access the API - such as the base URL and token ID.
85
86### Next steps
87
88Cool! You've handled authentication and got your `ProviderClient`. You're now
89ready to use an OpenStack service.
90
91* [Getting started with Compute](http://gophercloud.io/docs/compute)
92* [Getting started with Object Storage](http://gophercloud.io/docs/object-storage)
93* [Getting started with Networking](http://gophercloud.io/docs/networking)
94* [Getting started with Block Storage](http://gophercloud.io/docs/block-storage)
95* [Getting started with Identity](http://gophercloud.io/docs/identity)
96
97## Contributing
98
99Engaging the community and lowering barriers for contributors is something we
100care a lot about. For this reason, we've taken the time to write a [contributing
101guide](./CONTRIBUTING.md) for folks interested in getting involved in the project.
102If you're not sure what you can do to get involved, feel free to submit an issue
103or ping us an e-mail! You don't need to be a Go expert - all members of the
104community are welcome.
105
106## Help and feedback
107
108If you're struggling with something or have spotted a potential bug, feel free
109to submit an issue to our [bug tracker](/issues) or e-mail us directly at
110sdk-support@rackspace.com.