blob: 4d2e4c4b87e1899028ed8f063ee5a9f6a2fe260d [file] [log] [blame]
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -07001== Gophercloud -- V0.0.0
2The 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 II7b830c92013-06-28 11:20:14 -07006=== Getting Started
7==== Install the Go Programming Language
Samuel A. Falvo II07552812013-06-27 15:02:13 -07008Gophercloud provides an Openstack-compatible SDK binding to the Go community.
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -07009As 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 -070010
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070011==== Familiarize Yourself with Go
12To 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 -070013
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070014==== Installing Gophercloud in a Workspace
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070015
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070016IMPORTANT: *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 -070017
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070018===== Installing Into an Existing Project
Samuel A. Falvo II07552812013-06-27 15:02:13 -070019Assuming 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`:
20
21 go get github.com/rackspace/gophercloud
22
23The 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.,
24
25 export GOPHERCLOUD=$GOPATH/src/github.com/rackspace/gophercloud
26
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070027===== Creating a New Gophercloud Project
Samuel A. Falvo II07552812013-06-27 15:02:13 -070028If 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 -070029
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070030-----------------------------------------------------------------------------------------------------
Samuel A. Falvo II07552812013-06-27 15:02:13 -070031You 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 -070032
Jamie Hannaford3fd3e9c2013-08-15 11:46:22 -050033 source <(curl "https://raw.github.com/rackspace/Gophercloud/master/scripts/create-environment.sh")
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070034-----------------------------------------------------------------------------------------------------
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070035
Samuel A. Falvo II07552812013-06-27 15:02:13 -070036This 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`.
37
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070038==== Make Sure Gophercloud Works For You
Samuel A. Falvo II07552812013-06-27 15:02:13 -070039You should follow these steps to make sure your local installation works as expected.
40
Samuel A. Falvo II9566bf82013-06-28 11:28:23 -070041-----
Samuel A. Falvo II73e3e872013-06-28 11:40:02 -070042export SDK_USERNAME=jack_frost <1>
43export SDK_PROVIDER=santa-telecom <2>
Samuel A. Falvo II9566bf82013-06-28 11:28:23 -070044SDK_PASSWORD=c0ldnbr33zy $GOPHERCLOUD/scripts/test-all.sh <3>
45-----
46<1> Use your cloud provider's API user name.
47<2> Use your provider's unique Gophercloud identifier. This is how Gophercloud will know which API endpoints to use.
48<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 -070049
50If 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:
51
521. Your provider diverges from established Openstack standards.
532. Gophercloud incorrectly implements the relevant Openstack standards.
543. Mistake in setting up the `SDK_*` environment variables above.
55
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070056If 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 -070057
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070058==== Using Gophercloud
59Simply 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 -070060
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070061==== Contributing Features or Bug-Fixes
Samuel A. Falvo II07552812013-06-27 15:02:13 -070062After 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 -070063
Samuel A. Falvo II07552812013-06-27 15:02:13 -070064After 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.
65
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070066Features 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 -070067
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070068.........................
69script-environment-setup
70server-creation
71issue-43-memory-leak-fix
72.........................
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070073
74Some examples of not-so-good branch names include:
75
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070076.........................
77cloud-server-api-server-creation-endpoint-support <1>
78tk <2>
79anything/with/slashes <3>
80.........................
81<1> This branch name is lengthy without delivering much value.
82<2> This branch name is too short to be useful to anyone other than the submitter.
83<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 -070084
85For 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:
86
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070087............................................
88cd $GOPHERCLOUD
89git checkout working
90git checkout -b issue-42-fix-memory-leak
91# edit edit edit ...
92# commits happen here ...
93git push -u origin issue-42-fix-memory-leak
94............................................
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070095
96At 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:
97
981. What is the problem?
992. Why is it a problem?
1003. What is your solution?
1014. How does your solution actually work?
102
103Here's a made-up example:
104
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -0700105......................................................................
106Fix memory leak detailed in issue #42.
107
108The Rackspace provider interface tended to leak memory every fifth
109Saturday of February. Over the course of several decades, we find
110we run out of memory. Killing and restarting the process periodically
111restores service, but is a burden on the ops team. This PR fixes this
112bug permanently.
113
114The barProvider structure found in
115provider/barisp.go defines a FooSet as a slice, as seen on line 314.
116Per services/auth/keystone2.go line 628, Keystone authentication
117only ever uses the first three elements of this FooSet. Line 42 shows
118where FooSet is initialized to an empty slice, but on line 512, we see
119a function that appends to this slice unconditionally.
120
121I'm not sure where the logic exists to determine where this function is
122called; so, I've adjusted the provider/barisp.go file to truncate this
123FooSet to only three items, maximum on behalf of the caller. This seems
124to solve the problem in my test cases. See included tests.
125......................................................................
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -0700126
127Obviously, please use common sense! In situations where these questions do not apply, please don't make up filler information.
128
Samuel A. Falvo II56e961f2013-06-28 11:35:00 -0700129NOTE: 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 -0700130
Samuel A. Falvo IIfc2cdef2013-06-28 11:36:00 -0700131TIP: 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 -0700132
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -0700133==== Master Branch vs. Working Branch
134
135Many 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 -0700136
137To 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`.