blob: 0f6bc378df27dd6ff8b6a2d6ff2a2ee3647bd21a [file] [log] [blame]
Samuel A. Falvo IIe21808f2013-08-14 14:48:09 -07001package main
2
3import (
4 "fmt"
5 "flag"
Max Lincoln75e06ec2013-12-13 00:00:12 -03006 "github.com/maxlinc/gophercloud"
Samuel A. Falvo IIe21808f2013-08-14 14:48:09 -07007)
8
9var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.")
10
11func main() {
12 flag.Parse()
13 withIdentity(false, func(acc gophercloud.AccessProvider) {
Jon Perritt499dce12013-10-29 15:41:14 -050014 withServerApi(acc, func(api gophercloud.CloudServersProvider) {
Samuel A. Falvo IIe21808f2013-08-14 14:48:09 -070015 log("Creating server")
Jon Perritt499dce12013-10-29 15:41:14 -050016 id, err := createServer(api, "", "", "", "")
Samuel A. Falvo IIe21808f2013-08-14 14:48:09 -070017 if err != nil {
18 panic(err)
19 }
Jon Perritt499dce12013-10-29 15:41:14 -050020 waitForServerState(api, id, "ACTIVE")
21 defer api.DeleteServerById(id)
22
23 tryAllAddresses(id, api)
24 tryAddressesByNetwork("public", id, api)
25 tryAddressesByNetwork("private", id, api)
Samuel A. Falvo IIe21808f2013-08-14 14:48:09 -070026
27 log("Done")
28 })
29 })
30}
31
Jon Perritt499dce12013-10-29 15:41:14 -050032func tryAllAddresses(id string, api gophercloud.CloudServersProvider) {
33 log("Getting list of all addresses...")
34 addresses, err := api.ListAddresses(id)
35 if (err != nil) && (err != gophercloud.WarnUnauthoritative) {
36 panic(err)
37 }
38 if err == gophercloud.WarnUnauthoritative {
39 log("Uh oh -- got a response back, but it's not authoritative for some reason.")
40 }
41 for _, addr := range addresses.Public {
42 log("Address:", addr.Addr, " IPv", addr.Version)
43 }
44}
45
46func tryAddressesByNetwork(networkLabel string, id string, api gophercloud.CloudServersProvider) {
47 log("Getting list of addresses on", networkLabel, "network...")
48 network, err := api.ListAddressesByNetwork(id, networkLabel)
49 if (err != nil) && (err != gophercloud.WarnUnauthoritative) {
50 panic(err)
51 }
52 if err == gophercloud.WarnUnauthoritative {
53 log("Uh oh -- got a response back, but it's not authoritative for some reason.")
54 }
55 for _, addr := range network[networkLabel]{
56 log("Address:", addr.Addr, " IPv", addr.Version)
57 }
58}
59
Samuel A. Falvo IIe21808f2013-08-14 14:48:09 -070060func log(s... interface{}) {
61 if !*quiet {
62 fmt.Println(s...)
63 }
64}