Add server action: change admin password
diff --git a/openstack/compute/servers/client.go b/openstack/compute/servers/client.go
index 3d51dd8..3ce6965 100644
--- a/openstack/compute/servers/client.go
+++ b/openstack/compute/servers/client.go
@@ -42,6 +42,10 @@
return c.getDeleteUrl(id)
}
+func (c *Client) getActionUrl(id string) string {
+ return fmt.Sprintf("%s/servers/%s/action", c.endpoint, id)
+}
+
func (c *Client) getListHeaders() (map[string]string, error) {
t, err := c.getAuthToken()
if err != nil {
@@ -69,6 +73,10 @@
return c.getListHeaders()
}
+func (c *Client) getActionHeaders() (map[string]string, error) {
+ return c.getListHeaders()
+}
+
func (c *Client) getAuthToken() (string, error) {
var err error
diff --git a/openstack/compute/servers/requests.go b/openstack/compute/servers/requests.go
index 28abd1c..772699b 100644
--- a/openstack/compute/servers/requests.go
+++ b/openstack/compute/servers/requests.go
@@ -96,3 +96,21 @@
})
return sr, err
}
+
+// ChangeAdminPassword alters the administrator or root password for a specified
+// server.
+func ChangeAdminPassword(c *Client, id, newPassword string) error {
+ h, err := c.getActionHeaders()
+ if err != nil {
+ return err
+ }
+
+ err = perigee.Post(c.getActionUrl(id), perigee.Options{
+ ReqBody: struct{C map[string]string `json:"changePassword"`}{
+ map[string]string{"adminPass": newPassword},
+ },
+ MoreHeaders: h,
+ OkCodes: []int{202},
+ })
+ return err
+}
diff --git a/openstack/compute/servers/servers.go b/openstack/compute/servers/servers.go
index e3bdbe3..28d66d0 100644
--- a/openstack/compute/servers/servers.go
+++ b/openstack/compute/servers/servers.go
@@ -36,6 +36,9 @@
// Metadata includes a list of all user-specified key-value pairs attached to the server.
//
// Links includes HTTP references to the itself, useful for passing along to other APIs that might want a server reference.
+//
+// AdminPass will generally be empty (""). However, it will contain the administrative password chosen when provisioning a new server without a set AdminPass setting in the first place.
+// Note that this is the ONLY time this field will be valid.
type Server struct {
Id string
TenantId string `mapstructure:tenant_id`
@@ -53,6 +56,7 @@
Addresses map[string]interface{}
Metadata map[string]interface{}
Links []interface{}
+ AdminPass string `mapstructure:adminPass`
}
// GetServers interprets the result of a List() call, producing a slice of Server entities.