Samuel A. Falvo II | 2dd7d2f | 2014-06-30 16:18:08 -0700 | [diff] [blame] | 1 | // +build acceptance,old |
| 2 | |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 3 | package main |
| 4 | |
| 5 | import ( |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 6 | "flag" |
Jon Perritt | 2be65d1 | 2013-12-13 17:21:09 -0600 | [diff] [blame] | 7 | "fmt" |
Max Lincoln | 28b4956 | 2013-12-13 13:23:44 -0300 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud" |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 9 | ) |
| 10 | |
| 11 | 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] | 12 | 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] | 13 | |
| 14 | func main() { |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 15 | flag.Parse() |
| 16 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 17 | withIdentity(false, func(auth gophercloud.AccessProvider) { |
| 18 | withServerApi(auth, func(servers gophercloud.CloudServersProvider) { |
| 19 | // Grab a listing of all servers. |
| 20 | ss, err := servers.ListServers() |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 21 | if err != nil { |
| 22 | panic(err) |
| 23 | } |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 24 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 25 | // And for each one that starts with the ACPTTEST prefix, delete it. |
| 26 | // These are likely left-overs from previously running acceptance tests. |
| 27 | // Note that 04-create-servers.go is intended to leak servers by intention, |
| 28 | // so as to test this code. :) |
| 29 | n := 0 |
| 30 | for _, s := range ss { |
| 31 | if len(s.Name) < 8 { |
| 32 | continue |
| 33 | } |
| 34 | if s.Name[0:8] == "ACPTTEST" { |
| 35 | err := servers.DeleteServerById(s.Id) |
| 36 | if err != nil { |
| 37 | panic(err) |
| 38 | } |
| 39 | n++ |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | if !*quiet { |
| 44 | fmt.Printf("%d servers removed.\n", n) |
| 45 | } |
| 46 | }) |
Jon Perritt | 2be65d1 | 2013-12-13 17:21:09 -0600 | [diff] [blame] | 47 | }) |
Samuel A. Falvo II | 286e4de | 2013-07-12 11:33:31 -0700 | [diff] [blame] | 48 | } |