Do the same for Rackspace RebuildOpts.
diff --git a/rackspace/compute/v2/servers/requests.go b/rackspace/compute/v2/servers/requests.go
index 8e55a6a..b83a893 100644
--- a/rackspace/compute/v2/servers/requests.go
+++ b/rackspace/compute/v2/servers/requests.go
@@ -83,3 +83,56 @@
return result
}
+
+// RebuildOpts represents all of the configuration options used in a server rebuild operation that
+// are supported by Rackspace.
+type RebuildOpts struct {
+ // Required. The ID of the image you want your server to be provisioned on
+ ImageID string
+
+ // Name to set the server to
+ Name string
+
+ // Required. The server's admin password
+ AdminPass string
+
+ // AccessIPv4 [optional] provides a new IPv4 address for the instance.
+ AccessIPv4 string
+
+ // AccessIPv6 [optional] provides a new IPv6 address for the instance.
+ AccessIPv6 string
+
+ // Metadata [optional] contains key-value pairs (up to 255 bytes each) to attach to the server.
+ Metadata map[string]string
+
+ // Personality [optional] includes the path and contents of a file to inject into the server at launch.
+ // The maximum size of the file is 255 bytes (decoded).
+ Personality []byte
+
+ // Rackspace-specific stuff begins here.
+
+ // DiskConfig [optional] controls how the created server's disk is partitioned. See the "diskconfig"
+ // extension in OpenStack compute v2.
+ DiskConfig diskconfig.DiskConfig
+}
+
+// ToServerRebuildMap constructs a request body using all of the OpenStack extensions that are
+// active on Rackspace.
+func (opts RebuildOpts) ToServerRebuildMap() (map[string]interface{}, error) {
+ base := os.RebuildOpts{
+ ImageID: opts.ImageID,
+ Name: opts.Name,
+ AdminPass: opts.AdminPass,
+ AccessIPv4: opts.AccessIPv4,
+ AccessIPv6: opts.AccessIPv6,
+ Metadata: opts.Metadata,
+ Personality: opts.Personality,
+ }
+
+ drive := diskconfig.RebuildOptsExt{
+ RebuildOptsBuilder: base,
+ DiskConfig: opts.DiskConfig,
+ }
+
+ return drive.ToServerRebuildMap()
+}
diff --git a/rackspace/compute/v2/servers/requests_test.go b/rackspace/compute/v2/servers/requests_test.go
index 999718b..ac7058f 100644
--- a/rackspace/compute/v2/servers/requests_test.go
+++ b/rackspace/compute/v2/servers/requests_test.go
@@ -29,3 +29,27 @@
`
th.CheckJSONEquals(t, expected, opts.ToServerCreateMap())
}
+
+func TestRebuildOpts(t *testing.T) {
+ opts := RebuildOpts{
+ Name: "rebuiltserver",
+ AdminPass: "swordfish",
+ ImageID: "asdfasdfasdf",
+ DiskConfig: diskconfig.Auto,
+ }
+
+ actual, err := opts.ToServerRebuildMap()
+ th.AssertNoErr(t, err)
+
+ expected := `
+ {
+ "rebuild": {
+ "name": "rebuiltserver",
+ "imageRef": "asdfasdfasdf",
+ "adminPass": "swordfish",
+ "OS-DCF:diskConfig": "AUTO"
+ }
+ }
+ `
+ th.CheckJSONEquals(t, expected, actual)
+}