Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "flag" |
| 5 | "fmt" |
Max Lincoln | 75e06ec | 2013-12-13 00:00:12 -0300 | [diff] [blame] | 6 | "github.com/maxlinc/gophercloud" |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 7 | ) |
| 8 | |
| 9 | var region, serverName, imageRef, flavorRef *string |
| 10 | var adminPass = flag.String("a", "", "Administrator password (auto-assigned if none)") |
Samuel A. Falvo II | 4b0ba75 | 2013-07-11 17:42:26 -0700 | [diff] [blame] | 11 | var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance tests. $? non-zero if error.") |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 12 | |
Samuel A. Falvo II | 4b0ba75 | 2013-07-11 17:42:26 -0700 | [diff] [blame] | 13 | func configure() { |
Samuel A. Falvo II | e4a3e42 | 2013-09-13 12:36:37 -0700 | [diff] [blame] | 14 | region = flag.String("r", "", "Region in which to create the server. Leave blank for provider-default region.") |
Samuel A. Falvo II | e3b2d7a | 2013-07-12 11:08:02 -0700 | [diff] [blame] | 15 | serverName = flag.String("n", randomString("ACPTTEST--", 16), "Server name (what you see in the control panel)") |
Samuel A. Falvo II | 4b0ba75 | 2013-07-11 17:42:26 -0700 | [diff] [blame] | 16 | imageRef = flag.String("i", "", "ID of image to deploy onto the server") |
| 17 | flavorRef = flag.String("f", "", "Flavor of server to deploy image upon") |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 18 | |
| 19 | flag.Parse() |
Samuel A. Falvo II | 4b0ba75 | 2013-07-11 17:42:26 -0700 | [diff] [blame] | 20 | } |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 21 | |
Samuel A. Falvo II | 4b0ba75 | 2013-07-11 17:42:26 -0700 | [diff] [blame] | 22 | func main() { |
| 23 | configure() |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 24 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 25 | withIdentity(false, func(auth gophercloud.AccessProvider) { |
| 26 | withServerApi(auth, func(servers gophercloud.CloudServersProvider) { |
| 27 | _, err := createServer(servers, *imageRef, *flavorRef, *serverName, *adminPass) |
| 28 | if err != nil { |
| 29 | panic(err) |
| 30 | } |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 31 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 32 | allServers, err := servers.ListServers() |
| 33 | if err != nil { |
| 34 | panic(err) |
| 35 | } |
| 36 | |
| 37 | if !*quiet { |
| 38 | fmt.Printf("ID,Name,Status,Progress\n") |
| 39 | for _, i := range allServers { |
| 40 | fmt.Printf("%s,\"%s\",%s,%d\n", i.Id, i.Name, i.Status, i.Progress) |
| 41 | } |
| 42 | } |
| 43 | }) |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 44 | }) |
Samuel A. Falvo II | e91ff6d | 2013-07-11 15:46:10 -0700 | [diff] [blame] | 45 | } |