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