Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "flag" |
Max Lincoln | 75e06ec | 2013-12-13 00:00:12 -0300 | [diff] [blame^] | 6 | "github.com/maxlinc/gophercloud" |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 7 | ) |
| 8 | |
| 9 | var quiet = flag.Bool("quiet", false, "Quiet operation for acceptance tests. $? non-zero if problem.") |
Samuel A. Falvo II | e4a3e42 | 2013-09-13 12:36:37 -0700 | [diff] [blame] | 10 | var region = flag.String("r", "", "Datacenter region. Leave blank for provider-default region.") |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 11 | |
| 12 | func main() { |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 13 | flag.Parse() |
| 14 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 15 | withIdentity(false, func(auth gophercloud.AccessProvider) { |
| 16 | withServerApi(auth, func(servers gophercloud.CloudServersProvider) { |
| 17 | // Grab a listing of all servers. |
| 18 | ss, err := servers.ListServers() |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 19 | if err != nil { |
| 20 | panic(err) |
| 21 | } |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 22 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 23 | // And for each one that starts with the ACPTTEST prefix, delete it. |
| 24 | // These are likely left-overs from previously running acceptance tests. |
| 25 | // Note that 04-create-servers.go is intended to leak servers by intention, |
| 26 | // so as to test this code. :) |
| 27 | n := 0 |
| 28 | for _, s := range ss { |
| 29 | if len(s.Name) < 8 { |
| 30 | continue |
| 31 | } |
| 32 | if s.Name[0:8] == "ACPTTEST" { |
| 33 | err := servers.DeleteServerById(s.Id) |
| 34 | if err != nil { |
| 35 | panic(err) |
| 36 | } |
| 37 | n++ |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | if !*quiet { |
| 42 | fmt.Printf("%d servers removed.\n", n) |
| 43 | } |
| 44 | }) |
| 45 | }) |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 46 | } |