blob: 6f078ee867acfdd11a158387551d87fb7a5d46c8 [file] [log] [blame]
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -07001package main
2
3import (
4 "flag"
5 "fmt"
6 "github.com/rackspace/gophercloud"
7)
8
9var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.")
10var serverId = flag.String("i", "", "ID of server whose admin password is to be changed.")
11var newPass = flag.String("p", "", "New password for the server.")
12
13func main() {
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -070014 flag.Parse()
15
Samuel A. Falvo IIcb9eca62013-07-31 14:33:33 -070016 withIdentity(false, func(acc gophercloud.AccessProvider) {
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070017 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 II5c305e12013-07-25 19:19:43 -070027
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070028 // If no password is provided, create one dynamically.
29 if *newPass == "" {
30 *newPass = randomString("", 16)
31 }
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -070032
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070033 // 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 II80699602013-07-25 23:35:57 -070038 if err != nil {
39 panic(err)
40 }
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070041
42 if !*quiet {
43 fmt.Println("Password change request submitted.")
Samuel A. Falvo II80699602013-07-25 23:35:57 -070044 }
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070045 })
46 })
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -070047}