Create VIP operation
diff --git a/rackspace/lb/v1/vips/requests.go b/rackspace/lb/v1/vips/requests.go
index d4bdb98..92bd0b2 100644
--- a/rackspace/lb/v1/vips/requests.go
+++ b/rackspace/lb/v1/vips/requests.go
@@ -1,6 +1,8 @@
package vips
import (
+ "github.com/racker/perigee"
+
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
)
@@ -13,3 +15,57 @@
return VIPPage{pagination.SinglePageBase(r)}
})
}
+
+// CreateOptsBuilder is the interface options structs have to satisfy in order
+// to be used in the main Create operation in this package. Since many
+// extensions decorate or modify the common logic, it is useful for them to
+// satisfy a basic interface in order for them to be used.
+type CreateOptsBuilder interface {
+ ToVIPCreateMap() (map[string]interface{}, error)
+}
+
+// CreateOpts is the common options struct used in this package's Create
+// operation.
+type CreateOpts struct {
+ ID string
+
+ Type string
+
+ Version string
+}
+
+// ToVIPCreateMap casts a CreateOpts struct to a map.
+func (opts CreateOpts) ToVIPCreateMap() (map[string]interface{}, error) {
+ lb := make(map[string]interface{})
+
+ if opts.ID != "" {
+ lb["id"] = opts.ID
+ }
+ if opts.Type != "" {
+ lb["type"] = opts.Type
+ }
+ if opts.Version != "" {
+ lb["ipVersion"] = opts.Version
+ }
+
+ return lb, nil
+}
+
+func Create(c *gophercloud.ServiceClient, lbID int, opts CreateOptsBuilder) CreateResult {
+ var res CreateResult
+
+ reqBody, err := opts.ToVIPCreateMap()
+ if err != nil {
+ res.Err = err
+ return res
+ }
+
+ _, res.Err = perigee.Request("POST", rootURL(c, lbID), perigee.Options{
+ MoreHeaders: c.AuthenticatedHeaders(),
+ ReqBody: &reqBody,
+ Results: &res.Body,
+ OkCodes: []int{202},
+ })
+
+ return res
+}