blob: d60557b031a2e07984606d2eccf3559e8f2ee7f1 [file] [log] [blame]
Samuel A. Falvo II2dd7d2f2014-06-30 16:18:08 -07001// +build acceptance,old
2
Samuel A. Falvo IId3617102014-01-20 18:27:42 -08003package main
4
5import (
6 "flag"
7 "fmt"
8 "github.com/rackspace/gophercloud"
9)
10
11var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.")
12
13func 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
32func 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
54func log(s ...interface{}) {
55 if !*quiet {
56 fmt.Println(s...)
57 }
58}