Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit b8ba1d1

Browse files
committed
Merge pull request #283 from jamiehannaford/upgrade-guide
Adding Upgrade guide
2 parents 5b23967 + 3586db1 commit b8ba1d1

File tree

2 files changed

+339
-10
lines changed

2 files changed

+339
-10
lines changed

UPGRADING.md

Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
# Upgrading to v1.0.0
2+
3+
With the arrival of this new major version increment, the unfortunate news is
4+
that breaking changes have been introduced to existing services. The API
5+
has been completely rewritten from the ground up to make the library more
6+
extensible, maintainable and easy-to-use.
7+
8+
Below we've compiled upgrade instructions for the various services that
9+
existed before. If you have a specific issue that is not addressed below,
10+
please [submit an issue](/issues/new) or
11+
[e-mail our support team](mailto:[email protected]).
12+
13+
* [Authentication](#authentication)
14+
* [Servers](#servers)
15+
* [List servers](#list-servers)
16+
* [Get server details](#get-server-details)
17+
* [Create server](#create-server)
18+
* [Resize server](#resize-server)
19+
* [Reboot server](#reboot-server)
20+
* [Update server](#update-server)
21+
* [Rebuild server](#rebuild-server)
22+
* [Change admin password](#change-admin-password)
23+
* [Delete server](#delete-server)
24+
* [Rescue server](#rescue-server)
25+
* [Images and flavors](#images-and-flavors)
26+
* [List images](#list-images)
27+
* [List flavors](#list-flavors)
28+
* [Create/delete image](#createdelete-image)
29+
* [Other](#other)
30+
* [List keypairs](#list-keypairs)
31+
* [Create/delete keypair](#createdelete-keypair)
32+
* [List IP addresses](#list-ip-addresses)
33+
34+
# Authentication
35+
36+
One of the major differences that this release introduces is the level of
37+
sub-packaging to differentiate between services and providers. You now have
38+
the option of authenticating with OpenStack and other providers (like Rackspace).
39+
40+
To authenticate with a vanilla OpenStack installation, you can either specify
41+
your credentials like this:
42+
43+
```go
44+
import (
45+
"github.com/rackspace/gophercloud"
46+
"github.com/rackspace/gophercloud/openstack"
47+
)
48+
49+
opts := gophercloud.AuthOptions{
50+
IdentityEndpoint: "https://my-openstack.com:5000/v2.0",
51+
Username: "{username}",
52+
Password: "{password}",
53+
TenantID: "{tenant_id}",
54+
}
55+
```
56+
57+
Or have them pulled in through environment variables, like this:
58+
59+
```go
60+
opts, err := openstack.AuthOptionsFromEnv()
61+
```
62+
63+
Once you have your `AuthOptions` struct, you pass it in to get back a `Provider`,
64+
like so:
65+
66+
```go
67+
provider, err := openstack.AuthenticatedClient(opts)
68+
```
69+
70+
This provider is the top-level structure that all services are created from.
71+
72+
# Servers
73+
74+
Before you can interact with the Compute API, you need to retrieve a
75+
`gophercloud.ServiceClient`. To do this:
76+
77+
```go
78+
// Define your region, etc.
79+
opts := gophercloud.EndpointOpts{Region: "RegionOne"}
80+
81+
client, err := openstack.NewComputeV2(provider, opts)
82+
```
83+
84+
## List servers
85+
86+
All operations that involve API collections (servers, flavors, images) now use
87+
the `pagination.Pager` interface. This interface represents paginated entities
88+
that can be iterated over.
89+
90+
Once you have a Pager, you can then pass a callback function into its `EachPage`
91+
method, and this will allow you to traverse over the collection and execute
92+
arbitrary functionality. So, an example with list servers:
93+
94+
```go
95+
import (
96+
"fmt"
97+
"github.com/rackspace/gophercloud/pagination"
98+
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
99+
)
100+
101+
// We have the option of filtering the server list. If we want the full
102+
// collection, leave it as an empty struct or nil
103+
opts := servers.ListOpts{Name: "server_1"}
104+
105+
// Retrieve a pager (i.e. a paginated collection)
106+
pager := servers.List(client, opts)
107+
108+
// Define an anonymous function to be executed on each page's iteration
109+
err := pager.EachPage(func(page pagination.Page) (bool, error) {
110+
serverList, err := servers.ExtractServers(page)
111+
112+
// `s' will be a servers.Server struct
113+
for _, s := range serverList {
114+
fmt.Printf("We have a server. ID=%s, Name=%s", s.ID, s.Name)
115+
}
116+
})
117+
```
118+
119+
## Get server details
120+
121+
```go
122+
import "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
123+
124+
// Get the HTTP result
125+
response := servers.Get(client, "server_id")
126+
127+
// Extract a Server struct from the response
128+
server, err := response.Extract()
129+
```
130+
131+
## Create server
132+
133+
```go
134+
import "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
135+
136+
// Define our options
137+
opts := servers.CreateOpts{
138+
Name: "new_server",
139+
FlavorRef: "flavorID",
140+
ImageRef: "imageID",
141+
}
142+
143+
// Get our response
144+
response := servers.Create(client, opts)
145+
146+
// Extract
147+
server, err := response.Extract()
148+
```
149+
150+
## Change admin password
151+
152+
```go
153+
import "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
154+
155+
result := servers.ChangeAdminPassword(client, "server_id", "newPassword_&123")
156+
```
157+
158+
## Resize server
159+
160+
```go
161+
import "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
162+
163+
result := servers.Resize(client, "server_id", "new_flavor_id")
164+
```
165+
166+
## Reboot server
167+
168+
```go
169+
import "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
170+
171+
// You have a choice of two reboot methods: servers.SoftReboot or servers.HardReboot
172+
result := servers.Reboot(client, "server_id", servers.SoftReboot)
173+
```
174+
175+
## Update server
176+
177+
```go
178+
import "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
179+
180+
opts := servers.UpdateOpts{Name: "new_name"}
181+
182+
server, err := servers.Update(client, "server_id", opts).Extract()
183+
```
184+
185+
## Rebuild server
186+
187+
```go
188+
import "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
189+
190+
// You have the option of specifying additional options
191+
opts := RebuildOpts{
192+
Name: "new_name",
193+
AdminPass: "admin_password",
194+
ImageID: "image_id",
195+
Metadata: map[string]string{"owner": "me"},
196+
}
197+
198+
result := servers.Rebuild(client, "server_id", opts)
199+
200+
// You can extract a servers.Server struct from the HTTP response
201+
server, err := result.Extract()
202+
```
203+
204+
## Delete server
205+
206+
```go
207+
import "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
208+
209+
response := servers.Delete(client, "server_id")
210+
```
211+
212+
## Rescue server
213+
214+
The server rescue extension for Compute is not currently supported.
215+
216+
# Images and flavors
217+
218+
## List images
219+
220+
As with listing servers (see above), you first retrieve a Pager, and then pass
221+
in a callback over each page:
222+
223+
```go
224+
import (
225+
"github.com/rackspace/gophercloud/pagination"
226+
"github.com/rackspace/gophercloud/openstack/compute/v2/images"
227+
)
228+
229+
// We have the option of filtering the image list. If we want the full
230+
// collection, leave it as an empty struct
231+
opts := images.ListOpts{ChangesSince: "2014-01-01T01:02:03Z", Name: "Ubuntu 12.04"}
232+
233+
// Retrieve a pager (i.e. a paginated collection)
234+
pager := images.List(client, opts)
235+
236+
// Define an anonymous function to be executed on each page's iteration
237+
err := pager.EachPage(func(page pagination.Page) (bool, error) {
238+
imageList, err := images.ExtractImages(page)
239+
240+
for _, i := range imageList {
241+
// "i" will be a images.Image
242+
}
243+
})
244+
```
245+
246+
## List flavors
247+
248+
```go
249+
import (
250+
"github.com/rackspace/gophercloud/pagination"
251+
"github.com/rackspace/gophercloud/openstack/compute/v2/flavors"
252+
)
253+
254+
// We have the option of filtering the flavor list. If we want the full
255+
// collection, leave it as an empty struct
256+
opts := flavors.ListOpts{ChangesSince: "2014-01-01T01:02:03Z", MinRAM: 4}
257+
258+
// Retrieve a pager (i.e. a paginated collection)
259+
pager := flavors.List(client, opts)
260+
261+
// Define an anonymous function to be executed on each page's iteration
262+
err := pager.EachPage(func(page pagination.Page) (bool, error) {
263+
flavorList, err := networks.ExtractFlavors(page)
264+
265+
for _, f := range flavorList {
266+
// "f" will be a flavors.Flavor
267+
}
268+
})
269+
```
270+
271+
## Create/delete image
272+
273+
Image management has been shifted to Glance, but unfortunately this service is
274+
not supported as of yet. You can, however, list Compute images like so:
275+
276+
```go
277+
import "github.com/rackspace/gophercloud/openstack/compute/v2/images"
278+
279+
// Retrieve a pager (i.e. a paginated collection)
280+
pager := images.List(client, opts)
281+
282+
// Define an anonymous function to be executed on each page's iteration
283+
err := pager.EachPage(func(page pagination.Page) (bool, error) {
284+
imageList, err := images.ExtractImages(page)
285+
286+
for _, i := range imageList {
287+
// "i" will be a images.Image
288+
}
289+
})
290+
```
291+
292+
# Other
293+
294+
## List keypairs
295+
296+
```go
297+
import "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
298+
299+
// Retrieve a pager (i.e. a paginated collection)
300+
pager := keypairs.List(client, opts)
301+
302+
// Define an anonymous function to be executed on each page's iteration
303+
err := pager.EachPage(func(page pagination.Page) (bool, error) {
304+
keyList, err := keypairs.ExtractKeyPairs(page)
305+
306+
for _, k := range keyList {
307+
// "k" will be a keypairs.KeyPair
308+
}
309+
})
310+
```
311+
312+
## Create/delete keypairs
313+
314+
To create a new keypair, you need to specify its name and, optionally, a
315+
pregenerated OpenSSH-formatted public key.
316+
317+
```go
318+
import "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
319+
320+
opts := keypairs.CreateOpts{
321+
Name: "new_key",
322+
PublicKey: "...",
323+
}
324+
325+
response := keypairs.Create(client, opts)
326+
327+
key, err := response.Extract()
328+
```
329+
330+
To delete an existing keypair:
331+
332+
```go
333+
response := keypairs.Delete(client, "keypair_id")
334+
```
335+
336+
## List IP addresses
337+
338+
This operation is not currently supported.

util_test.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,12 @@ package gophercloud
22

33
import (
44
"testing"
5-
"time"
65

76
th "github.com/rackspace/gophercloud/testhelper"
87
)
98

109
func TestWaitFor(t *testing.T) {
11-
err := WaitFor(0, func() (bool, error) {
12-
time.Sleep(1 * time.Second)
13-
return true, nil
14-
})
15-
if err == nil {
16-
t.Errorf("Expected error: 'Time out in WaitFor'")
17-
}
18-
19-
err = WaitFor(5, func() (bool, error) {
10+
err := WaitFor(5, func() (bool, error) {
2011
return true, nil
2112
})
2213
th.CheckNoErr(t, err)

0 commit comments

Comments
 (0)