blob: b33a15ce9bb0b1748b411b27e183fe92e4473115 [file] [log] [blame]
Samuel A. Falvo IIfca35b72013-07-02 18:30:28 -07001package main
2
3import (
4 "fmt"
5 "github.com/rackspace/gophercloud"
6 "os"
7)
8
9func main() {
10 provider := os.Getenv("SDK_PROVIDER")
11 username := os.Getenv("SDK_USERNAME")
12 password := os.Getenv("SDK_PASSWORD")
13
14 if (provider == "") || (username == "") || (password == "") {
15 fmt.Fprintf(os.Stderr, "One or more of the following environment variables aren't set:\n")
16 fmt.Fprintf(os.Stderr, " SDK_PROVIDER=\"%s\"\n", provider)
17 fmt.Fprintf(os.Stderr, " SDK_USERNAME=\"%s\"\n", username)
18 fmt.Fprintf(os.Stderr, " SDK_PASSWORD=\"%s\"\n", password)
19 os.Exit(1)
20 }
21
22 acc, err := gophercloud.Authenticate(
23 provider,
24 gophercloud.AuthOptions{
25 Username: username,
26 Password: password,
27 },
28 )
29 if err != nil {
30 panic(err)
31 }
32
33 api, err := gophercloud.ComputeApi(acc, gophercloud.ApiCriteria{
34 Name: "cloudServersOpenStack",
35 Region: "DFW",
36 VersionId: "2",
37 UrlChoice: gophercloud.PublicURL,
38 })
39 if err != nil {
40 panic(err)
41 }
42
43 servers, err := api.ListServers()
44 if err != nil {
45 panic(err)
46 }
47
48 fmt.Println("Server ID")
49 fmt.Println("----------------------------------------")
50 for _, s := range servers {
51 fmt.Printf(" %s\n", s.Id)
52 }
53}