blob: 92bd0b28b521949b20412cfdb7b2405a35947f10 [file] [log] [blame]
Jamie Hannafordf0cd1652014-11-04 10:54:11 +01001package vips
Jamie Hannaford2841a532014-11-04 11:05:42 +01002
3import (
Jamie Hannafordf7e8e1a2014-11-04 11:48:46 +01004 "github.com/racker/perigee"
5
Jamie Hannaford2841a532014-11-04 11:05:42 +01006 "github.com/rackspace/gophercloud"
7 "github.com/rackspace/gophercloud/pagination"
8)
9
10// List is the operation responsible for returning a paginated collection of
11// load balancer virtual IP addresses.
12func List(client *gophercloud.ServiceClient, loadBalancerID int) pagination.Pager {
13 url := rootURL(client, loadBalancerID)
14 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
15 return VIPPage{pagination.SinglePageBase(r)}
16 })
17}
Jamie Hannafordf7e8e1a2014-11-04 11:48:46 +010018
19// CreateOptsBuilder is the interface options structs have to satisfy in order
20// to be used in the main Create operation in this package. Since many
21// extensions decorate or modify the common logic, it is useful for them to
22// satisfy a basic interface in order for them to be used.
23type CreateOptsBuilder interface {
24 ToVIPCreateMap() (map[string]interface{}, error)
25}
26
27// CreateOpts is the common options struct used in this package's Create
28// operation.
29type CreateOpts struct {
30 ID string
31
32 Type string
33
34 Version string
35}
36
37// ToVIPCreateMap casts a CreateOpts struct to a map.
38func (opts CreateOpts) ToVIPCreateMap() (map[string]interface{}, error) {
39 lb := make(map[string]interface{})
40
41 if opts.ID != "" {
42 lb["id"] = opts.ID
43 }
44 if opts.Type != "" {
45 lb["type"] = opts.Type
46 }
47 if opts.Version != "" {
48 lb["ipVersion"] = opts.Version
49 }
50
51 return lb, nil
52}
53
54func Create(c *gophercloud.ServiceClient, lbID int, opts CreateOptsBuilder) CreateResult {
55 var res CreateResult
56
57 reqBody, err := opts.ToVIPCreateMap()
58 if err != nil {
59 res.Err = err
60 return res
61 }
62
63 _, res.Err = perigee.Request("POST", rootURL(c, lbID), perigee.Options{
64 MoreHeaders: c.AuthenticatedHeaders(),
65 ReqBody: &reqBody,
66 Results: &res.Body,
67 OkCodes: []int{202},
68 })
69
70 return res
71}