Change HTTP methods for OpenStack Compute
diff --git a/openstack/compute/v2/extensions/bootfromvolume/requests.go b/openstack/compute/v2/extensions/bootfromvolume/requests.go
index b64014f..c0ba368 100644
--- a/openstack/compute/v2/extensions/bootfromvolume/requests.go
+++ b/openstack/compute/v2/extensions/bootfromvolume/requests.go
@@ -99,10 +99,8 @@
return res
}
- _, res.Err = client.Request("POST", createURL(client), gophercloud.RequestOpts{
- JSONBody: reqBody,
- JSONResponse: &res.Body,
- OkCodes: []int{200, 202},
+ _, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200, 202},
})
return res
}
diff --git a/openstack/compute/v2/extensions/defsecrules/requests.go b/openstack/compute/v2/extensions/defsecrules/requests.go
index c29d46f..9f27ef1 100644
--- a/openstack/compute/v2/extensions/defsecrules/requests.go
+++ b/openstack/compute/v2/extensions/defsecrules/requests.go
@@ -73,10 +73,8 @@
return result
}
- _, result.Err = client.Request("POST", rootURL(client), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- JSONBody: &reqBody,
- OkCodes: []int{200},
+ _, result.Err = client.Post(rootURL(client), reqBody, &result.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return result
@@ -85,19 +83,13 @@
// Get will return details for a particular default rule.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var result GetResult
-
- _, result.Err = client.Request("GET", resourceURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- })
-
+ _, result.Err = client.Get(resourceURL(client, id), &result.Body, nil)
return result
}
// Delete will permanently delete a default rule from the project.
func Delete(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var result gophercloud.ErrResult
-
- _, result.Err = client.Request("DELETE", resourceURL(client, id), gophercloud.RequestOpts{})
-
+ _, result.Err = client.Delete(resourceURL(client, id), nil)
return result
}
diff --git a/openstack/compute/v2/extensions/floatingip/requests.go b/openstack/compute/v2/extensions/floatingip/requests.go
index 1fad93a..8abb72d 100644
--- a/openstack/compute/v2/extensions/floatingip/requests.go
+++ b/openstack/compute/v2/extensions/floatingip/requests.go
@@ -45,10 +45,8 @@
return res
}
- _, res.Err = client.Request("POST", createURL(client), gophercloud.RequestOpts{
- JSONBody: reqBody,
- JSONResponse: &res.Body,
- OkCodes: []int{200},
+ _, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return res
}
@@ -56,16 +54,14 @@
// Get returns data about a previously created FloatingIP.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
- _, res.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &res.Body,
- })
+ _, res.Err = client.Get(getURL(client, id), &res.Body, nil)
return res
}
// Delete requests the deletion of a previous allocated FloatingIP.
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
var res DeleteResult
- _, res.Err = client.Request("DELETE", deleteURL(client, id), gophercloud.RequestOpts{})
+ _, res.Err = client.Delete(deleteURL(client, id), nil)
return res
}
@@ -79,9 +75,7 @@
addFloatingIp["address"] = fip
reqBody := map[string]interface{}{"addFloatingIp": addFloatingIp}
- _, res.Err = client.Request("POST", associateURL(client, serverId), gophercloud.RequestOpts{
- JSONBody: reqBody,
- })
+ _, res.Err = client.Post(associateURL(client, serverId), reqBody, nil, nil)
return res
}
@@ -93,8 +87,6 @@
removeFloatingIp["address"] = fip
reqBody := map[string]interface{}{"removeFloatingIp": removeFloatingIp}
- _, res.Err = client.Request("POST", disassociateURL(client, serverId), gophercloud.RequestOpts{
- JSONBody: reqBody,
- })
+ _, res.Err = client.Post(disassociateURL(client, serverId), reqBody, nil, nil)
return res
}
diff --git a/openstack/compute/v2/extensions/keypairs/requests.go b/openstack/compute/v2/extensions/keypairs/requests.go
index 1ab7274..c56ee67 100644
--- a/openstack/compute/v2/extensions/keypairs/requests.go
+++ b/openstack/compute/v2/extensions/keypairs/requests.go
@@ -81,10 +81,8 @@
return res
}
- _, res.Err = client.Request("POST", createURL(client), gophercloud.RequestOpts{
- JSONBody: reqBody,
- JSONResponse: &res.Body,
- OkCodes: []int{200},
+ _, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return res
}
@@ -92,15 +90,13 @@
// Get returns public data about a previously uploaded KeyPair.
func Get(client *gophercloud.ServiceClient, name string) GetResult {
var res GetResult
- _, res.Err = client.Request("GET", getURL(client, name), gophercloud.RequestOpts{
- JSONResponse: &res.Body,
- })
+ _, res.Err = client.Get(getURL(client, name), &res.Body, nil)
return res
}
// Delete requests the deletion of a previous stored KeyPair from the server.
func Delete(client *gophercloud.ServiceClient, name string) DeleteResult {
var res DeleteResult
- _, res.Err = client.Request("DELETE", deleteURL(client, name), gophercloud.RequestOpts{})
+ _, res.Err = client.Delete(deleteURL(client, name), nil)
return res
}
diff --git a/openstack/compute/v2/extensions/secgroups/requests.go b/openstack/compute/v2/extensions/secgroups/requests.go
index f8d88d3..4cef480 100644
--- a/openstack/compute/v2/extensions/secgroups/requests.go
+++ b/openstack/compute/v2/extensions/secgroups/requests.go
@@ -78,10 +78,8 @@
return result
}
- _, result.Err = client.Request("POST", rootURL(client), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- JSONBody: &reqBody,
- OkCodes: []int{200},
+ _, result.Err = client.Post(rootURL(client), reqBody, &result.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return result
@@ -123,10 +121,8 @@
return result
}
- _, result.Err = client.Request("PUT", resourceURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- JSONBody: &reqBody,
- OkCodes: []int{200},
+ _, result.Err = client.Put(resourceURL(client, id), reqBody, &result.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return result
@@ -135,20 +131,14 @@
// Get will return details for a particular security group.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var result GetResult
-
- _, result.Err = client.Request("GET", resourceURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- })
-
+ _, result.Err = client.Get(resourceURL(client, id), &result.Body, nil)
return result
}
// Delete will permanently delete a security group from the project.
func Delete(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var result gophercloud.ErrResult
-
- _, result.Err = client.Request("DELETE", resourceURL(client, id), gophercloud.RequestOpts{})
-
+ _, result.Err = client.Delete(resourceURL(client, id), nil)
return result
}
@@ -231,10 +221,8 @@
return result
}
- _, result.Err = client.Request("POST", rootRuleURL(client), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- JSONBody: &reqBody,
- OkCodes: []int{200},
+ _, result.Err = client.Post(rootRuleURL(client), reqBody, &result.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return result
@@ -243,9 +231,7 @@
// DeleteRule will permanently delete a rule from a security group.
func DeleteRule(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var result gophercloud.ErrResult
-
- _, result.Err = client.Request("DELETE", resourceRuleURL(client, id), gophercloud.RequestOpts{})
-
+ _, result.Err = client.Delete(resourceRuleURL(client, id), nil)
return result
}
@@ -259,23 +245,13 @@
// rules of the group on the server.
func AddServerToGroup(client *gophercloud.ServiceClient, serverID, groupName string) gophercloud.ErrResult {
var result gophercloud.ErrResult
-
- _, result.Err = client.Request("POST", serverActionURL(client, serverID), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- JSONBody: actionMap("add", groupName),
- })
-
+ _, result.Err = client.Post(serverActionURL(client, serverID), actionMap("add", groupName), &result.Body, nil)
return result
}
// RemoveServerFromGroup will disassociate a server from a security group.
func RemoveServerFromGroup(client *gophercloud.ServiceClient, serverID, groupName string) gophercloud.ErrResult {
var result gophercloud.ErrResult
-
- _, result.Err = client.Request("POST", serverActionURL(client, serverID), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- JSONBody: actionMap("remove", groupName),
- })
-
+ _, result.Err = client.Post(serverActionURL(client, serverID), actionMap("remove", groupName), &result.Body, nil)
return result
}
diff --git a/openstack/compute/v2/extensions/startstop/requests.go b/openstack/compute/v2/extensions/startstop/requests.go
index 89bc248..0e090e6 100644
--- a/openstack/compute/v2/extensions/startstop/requests.go
+++ b/openstack/compute/v2/extensions/startstop/requests.go
@@ -9,25 +9,15 @@
// Start is the operation responsible for starting a Compute server.
func Start(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var res gophercloud.ErrResult
-
reqBody := map[string]interface{}{"os-start": nil}
-
- _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
- JSONBody: reqBody,
- })
-
+ _, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
return res
}
// Stop is the operation responsible for stopping a Compute server.
func Stop(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var res gophercloud.ErrResult
-
reqBody := map[string]interface{}{"os-stop": nil}
-
- _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
- JSONBody: reqBody,
- })
-
+ _, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
return res
}
diff --git a/openstack/compute/v2/extensions/tenantnetworks/requests.go b/openstack/compute/v2/extensions/tenantnetworks/requests.go
index 99cd1ae..3ec13d3 100644
--- a/openstack/compute/v2/extensions/tenantnetworks/requests.go
+++ b/openstack/compute/v2/extensions/tenantnetworks/requests.go
@@ -17,8 +17,6 @@
// Get returns data about a previously created Network.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
- _, res.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &res.Body,
- })
+ _, res.Err = client.Get(getURL(client, id), &res.Body, nil)
return res
}
diff --git a/openstack/compute/v2/extensions/volumeattach/requests.go b/openstack/compute/v2/extensions/volumeattach/requests.go
index 62de27c..b4ebede 100644
--- a/openstack/compute/v2/extensions/volumeattach/requests.go
+++ b/openstack/compute/v2/extensions/volumeattach/requests.go
@@ -54,10 +54,8 @@
return res
}
- _, res.Err = client.Request("POST", createURL(client, serverId), gophercloud.RequestOpts{
- JSONBody: reqBody,
- JSONResponse: &res.Body,
- OkCodes: []int{200},
+ _, res.Err = client.Post(createURL(client, serverId), reqBody, &res.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return res
}
@@ -65,15 +63,13 @@
// Get returns public data about a previously created VolumeAttachment.
func Get(client *gophercloud.ServiceClient, serverId, aId string) GetResult {
var res GetResult
- _, res.Err = client.Request("GET", getURL(client, serverId, aId), gophercloud.RequestOpts{
- JSONResponse: &res.Body,
- })
+ _, res.Err = client.Get(getURL(client, serverId, aId), &res.Body, nil)
return res
}
// Delete requests the deletion of a previous stored VolumeAttachment from the server.
func Delete(client *gophercloud.ServiceClient, serverId, aId string) DeleteResult {
var res DeleteResult
- _, res.Err = client.Request("DELETE", deleteURL(client, serverId, aId), gophercloud.RequestOpts{})
+ _, res.Err = client.Delete(deleteURL(client, serverId, aId), nil)
return res
}
diff --git a/openstack/compute/v2/flavors/requests.go b/openstack/compute/v2/flavors/requests.go
index 1d33f58..586be67 100644
--- a/openstack/compute/v2/flavors/requests.go
+++ b/openstack/compute/v2/flavors/requests.go
@@ -62,9 +62,7 @@
// Get instructs OpenStack to provide details on a single flavor, identified by its ID.
// Use ExtractFlavor to convert its result into a Flavor.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
- var gr GetResult
- _, gr.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &gr.Body,
- })
- return gr
+ var res GetResult
+ _, res.Err = client.Get(getURL(client, id), &res.Body, nil)
+ return res
}
diff --git a/openstack/compute/v2/images/requests.go b/openstack/compute/v2/images/requests.go
index b41d1d9..5eb19b5 100644
--- a/openstack/compute/v2/images/requests.go
+++ b/openstack/compute/v2/images/requests.go
@@ -60,8 +60,6 @@
// Use ExtractImage() to interpret the result as an openstack Image.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var result GetResult
- _, result.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- })
+ _, result.Err = client.Get(getURL(client, id), &result.Body, nil)
return result
}
diff --git a/openstack/compute/v2/servers/requests.go b/openstack/compute/v2/servers/requests.go
index c862b4d..e0950e4 100644
--- a/openstack/compute/v2/servers/requests.go
+++ b/openstack/compute/v2/servers/requests.go
@@ -216,29 +216,22 @@
return res
}
- _, res.Err = client.Request("POST", listURL(client), gophercloud.RequestOpts{
- JSONResponse: &res.Body,
- JSONBody: reqBody,
- OkCodes: []int{202},
- })
+ _, res.Err = client.Post(listURL(client), reqBody, &res.Body, nil)
return res
}
// Delete requests that a server previously provisioned be removed from your account.
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
var res DeleteResult
- _, res.Err = client.Request("DELETE", deleteURL(client, id), gophercloud.RequestOpts{
- OkCodes: []int{204},
- })
+ _, res.Err = client.Delete(deleteURL(client, id), nil)
return res
}
// Get requests details on a single server, by ID.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var result GetResult
- _, result.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- OkCodes: []int{200, 203},
+ _, result.Err = client.Get(getURL(client, id), &result.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200, 203},
})
return result
}
@@ -280,10 +273,9 @@
// Update requests that various attributes of the indicated server be changed.
func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) UpdateResult {
var result UpdateResult
- _, result.Err = client.Request("PUT", updateURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- JSONBody: opts.ToServerUpdateMap(),
- OkCodes: []int{200},
+ reqBody := opts.ToServerUpdateMap()
+ _, result.Err = client.Put(updateURL(client, id), reqBody, &result.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return result
}
@@ -299,12 +291,7 @@
req.ChangePassword.AdminPass = newPassword
var res ActionResult
-
- _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
- JSONBody: req,
- OkCodes: []int{202},
- })
-
+ _, res.Err = client.Post(actionURL(client, id), req, nil, nil)
return res
}
@@ -368,15 +355,13 @@
return res
}
- _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
- JSONBody: struct {
- C map[string]string `json:"reboot"`
- }{
- map[string]string{"type": string(how)},
- },
- OkCodes: []int{202},
- })
+ reqBody := struct {
+ C map[string]string `json:"reboot"`
+ }{
+ map[string]string{"type": string(how)},
+ }
+ _, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
return res
}
@@ -469,12 +454,7 @@
return result
}
- _, result.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
- JSONBody: &reqBody,
- JSONResponse: &result.Body,
- OkCodes: []int{202},
- })
-
+ _, result.Err = client.Post(actionURL(client, id), reqBody, &result.Body, nil)
return result
}
@@ -515,11 +495,7 @@
return res
}
- _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
- JSONBody: reqBody,
- OkCodes: []int{202},
- })
-
+ _, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
return res
}
@@ -528,11 +504,10 @@
func ConfirmResize(client *gophercloud.ServiceClient, id string) ActionResult {
var res ActionResult
- _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
- JSONBody: map[string]interface{}{"confirmResize": nil},
- OkCodes: []int{204},
+ reqBody := map[string]interface{}{"confirmResize": nil}
+ _, res.Err = client.Post(actionURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{201, 202, 204},
})
-
return res
}
@@ -540,12 +515,8 @@
// See Resize() for more details.
func RevertResize(client *gophercloud.ServiceClient, id string) ActionResult {
var res ActionResult
-
- _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
- JSONBody: map[string]interface{}{"revertResize": nil},
- OkCodes: []int{202},
- })
-
+ reqBody := map[string]interface{}{"revertResize": nil}
+ _, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
return res
}
@@ -587,10 +558,8 @@
return result
}
- _, result.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &result.Body,
- JSONBody: &reqBody,
- OkCodes: []int{200},
+ _, result.Err = client.Post(actionURL(client, id), reqBody, &result.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return result
@@ -626,10 +595,8 @@
res.Err = err
return res
}
- _, res.Err = client.Request("PUT", metadataURL(client, id), gophercloud.RequestOpts{
- JSONBody: metadata,
- JSONResponse: &res.Body,
- OkCodes: []int{200},
+ _, res.Err = client.Put(metadataURL(client, id), metadata, &res.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return res
}
@@ -637,9 +604,7 @@
// Metadata requests all the metadata for the given server ID.
func Metadata(client *gophercloud.ServiceClient, id string) GetMetadataResult {
var res GetMetadataResult
- _, res.Err = client.Request("GET", metadataURL(client, id), gophercloud.RequestOpts{
- JSONResponse: &res.Body,
- })
+ _, res.Err = client.Get(metadataURL(client, id), &res.Body, nil)
return res
}
@@ -659,10 +624,8 @@
res.Err = err
return res
}
- _, res.Err = client.Request("POST", metadataURL(client, id), gophercloud.RequestOpts{
- JSONBody: metadata,
- JSONResponse: &res.Body,
- OkCodes: []int{200},
+ _, res.Err = client.Post(metadataURL(client, id), metadata, &res.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return res
}
@@ -698,10 +661,8 @@
return res
}
- _, res.Err = client.Request("PUT", metadatumURL(client, id, key), gophercloud.RequestOpts{
- JSONBody: metadatum,
- JSONResponse: &res.Body,
- OkCodes: []int{200},
+ _, res.Err = client.Put(metadatumURL(client, id, key), metadatum, &res.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
})
return res
}
@@ -718,7 +679,7 @@
// DeleteMetadatum will delete the key-value pair with the given key for the given server ID.
func DeleteMetadatum(client *gophercloud.ServiceClient, id, key string) DeleteMetadatumResult {
var res DeleteMetadatumResult
- _, res.Err = client.Request("DELETE", metadatumURL(client, id, key), gophercloud.RequestOpts{
+ _, res.Err = client.Delete(metadatumURL(client, id, key), &gophercloud.RequestOpts{
JSONResponse: &res.Body,
})
return res