Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "github.com/rackspace/gophercloud" |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 6 | "flag" |
Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 7 | ) |
| 8 | |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 9 | var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.") |
| 10 | |
Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 11 | func main() { |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 12 | flag.Parse() |
| 13 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 14 | withIdentity(false, func(acc gophercloud.AccessProvider) { |
Samuel A. Falvo II | 41856d6 | 2013-07-29 15:48:22 -0700 | [diff] [blame] | 15 | withServerApi(acc, func(api gophercloud.CloudServersProvider) { |
| 16 | tryFullDetails(api) |
| 17 | tryLinksOnly(api) |
| 18 | }) |
Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 19 | }) |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | func tryLinksOnly(api gophercloud.CloudServersProvider) { |
| 23 | servers, err := api.ListServersLinksOnly() |
| 24 | if err != nil { |
| 25 | panic(err) |
| 26 | } |
| 27 | |
| 28 | if !*quiet { |
| 29 | fmt.Println("Id,Name") |
| 30 | for _, s := range servers { |
| 31 | if s.AccessIPv4 != "" { |
| 32 | panic("IPv4 not expected") |
| 33 | } |
| 34 | |
| 35 | if s.Status != "" { |
| 36 | panic("Status not expected") |
| 37 | } |
| 38 | |
| 39 | if s.Progress != 0 { |
| 40 | panic("Progress not expected") |
| 41 | } |
| 42 | |
| 43 | fmt.Printf("%s,\"%s\"\n", s.Id, s.Name) |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func tryFullDetails(api gophercloud.CloudServersProvider) { |
Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 49 | servers, err := api.ListServers() |
| 50 | if err != nil { |
| 51 | panic(err) |
| 52 | } |
| 53 | |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 54 | if !*quiet { |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame] | 55 | fmt.Println("Id,Name,AccessIPv4,Status,Progress") |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 56 | for _, s := range servers { |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame] | 57 | fmt.Printf("%s,\"%s\",%s,%s,%d\n", s.Id, s.Name, s.AccessIPv4, s.Status, s.Progress) |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 58 | } |
Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame] | 61 | |