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 | 704a750 | 2013-07-10 15:23:43 -0700 | [diff] [blame] | 12 | provider, username, password := getCredentials() |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 13 | flag.Parse() |
| 14 | |
Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 15 | acc, err := gophercloud.Authenticate( |
| 16 | provider, |
| 17 | gophercloud.AuthOptions{ |
| 18 | Username: username, |
| 19 | Password: password, |
| 20 | }, |
| 21 | ) |
| 22 | if err != nil { |
| 23 | panic(err) |
| 24 | } |
| 25 | |
Samuel A. Falvo II | 1dd740a | 2013-07-08 15:48:40 -0700 | [diff] [blame] | 26 | api, err := gophercloud.ServersApi(acc, gophercloud.ApiCriteria{ |
Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 27 | Name: "cloudServersOpenStack", |
| 28 | Region: "DFW", |
| 29 | VersionId: "2", |
| 30 | UrlChoice: gophercloud.PublicURL, |
| 31 | }) |
| 32 | if err != nil { |
| 33 | panic(err) |
| 34 | } |
| 35 | |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame^] | 36 | tryFullDetails(api) |
| 37 | tryLinksOnly(api) |
| 38 | } |
| 39 | |
| 40 | func tryLinksOnly(api gophercloud.CloudServersProvider) { |
| 41 | servers, err := api.ListServersLinksOnly() |
| 42 | if err != nil { |
| 43 | panic(err) |
| 44 | } |
| 45 | |
| 46 | if !*quiet { |
| 47 | fmt.Println("Id,Name") |
| 48 | for _, s := range servers { |
| 49 | if s.AccessIPv4 != "" { |
| 50 | panic("IPv4 not expected") |
| 51 | } |
| 52 | |
| 53 | if s.Status != "" { |
| 54 | panic("Status not expected") |
| 55 | } |
| 56 | |
| 57 | if s.Progress != 0 { |
| 58 | panic("Progress not expected") |
| 59 | } |
| 60 | |
| 61 | fmt.Printf("%s,\"%s\"\n", s.Id, s.Name) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func tryFullDetails(api gophercloud.CloudServersProvider) { |
Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 67 | servers, err := api.ListServers() |
| 68 | if err != nil { |
| 69 | panic(err) |
| 70 | } |
| 71 | |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 72 | if !*quiet { |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame^] | 73 | fmt.Println("Id,Name,AccessIPv4,Status,Progress") |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 74 | for _, s := range servers { |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame^] | 75 | 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] | 76 | } |
Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 77 | } |
| 78 | } |
Samuel A. Falvo II | a0a5584 | 2013-07-24 13:14:17 -0700 | [diff] [blame^] | 79 | |