blob: 6d826dbea7a0becfe7dc95d890279408472dd7b0 [file] [log] [blame]
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -07001package main
2
3import (
4 "fmt"
5 "flag"
6 "github.com/rackspace/gophercloud"
7 "os"
8)
9
10var id = flag.String("i", "", "Server ID to get info on. Defaults to first server in your account if unspecified.")
11var rgn = flag.String("r", "DFW", "Datacenter region")
12var quiet = flag.Bool("quiet", false, "Run quietly, for acceptance testing. $? non-zero if issue.")
13
14func main() {
15 provider := os.Getenv("SDK_PROVIDER")
16 username := os.Getenv("SDK_USERNAME")
17 password := os.Getenv("SDK_PASSWORD")
18
19 if (provider == "") || (username == "") || (password == "") {
20 fmt.Fprintf(os.Stderr, "One or more of the following environment variables aren't set:\n")
21 fmt.Fprintf(os.Stderr, " SDK_PROVIDER=\"%s\"\n", provider)
22 fmt.Fprintf(os.Stderr, " SDK_USERNAME=\"%s\"\n", username)
23 fmt.Fprintf(os.Stderr, " SDK_PASSWORD=\"%s\"\n", password)
24 os.Exit(1)
25 }
26
27 flag.Parse()
28
29 auth, err := gophercloud.Authenticate(
30 provider,
31 gophercloud.AuthOptions{
32 Username: username,
33 Password: password,
34 },
35 )
36 if err != nil {
37 panic(err)
38 }
39
40 servers, err := gophercloud.ServersApi(auth, gophercloud.ApiCriteria{
41 Name: "cloudServersOpenStack",
42 Region: *rgn,
43 VersionId: "2",
44 UrlChoice: gophercloud.PublicURL,
45 })
46 if err != nil {
47 panic(err)
48 }
49
50 serverId := ""
51 if *id == "" {
52 ss, err := servers.ListServers()
53 if err != nil {
54 panic(err)
55 }
56 // We could just cheat and dump the server details from ss[0].
57 // But, that tests ListServers(), and not ServerById(). So, we
58 // elect not to cheat.
59 serverId = ss[0].Id
60 } else {
61 serverId = *id
62 }
63
64 s, err := servers.ServerById(serverId)
65 if err != nil {
66 panic(err)
67 }
68
69 configs := []string {
70 "Access IPv4: %s\n",
71 "Access IPv6: %s\n",
72 " Created: %s\n",
73 " Flavor: %s\n",
74 " Host ID: %s\n",
75 " ID: %s\n",
76 " Image: %s\n",
77 " Name: %s\n",
78 " Progress: %s\n",
79 " Status: %s\n",
80 " Tenant ID: %s\n",
81 " Updated: %s\n",
82 " User ID: %s\n",
83 }
84
85 values := []string {
86 s.AccessIPv4,
87 s.AccessIPv6,
88 s.Created,
89 s.Flavor.Id,
90 s.HostId,
91 s.Id,
92 s.Image.Id,
93 s.Name,
94 fmt.Sprintf("%d", s.Progress),
95 s.Status,
96 s.TenantId,
97 s.Updated,
98 s.UserId,
99 }
100
101 if !*quiet {
102 fmt.Println("Server info:")
103 for i, _ := range configs {
104 fmt.Printf(configs[i], values[i])
105 }
106 }
107}