blob: 3e38ba4f3538d6cca8496700cddd3afbbbf92f0c [file] [log] [blame]
Samuel A. Falvo II2dd7d2f2014-06-30 16:18:08 -07001// +build acceptance,old
2
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -07003package main
4
5import (
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -07006 "flag"
Jon Perritt2be65d12013-12-13 17:21:09 -06007 "fmt"
Max Lincoln28b49562013-12-13 13:23:44 -03008 "github.com/rackspace/gophercloud"
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -07009)
10
11var quiet = flag.Bool("quiet", false, "Quiet operation for acceptance tests. $? non-zero if problem.")
Samuel A. Falvo IIe4a3e422013-09-13 12:36:37 -070012var region = flag.String("r", "", "Datacenter region. Leave blank for provider-default region.")
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -070013
14func main() {
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -070015 flag.Parse()
16
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070017 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 II286e4de2013-07-12 11:33:31 -070021 if err != nil {
22 panic(err)
23 }
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -070024
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070025 // 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 Perritt2be65d12013-12-13 17:21:09 -060047 })
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -070048}