Samuel A. Falvo II | adbecf9 | 2013-07-30 13:13:59 -0700 | [diff] [blame^] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "flag" |
| 6 | "github.com/rackspace/gophercloud" |
| 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 | |
| 14 | withIdentity(false, func(acc gophercloud.AccessProvider) { |
| 15 | withServerApi(acc, func(servers gophercloud.CloudServersProvider) { |
| 16 | log("Creating server") |
| 17 | serverId, err := createServer(servers, "", "", "", "") |
| 18 | if err != nil { |
| 19 | panic(err) |
| 20 | } |
| 21 | waitForServerState(servers, serverId, "ACTIVE") |
| 22 | |
| 23 | log("Soft-rebooting server") |
| 24 | servers.RebootServer(serverId, false) |
| 25 | waitForServerState(servers, serverId, "REBOOT") |
| 26 | waitForServerState(servers, serverId, "ACTIVE") |
| 27 | |
| 28 | log("Hard-rebooting server") |
| 29 | servers.RebootServer(serverId, true) |
| 30 | waitForServerState(servers, serverId, "HARD_REBOOT") |
| 31 | waitForServerState(servers, serverId, "ACTIVE") |
| 32 | |
| 33 | log("Done") |
| 34 | servers.DeleteServerById(serverId) |
| 35 | }) |
| 36 | }) |
| 37 | } |
| 38 | |
| 39 | func log(s string) { |
| 40 | if !*quiet { |
| 41 | fmt.Println(s) |
| 42 | } |
| 43 | } |