Add update server capability.
This requires an updated version of Perigee, for it lacked a Put()
method. Make sure you "go get -u github.com/racker/perigee" prior to
testing, or you'll get method not defined errors.
diff --git a/acceptance/12-update-server.go b/acceptance/12-update-server.go
new file mode 100644
index 0000000..203b37d
--- /dev/null
+++ b/acceptance/12-update-server.go
@@ -0,0 +1,44 @@
+package main
+
+import (
+ "fmt"
+ "flag"
+ "github.com/rackspace/gophercloud"
+)
+
+var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.")
+
+func main() {
+ flag.Parse()
+ withIdentity(false, func(acc gophercloud.AccessProvider) {
+ withServerApi(acc, func(servers gophercloud.CloudServersProvider) {
+ log("Creating server")
+ id, err := createServer(servers, "", "", "", "")
+ if err != nil {
+ panic(err)
+ }
+ waitForServerState(servers, id, "ACTIVE")
+ defer servers.DeleteServerById(id)
+
+ log("Updating name of server")
+ newName := randomString("ACPTTEST", 32)
+ newDetails, err := servers.UpdateServer(id, gophercloud.NewServerSettings{
+ Name: newName,
+ })
+ if err != nil {
+ panic(err)
+ }
+ if newDetails.Name != newName {
+ panic("Name change didn't appear to take")
+ }
+
+ log("Done")
+ })
+ })
+}
+
+func log(s string) {
+ if !*quiet {
+ fmt.Println(s)
+ }
+}
diff --git a/interfaces.go b/interfaces.go
index 2bb8ac5..8e02fc3 100644
--- a/interfaces.go
+++ b/interfaces.go
@@ -38,6 +38,7 @@
RebootServer(id string, hard bool) error
RescueServer(id string) (string, error)
UnrescueServer(id string) error
+ UpdateServer(id string, newValues NewServerSettings) (*Server, error)
// Images
diff --git a/servers.go b/servers.go
index 6b97f05..16d82c5 100644
--- a/servers.go
+++ b/servers.go
@@ -247,6 +247,26 @@
})
}
+// See the CloudServersProvider interface for details
+func (gsp *genericServersProvider) UpdateServer(id string, changes NewServerSettings) (*Server, error) {
+ var svr *Server
+ err := gsp.context.WithReauth(gsp.access, func() error {
+ url := fmt.Sprintf("%s/servers/%s", gsp.endpoint, id)
+ return perigee.Put(url, perigee.Options{
+ ReqBody: &struct{
+ Server NewServerSettings `json:"server"`
+ }{changes},
+ MoreHeaders: map[string]string{
+ "X-Auth-Token": gsp.access.AuthToken(),
+ },
+ Results: &struct{
+ Server **Server `json:"server"`
+ }{&svr},
+ })
+ })
+ return svr, err
+}
+
// RaxBandwidth provides measurement of server bandwidth consumed over a given audit interval.
type RaxBandwidth struct {
AuditPeriodEnd string `json:"audit_period_end"`
@@ -372,6 +392,14 @@
OsExtStsVmState string `json:"OS-EXT-STS:vm_state"`
}
+// NewServerSettings structures record those fields of the Server structure to change
+// when updating a server (see UpdateServer method).
+type NewServerSettings struct {
+ Name string `json:"name,omitempty"`
+ AccessIPv4 string `json:"accessIPv4,omitempty"`
+ AccessIPv6 string `json:"accessIPv6,omitempty"`
+}
+
// NewServer structures are used for both requests and responses.
// The fields discussed below are relevent for server-creation purposes.
//