Merge pull request #312 from jrperritt/add-password-compute
[rfr] Add AdminPass Field (Servers)
diff --git a/acceptance/openstack/compute/v2/servers_test.go b/acceptance/openstack/compute/v2/servers_test.go
index e223c18..be1fe7a 100644
--- a/acceptance/openstack/compute/v2/servers_test.go
+++ b/acceptance/openstack/compute/v2/servers_test.go
@@ -12,6 +12,7 @@
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
"github.com/rackspace/gophercloud/openstack/networking/v2/networks"
"github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
)
func TestListServers(t *testing.T) {
@@ -94,6 +95,8 @@
name := tools.RandomString("ACPTTEST", 16)
t.Logf("Attempting to create server: %s\n", name)
+ pwd := tools.MakeNewPassword("")
+
server, err := servers.Create(client, servers.CreateOpts{
Name: name,
FlavorRef: choices.FlavorID,
@@ -101,11 +104,14 @@
Networks: []servers.Network{
servers.Network{UUID: network.ID},
},
+ AdminPass: pwd,
}).Extract()
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
+ th.AssertEquals(t, pwd, server.AdminPass)
+
return server, err
}
diff --git a/acceptance/rackspace/compute/v2/servers_test.go b/acceptance/rackspace/compute/v2/servers_test.go
index 0eb00a8..81c8599 100644
--- a/acceptance/rackspace/compute/v2/servers_test.go
+++ b/acceptance/rackspace/compute/v2/servers_test.go
@@ -39,11 +39,14 @@
name := tools.RandomString("Gophercloud-", 8)
+ pwd := tools.MakeNewPassword("")
+
opts := &servers.CreateOpts{
Name: name,
ImageRef: options.imageID,
FlavorRef: options.flavorID,
DiskConfig: diskconfig.Manual,
+ AdminPass: pwd,
}
if keyName != "" {
@@ -59,6 +62,8 @@
th.AssertNoErr(t, err)
t.Logf("Server created successfully.")
+ th.CheckEquals(t, pwd, s.AdminPass)
+
return s
}
diff --git a/openstack/blockstorage/v1/snapshots/util_test.go b/openstack/blockstorage/v1/snapshots/util_test.go
deleted file mode 100644
index a4c4c82..0000000
--- a/openstack/blockstorage/v1/snapshots/util_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-package snapshots
-
-import (
- "fmt"
- "net/http"
- "testing"
- "time"
-
- th "github.com/rackspace/gophercloud/testhelper"
- "github.com/rackspace/gophercloud/testhelper/client"
-)
-
-func TestWaitForStatus(t *testing.T) {
- th.SetupHTTP()
- defer th.TeardownHTTP()
-
- th.Mux.HandleFunc("/snapshots/1234", func(w http.ResponseWriter, r *http.Request) {
- time.Sleep(2 * time.Second)
- w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
- fmt.Fprintf(w, `
- {
- "snapshot": {
- "display_name": "snapshot-001",
- "id": "1234",
- "status":"available"
- }
- }`)
- })
-
- err := WaitForStatus(client.ServiceClient(), "1234", "available", 0)
- if err == nil {
- t.Errorf("Expected error: 'Time Out in WaitFor'")
- }
-
- err = WaitForStatus(client.ServiceClient(), "1234", "available", 3)
- th.CheckNoErr(t, err)
-}
diff --git a/openstack/blockstorage/v1/volumes/util_test.go b/openstack/blockstorage/v1/volumes/util_test.go
deleted file mode 100644
index 24ef3b6..0000000
--- a/openstack/blockstorage/v1/volumes/util_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-package volumes
-
-import (
- "fmt"
- "net/http"
- "testing"
- "time"
-
- th "github.com/rackspace/gophercloud/testhelper"
- "github.com/rackspace/gophercloud/testhelper/client"
-)
-
-func TestWaitForStatus(t *testing.T) {
- th.SetupHTTP()
- defer th.TeardownHTTP()
-
- th.Mux.HandleFunc("/volumes/1234", func(w http.ResponseWriter, r *http.Request) {
- time.Sleep(3 * time.Second)
- w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
- fmt.Fprintf(w, `
- {
- "volume": {
- "display_name": "vol-001",
- "id": "1234",
- "status":"available"
- }
- }`)
- })
-
- err := WaitForStatus(client.ServiceClient(), "1234", "available", 0)
- if err == nil {
- t.Errorf("Expected error: 'Time Out in WaitFor'")
- }
-
- err = WaitForStatus(client.ServiceClient(), "1234", "available", 6)
- th.CheckNoErr(t, err)
-}
diff --git a/openstack/compute/v2/servers/requests.go b/openstack/compute/v2/servers/requests.go
index 95a4188..6381419 100644
--- a/openstack/compute/v2/servers/requests.go
+++ b/openstack/compute/v2/servers/requests.go
@@ -131,6 +131,10 @@
// ConfigDrive [optional] enables metadata injection through a configuration drive.
ConfigDrive bool
+
+ // AdminPass [optional] sets the root user password. If not set, a randomly-generated
+ // password will be created and returned in the response.
+ AdminPass string
}
// ToServerCreateMap assembles a request body based on the contents of a CreateOpts.
@@ -158,6 +162,9 @@
if opts.Metadata != nil {
server["metadata"] = opts.Metadata
}
+ if opts.AdminPass != "" {
+ server["adminPass"] = opts.AdminPass
+ }
if len(opts.SecurityGroups) > 0 {
securityGroups := make([]map[string]interface{}, len(opts.SecurityGroups))
diff --git a/rackspace/compute/v2/servers/requests.go b/rackspace/compute/v2/servers/requests.go
index 884b9cb..809183e 100644
--- a/rackspace/compute/v2/servers/requests.go
+++ b/rackspace/compute/v2/servers/requests.go
@@ -43,6 +43,10 @@
// ConfigDrive [optional] enables metadata injection through a configuration drive.
ConfigDrive bool
+ // AdminPass [optional] sets the root user password. If not set, a randomly-generated
+ // password will be created and returned in the response.
+ AdminPass string
+
// Rackspace-specific extensions begin here.
// KeyPair [optional] specifies the name of the SSH KeyPair to be injected into the newly launched
@@ -72,6 +76,7 @@
Metadata: opts.Metadata,
Personality: opts.Personality,
ConfigDrive: opts.ConfigDrive,
+ AdminPass: opts.AdminPass,
}
drive := diskconfig.CreateOptsExt{