blob: 758c706672002fdbc52b8bbdf69f0c96ce5bb194 [file] [log] [blame]
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -07001package main
2
3import (
4 "fmt"
5 "github.com/rackspace/gophercloud"
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -07006 "flag"
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -07007)
8
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -07009var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.")
10
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -070011func main() {
Samuel A. Falvo II704a7502013-07-10 15:23:43 -070012 provider, username, password := getCredentials()
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -070013 flag.Parse()
14
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -070015 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 II1dd740a2013-07-08 15:48:40 -070026 api, err := gophercloud.ServersApi(acc, gophercloud.ApiCriteria{
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -070027 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 IIa0a55842013-07-24 13:14:17 -070036 tryFullDetails(api)
37 tryLinksOnly(api)
38}
39
40func 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
66func tryFullDetails(api gophercloud.CloudServersProvider) {
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -070067 servers, err := api.ListServers()
68 if err != nil {
69 panic(err)
70 }
71
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -070072 if !*quiet {
Samuel A. Falvo IIa0a55842013-07-24 13:14:17 -070073 fmt.Println("Id,Name,AccessIPv4,Status,Progress")
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -070074 for _, s := range servers {
Samuel A. Falvo IIa0a55842013-07-24 13:14:17 -070075 fmt.Printf("%s,\"%s\",%s,%s,%d\n", s.Id, s.Name, s.AccessIPv4, s.Status, s.Progress)
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -070076 }
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -070077 }
78}
Samuel A. Falvo IIa0a55842013-07-24 13:14:17 -070079