Samuel A. Falvo II | 2dd7d2f | 2014-06-30 16:18:08 -0700 | [diff] [blame] | 1 | // +build acceptance,old |
| 2 | |
Samuel A. Falvo II | 5c305e1 | 2013-07-25 19:19:43 -0700 | [diff] [blame] | 3 | package main |
| 4 | |
| 5 | import ( |
| 6 | "flag" |
| 7 | "fmt" |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | ) |
| 10 | |
| 11 | var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.") |
| 12 | var serverId = flag.String("i", "", "ID of server whose admin password is to be changed.") |
| 13 | var newPass = flag.String("p", "", "New password for the server.") |
| 14 | |
| 15 | func main() { |
Samuel A. Falvo II | 5c305e1 | 2013-07-25 19:19:43 -0700 | [diff] [blame] | 16 | flag.Parse() |
| 17 | |
Samuel A. Falvo II | cb9eca6 | 2013-07-31 14:33:33 -0700 | [diff] [blame] | 18 | withIdentity(false, func(acc gophercloud.AccessProvider) { |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 19 | withServerApi(acc, func(api gophercloud.CloudServersProvider) { |
| 20 | // If user doesn't explicitly provide a server ID, create one dynamically. |
| 21 | if *serverId == "" { |
| 22 | var err error |
| 23 | *serverId, err = createServer(api, "", "", "", "") |
| 24 | if err != nil { |
| 25 | panic(err) |
| 26 | } |
| 27 | waitForServerState(api, *serverId, "ACTIVE") |
| 28 | } |
Samuel A. Falvo II | 5c305e1 | 2013-07-25 19:19:43 -0700 | [diff] [blame] | 29 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 30 | // If no password is provided, create one dynamically. |
| 31 | if *newPass == "" { |
| 32 | *newPass = randomString("", 16) |
| 33 | } |
Samuel A. Falvo II | 5c305e1 | 2013-07-25 19:19:43 -0700 | [diff] [blame] | 34 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 35 | // Submit the request for changing the admin password. |
| 36 | // Note that we don't verify this actually completes; |
| 37 | // doing so is beyond the scope of the SDK, and should be |
| 38 | // the responsibility of your specific OpenStack provider. |
| 39 | err := api.SetAdminPassword(*serverId, *newPass) |
Samuel A. Falvo II | 8069960 | 2013-07-25 23:35:57 -0700 | [diff] [blame] | 40 | if err != nil { |
| 41 | panic(err) |
| 42 | } |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 43 | |
| 44 | if !*quiet { |
| 45 | fmt.Println("Password change request submitted.") |
Samuel A. Falvo II | 8069960 | 2013-07-25 23:35:57 -0700 | [diff] [blame] | 46 | } |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 47 | }) |
| 48 | }) |
Samuel A. Falvo II | 5c305e1 | 2013-07-25 19:19:43 -0700 | [diff] [blame] | 49 | } |