blob: bae220ff8e4dc596cbdaa6352afc55653b2b9fa0 [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"
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -07007)
8
9var id = flag.String("i", "", "Server ID to get info on. Defaults to first server in your account if unspecified.")
10var rgn = flag.String("r", "DFW", "Datacenter region")
11var quiet = flag.Bool("quiet", false, "Run quietly, for acceptance testing. $? non-zero if issue.")
12
13func main() {
Samuel A. Falvo II704a7502013-07-10 15:23:43 -070014 provider, username, password := getCredentials()
Samuel A. Falvo II02f5e832013-07-10 13:52:27 -070015 flag.Parse()
16
17 auth, err := gophercloud.Authenticate(
18 provider,
19 gophercloud.AuthOptions{
20 Username: username,
21 Password: password,
22 },
23 )
24 if err != nil {
25 panic(err)
26 }
27
28 servers, err := gophercloud.ServersApi(auth, gophercloud.ApiCriteria{
29 Name: "cloudServersOpenStack",
30 Region: *rgn,
31 VersionId: "2",
32 UrlChoice: gophercloud.PublicURL,
33 })
34 if err != nil {
35 panic(err)
36 }
37
38 serverId := ""
39 if *id == "" {
40 ss, err := servers.ListServers()
41 if err != nil {
42 panic(err)
43 }
44 // We could just cheat and dump the server details from ss[0].
45 // But, that tests ListServers(), and not ServerById(). So, we
46 // elect not to cheat.
47 serverId = ss[0].Id
48 } else {
49 serverId = *id
50 }
51
52 s, err := servers.ServerById(serverId)
53 if err != nil {
54 panic(err)
55 }
56
57 configs := []string {
58 "Access IPv4: %s\n",
59 "Access IPv6: %s\n",
60 " Created: %s\n",
61 " Flavor: %s\n",
62 " Host ID: %s\n",
63 " ID: %s\n",
64 " Image: %s\n",
65 " Name: %s\n",
66 " Progress: %s\n",
67 " Status: %s\n",
68 " Tenant ID: %s\n",
69 " Updated: %s\n",
70 " User ID: %s\n",
71 }
72
73 values := []string {
74 s.AccessIPv4,
75 s.AccessIPv6,
76 s.Created,
77 s.Flavor.Id,
78 s.HostId,
79 s.Id,
80 s.Image.Id,
81 s.Name,
82 fmt.Sprintf("%d", s.Progress),
83 s.Status,
84 s.TenantId,
85 s.Updated,
86 s.UserId,
87 }
88
89 if !*quiet {
90 fmt.Println("Server info:")
91 for i, _ := range configs {
92 fmt.Printf(configs[i], values[i])
93 }
94 }
95}