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 | |
| 36 | servers, err := api.ListServers() |
| 37 | if err != nil { |
| 38 | panic(err) |
| 39 | } |
| 40 | |
Samuel A. Falvo II | 02f5e83 | 2013-07-10 13:52:27 -0700 | [diff] [blame] | 41 | if !*quiet { |
| 42 | for _, s := range servers { |
| 43 | fmt.Printf("%s\n", s.Id) |
| 44 | } |
Samuel A. Falvo II | fca35b7 | 2013-07-02 18:30:28 -0700 | [diff] [blame] | 45 | } |
| 46 | } |