blob: 77bf82f73f8131de6b77b24f696d20ec34cfb524 [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 II02f5e832013-07-10 13:52:27 -070012 flag.Parse()
13
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070014 withIdentity(false, func(acc gophercloud.AccessProvider) {
Samuel A. Falvo II41856d62013-07-29 15:48:22 -070015 withServerApi(acc, func(api gophercloud.CloudServersProvider) {
16 tryFullDetails(api)
17 tryLinksOnly(api)
18 })
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -070019 })
Samuel A. Falvo IIa0a55842013-07-24 13:14:17 -070020}
21
22func 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
48func tryFullDetails(api gophercloud.CloudServersProvider) {
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -070049 servers, err := api.ListServers()
50 if err != nil {
51 panic(err)
52 }
53
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -070054 if !*quiet {
Samuel A. Falvo IIa0a55842013-07-24 13:14:17 -070055 fmt.Println("Id,Name,AccessIPv4,Status,Progress")
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -070056 for _, s := range servers {
Samuel A. Falvo IIa0a55842013-07-24 13:14:17 -070057 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 -070058 }
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -070059 }
60}
Samuel A. Falvo IIa0a55842013-07-24 13:14:17 -070061