Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame^] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "flag" |
| 6 | "github.com/rackspace/gophercloud" |
| 7 | ) |
| 8 | |
| 9 | var quiet = flag.Bool("quiet", false, "Quiet operation for acceptance tests. $? non-zero if problem.") |
| 10 | var region = flag.String("r", "DFW", "Datacenter region") |
| 11 | |
| 12 | func 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 | } |