blob: f85b98006024ad0d98f3c6b8395892ab4c5657d5 [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[NOTE]
Samuel A. Falvo IIb4abb052013-06-28 11:25:09 -070031.*Please note that these instructions are here temporarily until we make this repository public.*
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070032-----------------------------------------------------------------------------------------------------
stackedsax563bf052013-06-25 13:21:00 -0700331. Navigate to the scripts/create-environment.sh file in the GitHub user interface
342. Click on 'Raw'
353. Copy and paste into a file locally
364. Supposing that file is named `/tmp/gcsetup.sh`, you can invoke it as follows:
37
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070038 source /tmp/gcsetup.sh
39-----------------------------------------------------------------------------------------------------
stackedsax563bf052013-06-25 13:21:00 -070040
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070041[WARNING]
Samuel A. Falvo IIb4abb052013-06-28 11:25:09 -070042.*Please note that this set of installation instructions will work as soon the repoistory is public.* We'll remove these admonitions at that time as well*
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070043-----------------------------------------------------------------------------------------------------
Samuel A. Falvo II07552812013-06-27 15:02:13 -070044You 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 -070045
Samuel A. Falvo II07552812013-06-27 15:02:13 -070046 source <(curl "https://raw.github.com/rackspace/Gophercloud/master/scripts/create-env.sh")
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070047-----------------------------------------------------------------------------------------------------
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070048
Samuel A. Falvo II07552812013-06-27 15:02:13 -070049This 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`.
50
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070051==== Make Sure Gophercloud Works For You
Samuel A. Falvo II07552812013-06-27 15:02:13 -070052You should follow these steps to make sure your local installation works as expected.
53
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070054[cols="<,<"]
55|==================
56|`export SDK_USERNAME=jack_frost`|Use your cloud provider's API user name.
57|`export SDK_PROVIDER=santa-telecom`|Use your provider's unique Gophercloud identifier. This is how Gophercloud will know which API endpoints to use.
58|`SDK_PASSWORD=c0ldnbr33zy $GOPHERCLOUD/scripts/test-all.sh`|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.
59|===================
Samuel A. Falvo II07552812013-06-27 15:02:13 -070060
61If 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:
62
631. Your provider diverges from established Openstack standards.
642. Gophercloud incorrectly implements the relevant Openstack standards.
653. Mistake in setting up the `SDK_*` environment variables above.
66
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070067If 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 -070068
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070069==== Using Gophercloud
70Simply 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 -070071
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070072==== Contributing Features or Bug-Fixes
Samuel A. Falvo II07552812013-06-27 15:02:13 -070073After 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 -070074
Samuel A. Falvo II07552812013-06-27 15:02:13 -070075After 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.
76
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070077Features 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 -070078
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070079.........................
80script-environment-setup
81server-creation
82issue-43-memory-leak-fix
83.........................
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -070084
85Some examples of not-so-good branch names include:
86
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070087.........................
88cloud-server-api-server-creation-endpoint-support <1>
89tk <2>
90anything/with/slashes <3>
91.........................
92<1> This branch name is lengthy without delivering much value.
93<2> This branch name is too short to be useful to anyone other than the submitter.
94<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 -070095
96For 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:
97
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -070098............................................
99cd $GOPHERCLOUD
100git checkout working
101git checkout -b issue-42-fix-memory-leak
102# edit edit edit ...
103# commits happen here ...
104git push -u origin issue-42-fix-memory-leak
105............................................
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -0700106
107At 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:
108
1091. What is the problem?
1102. Why is it a problem?
1113. What is your solution?
1124. How does your solution actually work?
113
114Here's a made-up example:
115
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -0700116......................................................................
117Fix memory leak detailed in issue #42.
118
119The Rackspace provider interface tended to leak memory every fifth
120Saturday of February. Over the course of several decades, we find
121we run out of memory. Killing and restarting the process periodically
122restores service, but is a burden on the ops team. This PR fixes this
123bug permanently.
124
125The barProvider structure found in
126provider/barisp.go defines a FooSet as a slice, as seen on line 314.
127Per services/auth/keystone2.go line 628, Keystone authentication
128only ever uses the first three elements of this FooSet. Line 42 shows
129where FooSet is initialized to an empty slice, but on line 512, we see
130a function that appends to this slice unconditionally.
131
132I'm not sure where the logic exists to determine where this function is
133called; so, I've adjusted the provider/barisp.go file to truncate this
134FooSet to only three items, maximum on behalf of the caller. This seems
135to solve the problem in my test cases. See included tests.
136......................................................................
Samuel A. Falvo IIff3f09d2013-06-20 17:54:26 -0700137
138Obviously, please use common sense! In situations where these questions do not apply, please don't make up filler information.
139
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -0700140NOTE: 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 `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 -0700141
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -0700142APPROVED: 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 -0700143
Samuel A. Falvo II7b830c92013-06-28 11:20:14 -0700144==== Master Branch vs. Working Branch
145
146Many 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 -0700147
148To 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`.