Mark Peek | 5a9151f | 2013-08-17 18:59:59 -0700 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "flag" |
| 5 | "fmt" |
| 6 | "github.com/rackspace/gophercloud" |
| 7 | ) |
| 8 | |
| 9 | var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance testing. $? non-zero on error though.") |
Samuel A. Falvo II | e4a3e42 | 2013-09-13 12:36:37 -0700 | [diff] [blame] | 10 | var rgn = flag.String("r", "", "Datacenter region to interrogate. Leave blank for provider-default region.") |
Mark Peek | 5a9151f | 2013-08-17 18:59:59 -0700 | [diff] [blame] | 11 | |
| 12 | func main() { |
| 13 | flag.Parse() |
| 14 | |
| 15 | withIdentity(false, func(auth gophercloud.AccessProvider) { |
| 16 | withServerApi(auth, func(servers gophercloud.CloudServersProvider) { |
| 17 | name := randomString("ACPTTEST", 16) |
| 18 | kp := gophercloud.NewKeyPair{ |
| 19 | Name: name, |
| 20 | } |
| 21 | keypair, err := servers.CreateKeyPair(kp) |
| 22 | if err != nil { |
| 23 | panic(err) |
| 24 | } |
| 25 | if !*quiet { |
| 26 | fmt.Printf("%s,%s,%s\n", keypair.Name, keypair.FingerPrint, keypair.PublicKey) |
| 27 | } |
| 28 | |
| 29 | keypair, err = servers.ShowKeyPair(name) |
| 30 | if err != nil { |
| 31 | panic(err) |
| 32 | } |
| 33 | if !*quiet { |
| 34 | fmt.Printf("%s,%s,%s\n", keypair.Name, keypair.FingerPrint, keypair.PublicKey) |
| 35 | } |
| 36 | |
| 37 | err = servers.DeleteKeyPair(name) |
| 38 | if err != nil { |
| 39 | panic(err) |
| 40 | } |
| 41 | }) |
| 42 | }) |
| 43 | } |