Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions acceptance/openstack/blockstorage/v1/snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func TestSnapshots(t *testing.T) {

t.Logf("Created snapshot: %+v\n", ss)

err = snapshots.Delete(client, ss.ID)
if err != nil {
res = snapshots.Delete(client, ss.ID)
if res.Err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about giving DeleteResult an Extract method that returns only the error, like ActionResult does? If not, should we take away ActionResult's method?

t.Fatalf("Failed to delete snapshot: %v", err)
}

Expand All @@ -66,8 +66,8 @@ func TestSnapshots(t *testing.T) {

t.Log("Deleted snapshot\n")

err = volumes.Delete(client, v.ID)
if err != nil {
res = volumes.Delete(client, v.ID)
if res.Err != nil {
t.Errorf("Failed to delete volume: %v", err)
}

Expand Down
4 changes: 2 additions & 2 deletions acceptance/openstack/blockstorage/v1/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func TestVolumes(t *testing.T) {
if err != nil {
t.Error(err)
}
err = volumes.Delete(client, cv.ID)
if err != nil {
res = volumes.Delete(client, cv.ID)
if res.Err != nil {
t.Error(err)
return
}
Expand Down
4 changes: 2 additions & 2 deletions acceptance/rackspace/blockstorage/v1/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func testSnapshotUpdate(t *testing.T, client *gophercloud.ServiceClient, id stri
}

func testSnapshotDelete(t *testing.T, client *gophercloud.ServiceClient, id string) {
err := snapshots.Delete(client, id)
th.AssertNoErr(t, err)
res := snapshots.Delete(client, id)
th.AssertNoErr(t, res.Err)
t.Logf("Deleted snapshot %s", id)
}
4 changes: 2 additions & 2 deletions acceptance/rackspace/blockstorage/v1/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func testVolumeUpdate(t *testing.T, client *gophercloud.ServiceClient, id string
}

func testVolumeDelete(t *testing.T, client *gophercloud.ServiceClient, id string) {
err := volumes.Delete(client, id)
th.AssertNoErr(t, err)
res := volumes.Delete(client, id)
th.AssertNoErr(t, res.Err)
t.Logf("Deleted volume %s", id)
}
4 changes: 2 additions & 2 deletions acceptance/rackspace/compute/v2/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func rebuildServer(t *testing.T, client *gophercloud.ServiceClient, server *os.S
func deleteServer(t *testing.T, client *gophercloud.ServiceClient, server *os.Server) {
t.Logf("> servers.Delete")

err := servers.Delete(client, server.ID)
th.AssertNoErr(t, err)
res := servers.Delete(client, server.ID)
th.AssertNoErr(t, res.Err)

t.Logf("Server deleted successfully.")
}
Expand Down
7 changes: 4 additions & 3 deletions openstack/blockstorage/v1/snapshots/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
}

// Delete will delete the existing Snapshot with the provided ID.
func Delete(client *gophercloud.ServiceClient, id string) error {
_, err := perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
var res DeleteResult
_, res.Err = perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{202, 204},
})
return err
return res
}

// Get retrieves the Snapshot with the provided ID. To extract the Snapshot
Expand Down
4 changes: 2 additions & 2 deletions openstack/blockstorage/v1/snapshots/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ func TestDelete(t *testing.T) {

MockDeleteResponse(t)

err := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertNoErr(t, err)
res := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertNoErr(t, res.Err)
}
5 changes: 5 additions & 0 deletions openstack/blockstorage/v1/snapshots/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type GetResult struct {
commonResult
}

// DeleteResult contains the response body and error from a Delete request.
type DeleteResult struct {
gophercloud.ExtractErrResult
}

// ListResult is a pagination.Pager that is returned from a call to the List function.
type ListResult struct {
pagination.SinglePageBase
Expand Down
7 changes: 4 additions & 3 deletions openstack/blockstorage/v1/volumes/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
}

// Delete will delete the existing Volume with the provided ID.
func Delete(client *gophercloud.ServiceClient, id string) error {
_, err := perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
var res DeleteResult
_, res.Err = perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{202, 204},
})
return err
return res
}

// Get retrieves the Volume with the provided ID. To extract the Volume object
Expand Down
4 changes: 2 additions & 2 deletions openstack/blockstorage/v1/volumes/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func TestDelete(t *testing.T) {

MockDeleteResponse(t)

err := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertNoErr(t, err)
res := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertNoErr(t, res.Err)
}

func TestUpdate(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions openstack/blockstorage/v1/volumes/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type GetResult struct {
commonResult
}

// DeleteResult contains the response body and error from a Delete request.
type DeleteResult struct {
gophercloud.ExtractErrResult
}

// ListResult is a pagination.pager that is returned from a call to the List function.
type ListResult struct {
pagination.SinglePageBase
Expand Down
1 change: 0 additions & 1 deletion openstack/compute/v2/extensions/keypairs/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func Delete(client *gophercloud.ServiceClient, name string) DeleteResult {
var res DeleteResult
_, res.Err = perigee.Request("DELETE", deleteURL(client, name), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
Results: &res.Body,
OkCodes: []int{202},
})
return res
Expand Down
7 changes: 1 addition & 6 deletions openstack/compute/v2/extensions/keypairs/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,5 @@ type GetResult struct {
// DeleteResult is the response from a Delete operation. Call its Extract method to determine if
// the call succeeded or failed.
type DeleteResult struct {
gophercloud.Result
}

// Extract determines whether or not a deletion request was accepted.
func (r DeleteResult) Extract() error {
return r.Err
gophercloud.ExtractErrResult
}
8 changes: 4 additions & 4 deletions openstack/compute/v2/servers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,13 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
}

// Delete requests that a server previously provisioned be removed from your account.
func Delete(client *gophercloud.ServiceClient, id string) error {
_, err := perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
var res DeleteResult
_, res.Err = perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{204},
})
return err
return res
}

// Get requests details on a single server, by ID.
Expand Down Expand Up @@ -283,7 +284,6 @@ func ChangeAdminPassword(client *gophercloud.ServiceClient, id, newPassword stri

_, res.Err = perigee.Request("POST", actionURL(client, id), perigee.Options{
ReqBody: req,
Results: &res.Body,
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{202},
})
Expand Down
4 changes: 2 additions & 2 deletions openstack/compute/v2/servers/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func TestDeleteServer(t *testing.T) {
defer th.TeardownHTTP()
HandleServerDeletionSuccessfully(t)

err := Delete(client.ServiceClient(), "asdfasdfasdf")
th.AssertNoErr(t, err)
res := Delete(client.ServiceClient(), "asdfasdfasdf")
th.AssertNoErr(t, res.Err)
}

func TestGetServer(t *testing.T) {
Expand Down
15 changes: 7 additions & 8 deletions openstack/compute/v2/servers/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ type UpdateResult struct {
serverResult
}

// DeleteResult temporarily contains the response from an Delete call.
type DeleteResult struct {
gophercloud.ExtractErrResult
}

// RebuildResult temporarily contains the response from a Rebuild call.
type RebuildResult struct {
serverResult
}

// ActionResult represents the result of server action operations, like reboot
type ActionResult struct {
gophercloud.Result
}

// Extract is a function that extracts error information from a result
func (r ActionResult) Extract() error {
return r.Err
gophercloud.ExtractErrResult
}

// Server exposes only the standard OpenStack fields corresponding to a given server on the user's account.
Expand Down Expand Up @@ -82,8 +82,7 @@ type Server struct {
Progress int

// AccessIPv4 and AccessIPv6 contain the IP addresses of the server, suitable for remote access for administration.
AccessIPv4 string
AccessIPv6 string
AccessIPv4, AccessIPv6 string

// Image refers to a JSON object, which itself indicates the OS image used to deploy the server.
Image map[string]interface{}
Expand Down
7 changes: 4 additions & 3 deletions openstack/identity/v3/endpoints/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ func Update(client *gophercloud.ServiceClient, endpointID string, opts EndpointO
}

// Delete removes an endpoint from the service catalog.
func Delete(client *gophercloud.ServiceClient, endpointID string) error {
_, err := perigee.Request("DELETE", endpointURL(client, endpointID), perigee.Options{
func Delete(client *gophercloud.ServiceClient, endpointID string) DeleteResult {
var res DeleteResult
_, res.Err = perigee.Request("DELETE", endpointURL(client, endpointID), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{204},
})
return err
return res
}
6 changes: 2 additions & 4 deletions openstack/identity/v3/endpoints/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ func TestDeleteEndpoint(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})

err := Delete(client.ServiceClient(), "34")
if err != nil {
t.Fatalf("Unexpected error from Delete: %v", err)
}
res := Delete(client.ServiceClient(), "34")
testhelper.AssertNoErr(t, res.Err)
}
5 changes: 5 additions & 0 deletions openstack/identity/v3/endpoints/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ type UpdateResult struct {
commonResult
}

// DeleteResult is the deferred result of an Delete call.
type DeleteResult struct {
gophercloud.ExtractErrResult
}

// Endpoint describes the entry point for another service's API.
type Endpoint struct {
ID string `mapstructure:"id" json:"id"`
Expand Down
7 changes: 4 additions & 3 deletions openstack/identity/v3/services/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ func Update(client *gophercloud.ServiceClient, serviceID string, serviceType str

// Delete removes an existing service.
// It either deletes all associated endpoints, or fails until all endpoints are deleted.
func Delete(client *gophercloud.ServiceClient, serviceID string) error {
_, err := perigee.Request("DELETE", serviceURL(client, serviceID), perigee.Options{
func Delete(client *gophercloud.ServiceClient, serviceID string) DeleteResult {
var res DeleteResult
_, res.Err = perigee.Request("DELETE", serviceURL(client, serviceID), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{204},
})
return err
return res
}
6 changes: 2 additions & 4 deletions openstack/identity/v3/services/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ func TestDeleteSuccessful(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})

err := Delete(client.ServiceClient(), "12345")
if err != nil {
t.Fatalf("Unable to delete service: %v", err)
}
res := Delete(client.ServiceClient(), "12345")
testhelper.AssertNoErr(t, res.Err)
}
5 changes: 5 additions & 0 deletions openstack/identity/v3/services/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ type UpdateResult struct {
commonResult
}

// DeleteResult is the deferred result of an Delete call.
type DeleteResult struct {
gophercloud.ExtractErrResult
}

// Service is the result of a list or information query.
type Service struct {
Description *string `json:"description,omitempty"`
Expand Down
7 changes: 4 additions & 3 deletions openstack/identity/v3/tokens/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,11 @@ func Validate(c *gophercloud.ServiceClient, token string) (bool, error) {
}

// Revoke immediately makes specified token invalid.
func Revoke(c *gophercloud.ServiceClient, token string) error {
_, err := perigee.Request("DELETE", tokenURL(c), perigee.Options{
func Revoke(c *gophercloud.ServiceClient, token string) RevokeResult {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Cool, I forgot all about these.

var res RevokeResult
_, res.Err = perigee.Request("DELETE", tokenURL(c), perigee.Options{
MoreHeaders: subjectTokenHeaders(c, token),
OkCodes: []int{204},
})
return err
return res
}
10 changes: 4 additions & 6 deletions openstack/identity/v3/tokens/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,19 +498,17 @@ func TestRevokeRequestSuccessful(t *testing.T) {
defer testhelper.TeardownHTTP()
client := prepareAuthTokenHandler(t, "DELETE", http.StatusNoContent)

err := Revoke(&client, "abcdef12345")
if err != nil {
t.Errorf("Unexpected error from Revoke: %v", err)
}
res := Revoke(&client, "abcdef12345")
testhelper.AssertNoErr(t, res.Err)
}

func TestRevokeRequestError(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
client := prepareAuthTokenHandler(t, "DELETE", http.StatusNotFound)

err := Revoke(&client, "abcdef12345")
if err == nil {
res := Revoke(&client, "abcdef12345")
if res.Err == nil {
t.Errorf("Missing expected error from Revoke")
}
}
5 changes: 5 additions & 0 deletions openstack/identity/v3/tokens/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ type GetResult struct {
commonResult
}

// RevokeResult is the deferred response from a Revoke call.
type RevokeResult struct {
commonResult
}

// Token is a string that grants a user access to a controlled set of services in an OpenStack provider.
// Each Token is valid for a set length of time.
type Token struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ type UpdateResult struct {
}

// DeleteResult represents the result of an update operation.
type DeleteResult commonResult
type DeleteResult struct {
gophercloud.ExtractErrResult
}

// FloatingIPPage is the page returned by a pager when traversing over a
// collection of floating IPs.
Expand Down
4 changes: 3 additions & 1 deletion openstack/networking/v2/extensions/layer3/routers/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ type UpdateResult struct {
}

// DeleteResult represents the result of a delete operation.
type DeleteResult commonResult
type DeleteResult struct {
gophercloud.ExtractErrResult
}

// InterfaceInfo represents information about a particular router interface. As
// mentioned above, in order for a router to forward to a subnet, it needs an
Expand Down
4 changes: 3 additions & 1 deletion openstack/networking/v2/extensions/lbaas/members/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@ type UpdateResult struct {
}

// DeleteResult represents the result of a delete operation.
type DeleteResult commonResult
type DeleteResult struct {
gophercloud.ExtractErrResult
}
4 changes: 3 additions & 1 deletion openstack/networking/v2/extensions/lbaas/monitors/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,6 @@ type UpdateResult struct {
}

// DeleteResult represents the result of a delete operation.
type DeleteResult commonResult
type DeleteResult struct {
gophercloud.ExtractErrResult
}
Loading