Delete VIPs
diff --git a/rackspace/lb/v1/vips/requests.go b/rackspace/lb/v1/vips/requests.go
index 92bd0b2..ffdc74c 100644
--- a/rackspace/lb/v1/vips/requests.go
+++ b/rackspace/lb/v1/vips/requests.go
@@ -1,10 +1,13 @@
package vips
import (
+ "errors"
+
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
+ "github.com/rackspace/gophercloud/rackspace/lb/v1"
)
// List is the operation responsible for returning a paginated collection of
@@ -27,11 +30,15 @@
// CreateOpts is the common options struct used in this package's Create
// operation.
type CreateOpts struct {
+ // Optional - the ID of an existing virtual IP. By doing this, you are
+ // allowing load balancers to share IPV6 addresses.
ID string
- Type string
+ // Optional - the type of address.
+ Type Type
- Version string
+ // Optional - the version of address.
+ Version Version
}
// ToVIPCreateMap casts a CreateOpts struct to a map.
@@ -51,6 +58,9 @@
return lb, nil
}
+// Create is the operation responsible for assigning a new Virtual IP to an
+// existing load balancer resource. Currently, only version 6 IP addresses may
+// be added.
func Create(c *gophercloud.ServiceClient, lbID int, opts CreateOptsBuilder) CreateResult {
var res CreateResult
@@ -69,3 +79,35 @@
return res
}
+
+// BulkDelete is the operation responsible for batch deleting multiple VIPs in
+// a single operation. It accepts a slice of integer IDs and will remove them
+// from the load balancer. The maximum limit is 10 VIP removals at once.
+func BulkDelete(c *gophercloud.ServiceClient, loadBalancerID int, vipIDs []int) DeleteResult {
+ var res DeleteResult
+
+ if len(vipIDs) > 10 || len(vipIDs) == 0 {
+ res.Err = errors.New("You must provide a minimum of 1 and a maximum of 10 VIP IDs")
+ return res
+ }
+
+ url := rootURL(c, loadBalancerID)
+ url += v1.IDSliceToQueryString("id", vipIDs)
+
+ _, res.Err = perigee.Request("DELETE", url, perigee.Options{
+ MoreHeaders: c.AuthenticatedHeaders(),
+ OkCodes: []int{202},
+ })
+
+ return res
+}
+
+// Delete is the operation responsible for permanently deleting a VIP.
+func Delete(c *gophercloud.ServiceClient, lbID, vipID int) DeleteResult {
+ var res DeleteResult
+ _, res.Err = perigee.Request("DELETE", resourceURL(c, lbID, vipID), perigee.Options{
+ MoreHeaders: c.AuthenticatedHeaders(),
+ OkCodes: []int{200},
+ })
+ return res
+}
diff --git a/rackspace/lb/v1/vips/requests_test.go b/rackspace/lb/v1/vips/requests_test.go
index 762b139..74ac461 100644
--- a/rackspace/lb/v1/vips/requests_test.go
+++ b/rackspace/lb/v1/vips/requests_test.go
@@ -9,8 +9,9 @@
)
const (
- lbID = 12345
- vipID = 67890
+ lbID = 12345
+ vipID = 67890
+ vipID2 = 67891
)
func TestList(t *testing.T) {
@@ -62,3 +63,25 @@
th.CheckDeepEquals(t, expected, vip)
}
+
+func TestBulkDelete(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ ids := []int{vipID, vipID2}
+
+ mockBatchDeleteResponse(t, lbID, ids)
+
+ err := BulkDelete(client.ServiceClient(), lbID, ids).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestDelete(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ mockDeleteResponse(t, lbID, vipID)
+
+ err := Delete(client.ServiceClient(), lbID, vipID).ExtractErr()
+ th.AssertNoErr(t, err)
+}
diff --git a/rackspace/lb/v1/vips/results.go b/rackspace/lb/v1/vips/results.go
index aa5ef37..678b2af 100644
--- a/rackspace/lb/v1/vips/results.go
+++ b/rackspace/lb/v1/vips/results.go
@@ -9,12 +9,32 @@
// VIP represents a Virtual IP API resource.
type VIP struct {
- Address string `json:"address,omitempty"`
- ID int `json:"id,omitempty"`
- Type string `json:"type,omitempty"`
- Version string `json:"ipVersion,omitempty" mapstructure:"ipVersion"`
+ Address string `json:"address,omitempty"`
+ ID int `json:"id,omitempty"`
+ Type Type `json:"type,omitempty"`
+ Version Version `json:"ipVersion,omitempty" mapstructure:"ipVersion"`
}
+// Version represents the version of a VIP.
+type Version string
+
+// Convenient constants to use for type
+const (
+ IPV4 Version = "IPV4"
+ IPV6 Version = "IPV6"
+)
+
+// Type represents the type of a VIP.
+type Type string
+
+const (
+ // PUBLIC indicates a VIP type that is routable on the public Internet.
+ PUBLIC Type = "PUBLIC"
+
+ // PRIVATE indicates a VIP type that is routable only on ServiceNet.
+ PRIVATE Type = "SERVICENET"
+)
+
// VIPPage is the page returned by a pager when traversing over a collection
// of VIPs.
type VIPPage struct {
@@ -58,6 +78,12 @@
return resp, err
}
+// CreateResult represents the result of a create operation.
type CreateResult struct {
commonResult
}
+
+// DeleteResult represents the result of a delete operation.
+type DeleteResult struct {
+ gophercloud.ErrResult
+}