blob: 926250907cf8cd5b634951d091e365d3f32a10f3 [file] [log] [blame]
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -07001package main
2
3import (
4 "fmt"
5 "flag"
Max Lincoln75e06ec2013-12-13 00:00:12 -03006 "github.com/maxlinc/gophercloud"
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -07007)
8
9var quiet = flag.Bool("quiet", false, "Quiet operation for acceptance tests. $? non-zero if problem.")
Samuel A. Falvo IIe4a3e422013-09-13 12:36:37 -070010var region = flag.String("r", "", "Datacenter region. Leave blank for provider-default region.")
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -070011
12func main() {
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -070013 flag.Parse()
14
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070015 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 II286e4de2013-07-12 11:33:31 -070019 if err != nil {
20 panic(err)
21 }
Samuel A. Falvo II286e4de2013-07-12 11:33:31 -070022
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070023 // 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 II286e4de2013-07-12 11:33:31 -070046}