blob: 880fbe8b8ad1819c9291b4e299d80e5a541af67b [file] [log] [blame]
Samuel A. Falvo II2dd7d2f2014-06-30 16:18:08 -07001// +build acceptance,old
2
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -07003package main
4
5import (
6 "flag"
7 "fmt"
8 "github.com/rackspace/gophercloud"
9)
10
11var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.")
12var serverId = flag.String("i", "", "ID of server whose admin password is to be changed.")
13var newPass = flag.String("p", "", "New password for the server.")
14
15func main() {
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -070016 flag.Parse()
17
Samuel A. Falvo IIcb9eca62013-07-31 14:33:33 -070018 withIdentity(false, func(acc gophercloud.AccessProvider) {
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070019 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 II5c305e12013-07-25 19:19:43 -070029
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070030 // If no password is provided, create one dynamically.
31 if *newPass == "" {
32 *newPass = randomString("", 16)
33 }
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -070034
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070035 // 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 II80699602013-07-25 23:35:57 -070040 if err != nil {
41 panic(err)
42 }
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070043
44 if !*quiet {
45 fmt.Println("Password change request submitted.")
Samuel A. Falvo II80699602013-07-25 23:35:57 -070046 }
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070047 })
48 })
Samuel A. Falvo II5c305e12013-07-25 19:19:43 -070049}