blob: a9352b79e2a4d5578d1064a59fc8640673f39127 [file] [log] [blame]
Josh Toftf21fcac2013-12-16 16:19:47 -08001== Gophercloud -- V0.0.0 image:https://secure.travis-ci.org/rackspace/gophercloud.png?branch=master["build status",link="https://travis-ci.org/rackspace/gophercloud"]
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -07002The Go ecosystem seems to lack a comprehensive cloud services API (at the time this README was first written). As both Go and cloud services are trending in many businesses, and with Go used increasingly in infrastructure, it seems like an odd omission. To fill this gap, Gophercloud provides a Go binding to OpenStack cloud APIs. Many providers offer many APIs that are compatible with OpenStack; thus, building your infrastructure automation projects around Openstack is a natural way to avoid vendor lock-in.
Glen Campbella1f6f222013-06-20 11:10:46 -07003
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -07004WARNING: This library is still in the very early stages of development. Unless you want to contribute, it probably isn't what you want.
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -07005
Samuel A. Falvo II9e271cf2014-02-25 11:21:43 -08006The documentation below is obsolete, and will be updated with something shorter and more reasonable soon. In the meantime, the most up to date documentation can be found at link:http://godoc.org/github.com/rackspace/gophercloud[our Godoc.org documentation].
7
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -07008=== Getting Started
9==== Install the Go Programming Language
Samuel A. Falvo II07552812013-06-27 15:02:13 -070010Gophercloud provides an Openstack-compatible SDK binding to the Go community.
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070011As such, to either use it or contribute code, you'll need to have Go installed. Please http://golang.org/doc/install[refer to the Go installation instructions] for detailed steps to install the latest stable release of Go.
Samuel A. Falvo II07552812013-06-27 15:02:13 -070012
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070013==== Familiarize Yourself with Go
14To use or contribute to Gophercloud, you'll need some passing familiarity with Go, and how it uses certain concepts. If you've never worked with Go before, I _strongly_ encourage the interested reader to follow through the excellent online book titled http://golang.org/doc/effective_go.html[Effective Go].
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070015
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070016==== Installing Gophercloud in a Workspace
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070017
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070018IMPORTANT: *Please* do not just clone this repository expecting it to work like any other Python, Ruby, Java, or C/C++ repo. Go packages don't work that way! (You _did_ read Effective Go, right?)
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070019
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070020===== Installing Into an Existing Project
Samuel A. Falvo II07552812013-06-27 15:02:13 -070021Assuming you have a project underway already and its `$GOPATH` environment variable holds the correct path, you can include the Gophercloud package in the usual manner using `go get`:
22
23 go get github.com/rackspace/gophercloud
24
25The remainder of this document, and supporting materials, assumes a correct `$GOPATH` configuration, but further assumes that an environment variable `$GOPHERCLOUD` points to the Gophercloud installation directory as well. E.g.,
26
27 export GOPHERCLOUD=$GOPATH/src/github.com/rackspace/gophercloud
28
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070029===== Creating a New Gophercloud Project
Samuel A. Falvo II07552812013-06-27 15:02:13 -070030If you're just starting out with Go, a convenience script exists which lets you create a new Go workspace preconfigured with Gophercloud for you.
stackedsax563bf052013-06-25 13:21:00 -070031
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070032-----------------------------------------------------------------------------------------------------
Samuel A. Falvo II07552812013-06-27 15:02:13 -070033You can execute the following command to create a brand new Go workspace that is minimally configured for use with Gophercloud. This should work for any reasonable POSIX-compatible environment.
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070034
Jamie Hannaford3fd3e9c2013-08-15 11:46:22 -050035 source <(curl "https://raw.github.com/rackspace/Gophercloud/master/scripts/create-environment.sh")
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070036-----------------------------------------------------------------------------------------------------
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070037
Samuel A. Falvo II07552812013-06-27 15:02:13 -070038This script will not only install the software, but also create a shell script `env.sh` which, when executed, restores both `$GOPATH` and `$GOPHERCLOUD` to their correct values. The project will be installed in `$HOME/go/gophercloud`.
39
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070040==== Make Sure Gophercloud Works For You
Samuel A. Falvo II07552812013-06-27 15:02:13 -070041You should follow these steps to make sure your local installation works as expected.
42
Samuel A. Falvo II9566bf82013-06-28 11:28:23 -070043-----
Samuel A. Falvo II73e3e872013-06-28 11:40:02 -070044export SDK_USERNAME=jack_frost <1>
45export SDK_PROVIDER=santa-telecom <2>
Samuel A. Falvo II9566bf82013-06-28 11:28:23 -070046SDK_PASSWORD=c0ldnbr33zy $GOPHERCLOUD/scripts/test-all.sh <3>
47-----
48<1> Use your cloud provider's API user name.
49<2> Use your provider's unique Gophercloud identifier. This is how Gophercloud will know which API endpoints to use.
50<3> Do not export your password unless you don't care that it may reside in memory after the tests have all run. You might want to remove it from your shell's history file afterwards too.
Samuel A. Falvo II07552812013-06-27 15:02:13 -070051
52If everything goes well, you should only see output indicating the Go commands for each of the acceptance tests being run. Errors can be caused by several factors:
53
541. Your provider diverges from established Openstack standards.
552. Gophercloud incorrectly implements the relevant Openstack standards.
563. Mistake in setting up the `SDK_*` environment variables above.
57
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070058If a problem occurs, https://github.com/rackspace/gophercloud/issues[we'd love to hear about it in the issue tracker!]
Samuel A. Falvo II07552812013-06-27 15:02:13 -070059
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070060==== Using Gophercloud
61Simply list Gophercloud in the import section of relevant source listings, and you will be able to issue cloud requests through Gophercloud. For examples, either refer to the detailed SDK documentation, or https://github.com/rackspace/gophercloud/tree/master/acceptance[take a look at the acceptance-level tests in the `acceptance` subdirectory.]
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070062
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070063==== Contributing Features or Bug-Fixes
Samuel A. Falvo II07552812013-06-27 15:02:13 -070064After using Gophercloud for a while, you might find that it lacks some useful feature, or that existing behavior seems buggy. We welcome contributions from our users for both missing functionality as well as for bug fixes.
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070065
Samuel A. Falvo II07552812013-06-27 15:02:13 -070066After installing Gophercloud and after running its `env.sh` script (only needed once per shell session), you will find the source files in the `$GOPHERCLOUD` directory. Feel free to open your favorite editor inside that directory and poke around.
67
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070068Features and bug-fixes *must* appear on their own *feature branches*, even if you fork the Gophercloud repository. The name of the branch should be fairly descriptive, but try to avoid verbosity for verbosity's sake. Examples of good feature branch names include:
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070069
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070070.........................
71script-environment-setup
72server-creation
73issue-43-memory-leak-fix
74.........................
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070075
76Some examples of not-so-good branch names include:
77
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070078.........................
79cloud-server-api-server-creation-endpoint-support <1>
80tk <2>
81anything/with/slashes <3>
82.........................
83<1> This branch name is lengthy without delivering much value.
84<2> This branch name is too short to be useful to anyone other than the submitter.
85<3> This branch name exacerbates some Git usability issues, where some commands separate origins from branch names using slashes and others do not. Thus, using these kinds of branch names increases chances for easily preventable errors.
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070086
87For example, if you're looking to fix a memory leak that is documented in, just to pick a number, issue 42, you might follow a sequence of commands such as the following:
88
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070089............................................
90cd $GOPHERCLOUD
91git checkout working
92git checkout -b issue-42-fix-memory-leak
93# edit edit edit ...
94# commits happen here ...
95git push -u origin issue-42-fix-memory-leak
96............................................
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070097
98At this point, you may now switch to the GitHub user interface, and open a pull-request for the feature branch. This pull request should be descriptive. Basically, you want to give a small code walkthrough in the pull request summary. You should be able to answer, at a minimum, four basic questions, as appropriate for the nature of the patch:
99
1001. What is the problem?
1012. Why is it a problem?
1023. What is your solution?
1034. How does your solution actually work?
104
105Here's a made-up example:
106
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -0700107......................................................................
108Fix memory leak detailed in issue #42.
109
110The Rackspace provider interface tended to leak memory every fifth
111Saturday of February. Over the course of several decades, we find
112we run out of memory. Killing and restarting the process periodically
113restores service, but is a burden on the ops team. This PR fixes this
114bug permanently.
115
116The barProvider structure found in
117provider/barisp.go defines a FooSet as a slice, as seen on line 314.
118Per services/auth/keystone2.go line 628, Keystone authentication
119only ever uses the first three elements of this FooSet. Line 42 shows
120where FooSet is initialized to an empty slice, but on line 512, we see
121a function that appends to this slice unconditionally.
122
123I'm not sure where the logic exists to determine where this function is
124called; so, I've adjusted the provider/barisp.go file to truncate this
125FooSet to only three items, maximum on behalf of the caller. This seems
126to solve the problem in my test cases. See included tests.
127......................................................................
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -0700128
129Obviously, please use common sense! In situations where these questions do not apply, please don't make up filler information.
130
Samuel A. Falvo II56e961f2013-06-28 11:35:00 -0700131NOTE: All bug-fix PRs **MUST** reference at least one open issue. New feature PRs **SHOULD** reference at least one open issue. This convention helps track *why* certain code is written the way it is, and maintains historical context. Lengthy design discussions should be moved to the https://groups.google.com/forum/#!forum/gophercloud-dev[gophercloud-dev mailing list] if they occur; links to appropriate discussions should be made in the issue, again to maintain context.
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -0700132
Samuel A. Falvo IIfc2cdef2013-06-28 11:36:00 -0700133TIP: You may elide answers to the questions above if the answers already appear in the referenced PR(s), issues, or mailing list discussions. We care that the answers exist and may be easily found, not so much about *where* the answers may be found.
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -0700134
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -0700135==== Master Branch vs. Working Branch
136
137Many projects will happily let you create a feature branch off the master branch. However, Go environments place special significance on master branches of packages. Because the `go get` command *is not* intended to perform complete package management tasks, but merely serve as a convenience for establishing your Go work environment, it will always fetch from the master branch of any repository you specify. *Therefore, the master branch MUST always represent a customer-installable package.* Not only that, but interface changes **must** be backward compatible at all times.
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -0700138
139To facilitate development efforts, then, we maintain a *working* branch. New features and bug fixes merge into the `working` branch, where it remains staged for some future release date. Ideally, every push to github and every merge to `working` should kick off a batch of tests to validate the product still works. Assuming that `working` tests all pass, *and* your features or bug-fixes are both code- and feature-complete, then and only then should `working` be merged into `master`.