Bulk delete network items from access list
diff --git a/rackspace/lb/v1/acl/requests.go b/rackspace/lb/v1/acl/requests.go
index e564307..206ec48 100644
--- a/rackspace/lb/v1/acl/requests.go
+++ b/rackspace/lb/v1/acl/requests.go
@@ -1 +1,101 @@
package acl
+
+import (
+ "errors"
+ "fmt"
+
+ "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
+// network items that define a load balancer's access list.
+func List(client *gophercloud.ServiceClient, lbID int) pagination.Pager {
+ url := rootURL(client, lbID)
+
+ return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
+ return AccessListPage{pagination.SinglePageBase(r)}
+ })
+}
+
+// CreateOptsBuilder is the interface responsible for generating the JSON
+// for a Create operation.
+type CreateOptsBuilder interface {
+ ToAccessListCreateMap() (map[string]interface{}, error)
+}
+
+// CreateOpts is a slice of CreateOpt structs, that allow the user to create
+// multiple nodes in a single operation (one node per CreateOpt).
+type CreateOpts []CreateOpt
+
+// CreateOpt represents the options to create a single node.
+type CreateOpt struct {
+ // Required - the IP address or CIDR for item to add to access list.
+ Address string
+
+ // Required - the type of the node. Either ALLOW or DENY.
+ Type Type
+}
+
+// ToAccessListCreateMap converts a slice of options into a map that can be
+// used for the JSON.
+func (opts CreateOpts) ToAccessListCreateMap() (map[string]interface{}, error) {
+ type itemMap map[string]interface{}
+ items := []itemMap{}
+
+ for k, v := range opts {
+ if v.Address == "" {
+ return itemMap{}, fmt.Errorf("Address is a required attribute, none provided for %d CreateOpt element", k)
+ }
+ if v.Type != ALLOW && v.Type != DENY {
+ return itemMap{}, fmt.Errorf("Type must be ALLOW or DENY")
+ }
+
+ item := make(itemMap)
+ item["address"] = v.Address
+ item["type"] = v.Type
+
+ items = append(items, item)
+ }
+
+ return itemMap{"accessList": items}, nil
+}
+
+func Create(client *gophercloud.ServiceClient, loadBalancerID int, opts CreateOptsBuilder) CreateResult {
+ var res CreateResult
+
+ reqBody, err := opts.ToAccessListCreateMap()
+ if err != nil {
+ res.Err = err
+ return res
+ }
+
+ _, res.Err = perigee.Request("POST", rootURL(client, loadBalancerID), perigee.Options{
+ MoreHeaders: client.AuthenticatedHeaders(),
+ ReqBody: &reqBody,
+ OkCodes: []int{202},
+ })
+
+ return res
+}
+
+func BulkDelete(c *gophercloud.ServiceClient, loadBalancerID int, itemIDs []int) DeleteResult {
+ var res DeleteResult
+
+ if len(itemIDs) > 10 || len(itemIDs) == 0 {
+ res.Err = errors.New("You must provide a minimum of 1 and a maximum of 10 item IDs")
+ return res
+ }
+
+ url := rootURL(c, loadBalancerID)
+ url += v1.IDSliceToQueryString("id", itemIDs)
+
+ _, res.Err = perigee.Request("DELETE", url, perigee.Options{
+ MoreHeaders: c.AuthenticatedHeaders(),
+ OkCodes: []int{200},
+ })
+
+ return res
+}