Samuel A. Falvo II | 2dd7d2f | 2014-06-30 16:18:08 -0700 | [diff] [blame] | 1 | // +build acceptance,old |
| 2 | |
Samuel A. Falvo II | d361710 | 2014-01-20 18:27:42 -0800 | [diff] [blame] | 3 | package main |
| 4 | |
| 5 | import ( |
| 6 | "flag" |
| 7 | "fmt" |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | ) |
| 10 | |
| 11 | var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.") |
| 12 | |
| 13 | func main() { |
| 14 | flag.Parse() |
| 15 | withIdentity(false, func(acc gophercloud.AccessProvider) { |
| 16 | withServerApi(acc, func(api gophercloud.CloudServersProvider) { |
| 17 | log("Creating server") |
| 18 | id, err := createServer(api, "", "", "", "") |
| 19 | if err != nil { |
| 20 | panic(err) |
| 21 | } |
| 22 | waitForServerState(api, id, "ACTIVE") |
| 23 | defer api.DeleteServerById(id) |
| 24 | |
| 25 | tryAllAddresses(id, api) |
| 26 | |
| 27 | log("Done") |
| 28 | }) |
| 29 | }) |
| 30 | } |
| 31 | |
| 32 | func tryAllAddresses(id string, api gophercloud.CloudServersProvider) { |
| 33 | log("Getting the server instance") |
| 34 | s, err := api.ServerById(id) |
| 35 | if err != nil { |
| 36 | panic(err) |
| 37 | } |
| 38 | |
| 39 | log("Getting the complete set of pools") |
| 40 | ps, err := s.AllAddressPools() |
| 41 | if err != nil { |
| 42 | panic(err) |
| 43 | } |
| 44 | |
| 45 | log("Listing IPs for each pool") |
| 46 | for k, v := range ps { |
| 47 | log(fmt.Sprintf(" Pool %s", k)) |
| 48 | for _, a := range v { |
| 49 | log(fmt.Sprintf(" IP: %s, Version: %d", a.Addr, a.Version)) |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func log(s ...interface{}) { |
| 55 | if !*quiet { |
| 56 | fmt.Println(s...) |
| 57 | } |
| 58 | } |