Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 4 | "flag" |
Jon Perritt | 2be65d1 | 2013-12-13 17:21:09 -0600 | [diff] [blame^] | 5 | "fmt" |
Max Lincoln | 28b4956 | 2013-12-13 13:23:44 -0300 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud" |
Samuel A. Falvo II | 15da6ab | 2013-07-30 14:02:11 -0700 | [diff] [blame] | 7 | ) |
| 8 | |
| 9 | var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.") |
| 10 | |
| 11 | func main() { |
| 12 | flag.Parse() |
| 13 | withIdentity(false, func(acc gophercloud.AccessProvider) { |
| 14 | withServerApi(acc, func(servers gophercloud.CloudServersProvider) { |
| 15 | log("Creating server") |
| 16 | id, err := createServer(servers, "", "", "", "") |
| 17 | if err != nil { |
| 18 | panic(err) |
| 19 | } |
| 20 | waitForServerState(servers, id, "ACTIVE") |
| 21 | defer servers.DeleteServerById(id) |
| 22 | |
| 23 | log("Rescuing server") |
| 24 | adminPass, err := servers.RescueServer(id) |
| 25 | if err != nil { |
| 26 | panic(err) |
| 27 | } |
| 28 | log(" Admin password = " + adminPass) |
| 29 | if len(adminPass) < 1 { |
| 30 | panic("Empty admin password") |
| 31 | } |
| 32 | waitForServerState(servers, id, "RESCUE") |
| 33 | |
| 34 | log("Unrescuing server") |
| 35 | err = servers.UnrescueServer(id) |
| 36 | if err != nil { |
| 37 | panic(err) |
| 38 | } |
| 39 | waitForServerState(servers, id, "ACTIVE") |
| 40 | |
| 41 | log("Done") |
| 42 | }) |
| 43 | }) |
| 44 | } |
| 45 | |
| 46 | func log(s string) { |
| 47 | if !*quiet { |
| 48 | fmt.Println(s) |
| 49 | } |
| 50 | } |