blob: 8d05e8e319d324a3e77873f8c12e3e38b26a3e62 [file] [log] [blame]
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -07001package main
2
3import (
4 "fmt"
5 "flag"
6 "github.com/rackspace/gophercloud"
7)
8
9var quiet = flag.Bool("quiet", false, "Quiet operation for acceptance tests. $? non-zero if problem.")
10var region = flag.String("r", "DFW", "Datacenter region")
11
12func main() {
13 provider, username, password := getCredentials()
14 flag.Parse()
15
16 auth, err := gophercloud.Authenticate(provider, gophercloud.AuthOptions{
17 Username: username,
18 Password: password,
19 })
20 if err != nil {
21 panic(err)
22 }
23
24 servers, err := gophercloud.ServersApi(auth, gophercloud.ApiCriteria{
25 Name: "cloudServersOpenStack",
26 Region: *region,
27 VersionId: "2",
28 UrlChoice: gophercloud.PublicURL,
29 })
30 if err != nil {
31 panic(err)
32 }
33
34 ss, err := servers.ListServers()
35 if err != nil {
36 panic(err)
37 }
38
39 n := 0
40 for _, s := range ss {
41 if len(s.Name) < 10 {
42 continue
43 }
44 if s.Name[0:10] == "ACPTTEST--" {
45 err := servers.DeleteServerById(s.Id)
46 if err != nil {
47 panic(err)
48 }
49 n++
50 }
51 }
52
53 if !*quiet {
54 fmt.Printf("%d servers removed.\n", n)
55 }
56}