![]() Catch up with all the latest stuff from gophercloud 4b7db606 - only try to reauth once d13755e6 - BlockStorage v3: Rename VolumeType PublicAccess to IsPublic 614da04d - Add UPDATE support in V3 volume types (#656) be3fd784 - Flavor Extra Specs Create c2cafb46 - Flavor Extra Specs: List / Get 7b1b8775 - Compute v2: Flavor Access Add cf81d92c - Add DELETE support in V3 volume types a879b375 - Fix incorrect variable name 2997913a - Add pagination support in snapshots a5c71868 - Support pagination in volume resources 1db0312e - TrivialFix incorrect variable name 69194d93 - Add basic CRUD acceptance testcases in snapshot V3 22c7abce - Add CREATE support in V3 volume types aed60e9f - Add basic CRUD acceptance in volume V3 7cbf4661 - BlockStorage v3: volumetype get/list acc test bcab0f79 - Update README with Thank Yous f85e7c0f - Docs: Updating Contributing and Style Guides be1b616c - Fix a small syntax error of TestShareTypeExtraSpecs test 3f38a1ee - Add List/Get support for volume type in volume V3 48a40399 - Support for setting availability_zone_hints to a router 747776a7 - Fix the undefined function error of TestPortsbindingCRUD test a7ec61ea - Fix the undefined function error of TestNetworksProviderCRUD test 25e18920 - Compute v2: Add the extended status information API b63d2fd3 - availability_zone_hints for network(s) 157d7511 - Add support for ipv6_address_mode and ipv6_ra_mode in subnets ed468967 - DBv1: configurations acceptance test 578e2aab - Configuration group time parsing error 669959f8 - Compute v2: attachinterfaces acceptance test 8113f0cb - Add Nova interface-detach support d6484abc - Add Nova interface-attach support 7883fd95 - fix reauth deadlock by not calling Token() during reauth 4d0f8253 - Add support to get interface of a server 7dc13e0d - AccTests: BlockStorage v2 ForceDelete 1e86e54d - Refactor blockstorage actionURL e30da231 - Feature/support force delete e193578c - add UseTokenLock method in ProviderClient to allow safe concurrent access e6a5f874 - ObjectStorage v1: Rename ExtractLastMarker to extractLastMarker c47bb004 - BlockStorage v2/v3: Reorder snapshot/volume ListOpts and update godoc 2c05d0e4 - Add 'tenant' support in volume&snapshot API 639d71fd - Networking v2: Port Security Extension 755794a7 - ObjectStorage v1: Subdir and Marker detection a043441f - fixed bug with endless loop when using delimiter on folded directory a4799293 - OpenStack: support OS_PROJECT_* variables |
||
---|---|---|
.. | ||
openstack | ||
pagination | ||
.gitignore | ||
.travis.yml | ||
.zuul.yaml | ||
auth_options.go | ||
BUILD | ||
CHANGELOG.md | ||
doc.go | ||
endpoint_search.go | ||
errors.go | ||
FAQ.md | ||
LICENSE | ||
MIGRATING.md | ||
params.go | ||
provider_client.go | ||
README.md | ||
results.go | ||
service_client.go | ||
STYLEGUIDE.md | ||
util.go |
Gophercloud: an OpenStack SDK for Go
Gophercloud is an OpenStack Go SDK.
Useful links
How to install
Before installing, you need to ensure that your GOPATH environment variable is pointing to an appropriate directory where you want to install Gophercloud:
mkdir $HOME/go
export GOPATH=$HOME/go
To protect yourself against changes in your dependencies, we highly recommend choosing a dependency management solution for your projects, such as godep. Once this is set up, you can install Gophercloud as a dependency like so:
go get github.com/gophercloud/gophercloud
# Edit your code to import relevant packages from "github.com/gophercloud/gophercloud"
godep save ./...
This will install all the source files you need into a Godeps/_workspace
directory, which is
referenceable from your own source files when you use the godep go
command.
Getting started
Credentials
Because you'll be hitting an API, you will need to retrieve your OpenStack credentials and either store them as environment variables or in your local Go files. The first method is recommended because it decouples credential information from source code, allowing you to push the latter to your version control system without any security risk.
You will need to retrieve the following:
- username
- password
- a valid Keystone identity URL
For users that have the OpenStack dashboard installed, there's a shortcut. If
you visit the project/access_and_security
path in Horizon and click on the
"Download OpenStack RC File" button at the top right hand corner, you will
download a bash file that exports all of your access details to environment
variables. To execute the file, run source admin-openrc.sh
and you will be
prompted for your password.
Authentication
Once you have access to your credentials, you can begin plugging them into Gophercloud. The next step is authentication, and this is handled by a base "Provider" struct. To get one, you can either pass in your credentials explicitly, or tell Gophercloud to use environment variables:
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/utils"
)
// Option 1: Pass in the values yourself
opts := gophercloud.AuthOptions{
IdentityEndpoint: "https://openstack.example.com:5000/v2.0",
Username: "{username}",
Password: "{password}",
}
// Option 2: Use a utility function to retrieve all your environment variables
opts, err := openstack.AuthOptionsFromEnv()
Once you have the opts
variable, you can pass it in and get back a
ProviderClient
struct:
provider, err := openstack.AuthenticatedClient(opts)
The ProviderClient
is the top-level client that all of your OpenStack services
derive from. The provider contains all of the authentication details that allow
your Go code to access the API - such as the base URL and token ID.
Provision a server
Once we have a base Provider, we inject it as a dependency into each OpenStack service. In order to work with the Compute API, we need a Compute service client; which can be created like so:
client, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
})
We then use this client
for any Compute API operation we want. In our case,
we want to provision a new server - so we invoke the Create
method and pass
in the flavor ID (hardware specification) and image ID (operating system) we're
interested in:
import "github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
server, err := servers.Create(client, servers.CreateOpts{
Name: "My new server!",
FlavorRef: "flavor_id",
ImageRef: "image_id",
}).Extract()
The above code sample creates a new server with the parameters, and embodies the
new resource in the server
variable (a
servers.Server
struct).
Advanced Usage
Have a look at the FAQ for some tips on customizing the way Gophercloud works.
Backwards-Compatibility Guarantees
None. Vendor it and write tests covering the parts you use.
Contributing
See the contributing guide.
Help and feedback
If you're struggling with something or have spotted a potential bug, feel free to submit an issue to our bug tracker.
Thank You
We'd like to extend special thanks and appreciation to the following:
OpenLab
OpenLab is providing a full CI environment to test each PR and merge for a variety of OpenStack releases.
VEXXHOST
VEXXHOST is providing their services to assist with the development and testing of Gophercloud.