Samuel A. Falvo II | 2dd7d2f | 2014-06-30 16:18:08 -0700 | [diff] [blame] | 1 | // +build acceptance,old |
| 2 | |
Mark Peek | d2188c4 | 2013-08-27 08:16:28 -0700 | [diff] [blame] | 3 | package main |
| 4 | |
| 5 | import ( |
| 6 | "flag" |
| 7 | "fmt" |
Max Lincoln | 28b4956 | 2013-12-13 13:23:44 -0300 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud" |
Mark Peek | d2188c4 | 2013-08-27 08:16:28 -0700 | [diff] [blame] | 9 | ) |
| 10 | |
| 11 | var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance testing. $? non-zero on error though.") |
Samuel A. Falvo II | e4a3e42 | 2013-09-13 12:36:37 -0700 | [diff] [blame] | 12 | var rgn = flag.String("r", "", "Datacenter region to interrogate. Leave blank for provider-default region.") |
Mark Peek | d2188c4 | 2013-08-27 08:16:28 -0700 | [diff] [blame] | 13 | |
| 14 | func main() { |
| 15 | flag.Parse() |
| 16 | |
| 17 | withIdentity(false, func(auth gophercloud.AccessProvider) { |
| 18 | withServerApi(auth, func(servers gophercloud.CloudServersProvider) { |
| 19 | log("Creating server") |
| 20 | serverId, err := createServer(servers, "", "", "", "") |
| 21 | if err != nil { |
| 22 | panic(err) |
| 23 | } |
| 24 | waitForServerState(servers, serverId, "ACTIVE") |
| 25 | |
| 26 | log("Creating image") |
| 27 | name := randomString("ACPTTEST", 16) |
| 28 | createImage := gophercloud.CreateImage{ |
| 29 | Name: name, |
| 30 | } |
| 31 | imageId, err := servers.CreateImage(serverId, createImage) |
| 32 | if err != nil { |
| 33 | panic(err) |
| 34 | } |
| 35 | waitForImageState(servers, imageId, "ACTIVE") |
| 36 | |
| 37 | log("Deleting server") |
| 38 | servers.DeleteServerById(serverId) |
| 39 | |
| 40 | log("Deleting image") |
| 41 | servers.DeleteImageById(imageId) |
| 42 | |
| 43 | log("Done") |
| 44 | }) |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | func log(s string) { |
Jon Perritt | 2be65d1 | 2013-12-13 17:21:09 -0600 | [diff] [blame] | 49 | if !*quiet { |
| 50 | fmt.Println(s) |
| 51 | } |
Mark Peek | d2188c4 | 2013-08-27 08:16:28 -0700 | [diff] [blame] | 52 | } |