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