Update gophercloud: cleanup lbaas v1

This commit is contained in:
FengyunPan
2017-10-23 18:01:03 +08:00
parent b308e36819
commit bf7f1a0610
28 changed files with 58 additions and 2578 deletions

View File

@@ -12,6 +12,8 @@ go:
env:
global:
- secure: "xSQsAG5wlL9emjbCdxzz/hYQsSpJ/bABO1kkbwMSISVcJ3Nk0u4ywF+LS4bgeOnwPfmFvNTOqVDu3RwEvMeWXSI76t1piCPcObutb2faKLVD/hLoAS76gYX+Z8yGWGHrSB7Do5vTPj1ERe2UljdrnsSeOXzoDwFxYRaZLX4bBOB4AyoGvRniil5QXPATiA1tsWX1VMicj8a4F8X+xeESzjt1Q5Iy31e7vkptu71bhvXCaoo5QhYwT+pLR9dN0S1b7Ro0KVvkRefmr1lUOSYd2e74h6Lc34tC1h3uYZCS4h47t7v5cOXvMNxinEj2C51RvbjvZI1RLVdkuAEJD1Iz4+Ote46nXbZ//6XRZMZz/YxQ13l7ux1PFjgEB6HAapmF5Xd8PRsgeTU9LRJxpiTJ3P5QJ3leS1va8qnziM5kYipj/Rn+V8g2ad/rgkRox9LSiR9VYZD2Pe45YCb1mTKSl2aIJnV7nkOqsShY5LNB4JZSg7xIffA+9YVDktw8dJlATjZqt7WvJJ49g6A61mIUV4C15q2JPGKTkZzDiG81NtmS7hFa7k0yaE2ELgYocbcuyUcAahhxntYTC0i23nJmEHVNiZmBO3u7EgpWe4KGVfumU+lt12tIn5b3dZRBBUk3QakKKozSK1QPHGpk/AZGrhu7H6l8to6IICKWtDcyMPQ="
before_script:
- go vet ./...
script:
- ./script/coverage
- ./script/format

View File

@@ -25,10 +25,6 @@ filegroup(
":package-srcs",
"//vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips:all-srcs",
"//vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers:all-srcs",
"//vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members:all-srcs",
"//vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors:all-srcs",
"//vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools:all-srcs",
"//vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips:all-srcs",
"//vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners:all-srcs",
"//vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers:all-srcs",
"//vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors:all-srcs",

View File

@@ -8,7 +8,15 @@ import (
// GatewayInfo represents the information of an external gateway for any
// particular network router.
type GatewayInfo struct {
NetworkID string `json:"network_id"`
NetworkID string `json:"network_id"`
ExternalFixedIPs []ExternalFixedIP `json:"external_fixed_ips,omitempty"`
}
// ExternalFixedIP is the IP address and subnet ID of the external gateway of a
// router.
type ExternalFixedIP struct {
IPAddress string `json:"ip_address"`
SubnetID string `json:"subnet_id"`
}
// Route is a possible route in a router.

View File

@@ -1,31 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"requests.go",
"results.go",
"urls.go",
],
importpath = "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/pagination:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -1,59 +0,0 @@
/*
Package members provides information and interaction with Members of the
Load Balancer as a Service extension for the OpenStack Networking service.
Example to List Members
listOpts := members.ListOpts{
ProtocolPort: 80,
}
allPages, err := members.List(networkClient, listOpts).AllPages()
if err != nil {
panic(err)
}
allMembers, err := members.ExtractMembers(allPages)
if err != nil {
panic(err)
}
for _, member := range allMembers {
fmt.Printf("%+v\n", member)
}
Example to Create a Member
createOpts := members.CreateOpts{
Address: "192.168.2.14",
ProtocolPort: 80,
PoolID: "0b266a12-0fdf-4434-bd11-649d84e54bd5"
}
member, err := members.Create(networkClient, createOpts).Extract()
if err != nil {
panic(err)
}
Example to Update a Member
memberID := "46592c54-03f7-40ef-9cdf-b1fcf2775ddf"
updateOpts := members.UpdateOpts{
AdminStateUp: gophercloud.Disabled,
}
member, err := members.Update(networkClient, memberID, updateOpts).Extract()
if err != nil {
panic(err)
}
Example to Delete a Member
memberID := "46592c54-03f7-40ef-9cdf-b1fcf2775ddf"
err := members.Delete(networkClient, memberID).ExtractErr()
if err != nil {
panic(err)
}
*/
package members

View File

@@ -1,124 +0,0 @@
package members
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Filtering is achieved by passing in struct field values that map to
// the floating IP attributes you want to see returned. SortKey allows you to
// sort by a particular network attribute. SortDir sets the direction, and is
// either `asc' or `desc'. Marker and Limit are used for pagination.
type ListOpts struct {
Status string `q:"status"`
Weight int `q:"weight"`
AdminStateUp *bool `q:"admin_state_up"`
TenantID string `q:"tenant_id"`
PoolID string `q:"pool_id"`
Address string `q:"address"`
ProtocolPort int `q:"protocol_port"`
ID string `q:"id"`
Limit int `q:"limit"`
Marker string `q:"marker"`
SortKey string `q:"sort_key"`
SortDir string `q:"sort_dir"`
}
// List returns a Pager which allows you to iterate over a collection of
// members. It accepts a ListOpts struct, which allows you to filter and sort
// the returned collection for greater efficiency.
//
// Default policy settings return only those members that are owned by the
// tenant who submits the request, unless an admin user submits the request.
func List(c *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
q, err := gophercloud.BuildQueryString(&opts)
if err != nil {
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
return MemberPage{pagination.LinkedPageBase{PageResult: r}}
})
}
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToLBMemberCreateMap() (map[string]interface{}, error)
}
// CreateOpts contains all the values needed to create a new pool member.
type CreateOpts struct {
// Address is the IP address of the member.
Address string `json:"address" required:"true"`
// ProtocolPort is the port on which the application is hosted.
ProtocolPort int `json:"protocol_port" required:"true"`
// PoolID is the pool to which this member will belong.
PoolID string `json:"pool_id" required:"true"`
// TenantID is only required if the caller has an admin role and wants
// to create a pool for another tenant.
TenantID string `json:"tenant_id,omitempty"`
}
// ToLBMemberCreateMap builds a request body from CreateOpts.
func (opts CreateOpts) ToLBMemberCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "member")
}
// Create accepts a CreateOpts struct and uses the values to create a new
// load balancer pool member.
func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToLBMemberCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
return
}
// Get retrieves a particular pool member based on its unique ID.
func Get(c *gophercloud.ServiceClient, id string) (r GetResult) {
_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
return
}
// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToLBMemberUpdateMap() (map[string]interface{}, error)
}
// UpdateOpts contains the values used when updating a pool member.
type UpdateOpts struct {
// The administrative state of the member, which is up (true) or down (false).
AdminStateUp *bool `json:"admin_state_up,omitempty"`
}
// ToLBMemberUpdateMap builds a request body from UpdateOpts.
func (opts UpdateOpts) ToLBMemberUpdateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "member")
}
// Update allows members to be updated.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToLBMemberUpdateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 201, 202},
})
return
}
// Delete will permanently delete a particular member based on its unique ID.
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = c.Delete(resourceURL(c, id), nil)
return
}

View File

@@ -1,109 +0,0 @@
package members
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// Member represents the application running on a backend server.
type Member struct {
// Status is the status of the member. Indicates whether the member
// is operational.
Status string
// Weight is the weight of member.
Weight int
// AdminStateUp is the administrative state of the member, which is up
// (true) or down (false).
AdminStateUp bool `json:"admin_state_up"`
// TenantID is the owner of the member.
TenantID string `json:"tenant_id"`
// PoolID is the pool to which the member belongs.
PoolID string `json:"pool_id"`
// Address is the IP address of the member.
Address string
// ProtocolPort is the port on which the application is hosted.
ProtocolPort int `json:"protocol_port"`
// ID is the unique ID for the member.
ID string
}
// MemberPage is the page returned by a pager when traversing over a
// collection of pool members.
type MemberPage struct {
pagination.LinkedPageBase
}
// NextPageURL is invoked when a paginated collection of members has reached
// the end of a page and the pager seeks to traverse over a new one. In order
// to do this, it needs to construct the next page's URL.
func (r MemberPage) NextPageURL() (string, error) {
var s struct {
Links []gophercloud.Link `json:"members_links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return gophercloud.ExtractNextURL(s.Links)
}
// IsEmpty checks whether a MemberPage struct is empty.
func (r MemberPage) IsEmpty() (bool, error) {
is, err := ExtractMembers(r)
return len(is) == 0, err
}
// ExtractMembers accepts a Page struct, specifically a MemberPage struct,
// and extracts the elements into a slice of Member structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractMembers(r pagination.Page) ([]Member, error) {
var s struct {
Members []Member `json:"members"`
}
err := (r.(MemberPage)).ExtractInto(&s)
return s.Members, err
}
type commonResult struct {
gophercloud.Result
}
// Extract is a function that accepts a result and extracts a member.
func (r commonResult) Extract() (*Member, error) {
var s struct {
Member *Member `json:"member"`
}
err := r.ExtractInto(&s)
return s.Member, err
}
// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Member.
type CreateResult struct {
commonResult
}
// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Member.
type GetResult struct {
commonResult
}
// UpdateResult represents the result of an update operation. Call its Extract
// method to interpret it as a Member.
type UpdateResult struct {
commonResult
}
// DeleteResult represents the result of a delete operation. Call its
// ExtractErr method to determine if the result succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}

View File

@@ -1,16 +0,0 @@
package members
import "github.com/gophercloud/gophercloud"
const (
rootPath = "lb"
resourcePath = "members"
)
func rootURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL(rootPath, resourcePath)
}
func resourceURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL(rootPath, resourcePath, id)
}

View File

@@ -1,31 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"requests.go",
"results.go",
"urls.go",
],
importpath = "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/pagination:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -1,63 +0,0 @@
/*
Package monitors provides information and interaction with the Monitors
of the Load Balancer as a Service extension for the OpenStack Networking
Service.
Example to List Monitors
listOpts: monitors.ListOpts{
Type: "HTTP",
}
allPages, err := monitors.List(networkClient, listOpts).AllPages()
if err != nil {
panic(err)
}
allMonitors, err := monitors.ExtractMonitors(allPages)
if err != nil {
panic(err)
}
for _, monitor := range allMonitors {
fmt.Printf("%+v\n", monitor)
}
Example to Create a Monitor
createOpts := monitors.CreateOpts{
Type: "HTTP",
Delay: 20,
Timeout: 20,
MaxRetries: 5,
URLPath: "/check",
ExpectedCodes: "200-299",
}
monitor, err := monitors.Create(networkClient, createOpts).Extract()
if err != nil {
panic(err)
}
Example to Update a Monitor
monitorID := "681aed03-aadb-43ae-aead-b9016375650a"
updateOpts := monitors.UpdateOpts{
Timeout: 30,
}
monitor, err := monitors.Update(networkClient, monitorID, updateOpts).Extract()
if err != nil {
panic(err)
}
Example to Delete a Member
monitorID := "681aed03-aadb-43ae-aead-b9016375650a"
err := monitors.Delete(networkClient, monitorID).ExtractErr()
if err != nil {
panic(err)
}
*/
package monitors

View File

@@ -1,227 +0,0 @@
package monitors
import (
"fmt"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Filtering is achieved by passing in struct field values that map to
// the floating IP attributes you want to see returned. SortKey allows you to
// sort by a particular network attribute. SortDir sets the direction, and is
// either `asc' or `desc'. Marker and Limit are used for pagination.
type ListOpts struct {
ID string `q:"id"`
TenantID string `q:"tenant_id"`
Type string `q:"type"`
Delay int `q:"delay"`
Timeout int `q:"timeout"`
MaxRetries int `q:"max_retries"`
HTTPMethod string `q:"http_method"`
URLPath string `q:"url_path"`
ExpectedCodes string `q:"expected_codes"`
AdminStateUp *bool `q:"admin_state_up"`
Status string `q:"status"`
Limit int `q:"limit"`
Marker string `q:"marker"`
SortKey string `q:"sort_key"`
SortDir string `q:"sort_dir"`
}
// List returns a Pager which allows you to iterate over a collection of
// monitors. It accepts a ListOpts struct, which allows you to filter and sort
// the returned collection for greater efficiency.
//
// Default policy settings return only those monitors that are owned by the
// tenant who submits the request, unless an admin user submits the request.
func List(c *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
q, err := gophercloud.BuildQueryString(&opts)
if err != nil {
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
return MonitorPage{pagination.LinkedPageBase{PageResult: r}}
})
}
// MonitorType is the type for all the types of LB monitors.
type MonitorType string
// Constants that represent approved monitoring types.
const (
TypePING MonitorType = "PING"
TypeTCP MonitorType = "TCP"
TypeHTTP MonitorType = "HTTP"
TypeHTTPS MonitorType = "HTTPS"
)
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToLBMonitorCreateMap() (map[string]interface{}, error)
}
// CreateOpts contains all the values needed to create a new health monitor.
type CreateOpts struct {
// MonitorType is the type of probe, which is PING, TCP, HTTP, or HTTPS,
// that is sent by the load balancer to verify the member state.
Type MonitorType `json:"type" required:"true"`
// Delay is the time, in seconds, between sending probes to members.
Delay int `json:"delay" required:"true"`
// Timeout is the maximum number of seconds for a monitor to wait for a ping
// reply before it times out. The value must be less than the delay value.
Timeout int `json:"timeout" required:"true"`
// MaxRetries is the number of permissible ping failures before changing the
// member's status to INACTIVE. Must be a number between 1 and 10.
MaxRetries int `json:"max_retries" required:"true"`
// URLPath is the URI path that will be accessed if monitor type
// is HTTP or HTTPS. Required for HTTP(S) types.
URLPath string `json:"url_path,omitempty"`
// HTTPMethod is the HTTP method used for requests by the monitor. If this
// attribute is not specified, it defaults to "GET". Required for HTTP(S)
// types.
HTTPMethod string `json:"http_method,omitempty"`
// ExpectedCodes is the expected HTTP codes for a passing HTTP(S) monitor
// You can either specify a single status like "200", or a range like
// "200-202". Required for HTTP(S) types.
ExpectedCodes string `json:"expected_codes,omitempty"`
// TenantID is only required if the caller has an admin role and wants
// to create a pool for another tenant.
TenantID string `json:"tenant_id,omitempty"`
// AdminStateUp denotes whether the monitor is administratively up or down.
AdminStateUp *bool `json:"admin_state_up,omitempty"`
}
// ToLBMonitorCreateMap builds a request body from CreateOpts.
func (opts CreateOpts) ToLBMonitorCreateMap() (map[string]interface{}, error) {
if opts.Type == TypeHTTP || opts.Type == TypeHTTPS {
if opts.URLPath == "" {
err := gophercloud.ErrMissingInput{}
err.Argument = "monitors.CreateOpts.URLPath"
return nil, err
}
if opts.ExpectedCodes == "" {
err := gophercloud.ErrMissingInput{}
err.Argument = "monitors.CreateOpts.ExpectedCodes"
return nil, err
}
}
if opts.Delay < opts.Timeout {
err := gophercloud.ErrInvalidInput{}
err.Argument = "monitors.CreateOpts.Delay/monitors.CreateOpts.Timeout"
err.Info = "Delay must be greater than or equal to timeout"
return nil, err
}
return gophercloud.BuildRequestBody(opts, "health_monitor")
}
// Create is an operation which provisions a new health monitor. There are
// different types of monitor you can provision: PING, TCP or HTTP(S). Below
// are examples of how to create each one.
//
// Here is an example config struct to use when creating a PING or TCP monitor:
//
// CreateOpts{Type: TypePING, Delay: 20, Timeout: 10, MaxRetries: 3}
// CreateOpts{Type: TypeTCP, Delay: 20, Timeout: 10, MaxRetries: 3}
//
// Here is an example config struct to use when creating a HTTP(S) monitor:
//
// CreateOpts{Type: TypeHTTP, Delay: 20, Timeout: 10, MaxRetries: 3,
// HttpMethod: "HEAD", ExpectedCodes: "200"}
//
func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToLBMonitorCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
return
}
// Get retrieves a particular health monitor based on its unique ID.
func Get(c *gophercloud.ServiceClient, id string) (r GetResult) {
_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
return
}
// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToLBMonitorUpdateMap() (map[string]interface{}, error)
}
// UpdateOpts contains all the values needed to update an existing monitor.
// Attributes not listed here but appear in CreateOpts are immutable and cannot
// be updated.
type UpdateOpts struct {
// Delay is the time, in seconds, between sending probes to members.
Delay int `json:"delay,omitempty"`
// Timeout is the maximum number of seconds for a monitor to wait for a ping
// reply before it times out. The value must be less than the delay value.
Timeout int `json:"timeout,omitempty"`
// MaxRetries is the number of permissible ping failures before changing the
// member's status to INACTIVE. Must be a number between 1 and 10.
MaxRetries int `json:"max_retries,omitempty"`
// URLPath is the URI path that will be accessed if monitor type
// is HTTP or HTTPS.
URLPath string `json:"url_path,omitempty"`
// HTTPMethod is the HTTP method used for requests by the monitor. If this
// attribute is not specified, it defaults to "GET".
HTTPMethod string `json:"http_method,omitempty"`
// ExpectedCodes is the expected HTTP codes for a passing HTTP(S) monitor
// You can either specify a single status like "200", or a range like
// "200-202".
ExpectedCodes string `json:"expected_codes,omitempty"`
// AdminStateUp denotes whether the monitor is administratively up or down.
AdminStateUp *bool `json:"admin_state_up,omitempty"`
}
// ToLBMonitorUpdateMap builds a request body from UpdateOpts.
func (opts UpdateOpts) ToLBMonitorUpdateMap() (map[string]interface{}, error) {
if opts.Delay > 0 && opts.Timeout > 0 && opts.Delay < opts.Timeout {
err := gophercloud.ErrInvalidInput{}
err.Argument = "monitors.CreateOpts.Delay/monitors.CreateOpts.Timeout"
err.Value = fmt.Sprintf("%d/%d", opts.Delay, opts.Timeout)
err.Info = "Delay must be greater than or equal to timeout"
return nil, err
}
return gophercloud.BuildRequestBody(opts, "health_monitor")
}
// Update is an operation which modifies the attributes of the specified
// monitor.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToLBMonitorUpdateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 202},
})
return
}
// Delete will permanently delete a particular monitor based on its unique ID.
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = c.Delete(resourceURL(c, id), nil)
return
}

View File

@@ -1,141 +0,0 @@
package monitors
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// Monitor represents a load balancer health monitor. A health monitor is used
// to determine whether or not back-end members of the VIP's pool are usable
// for processing a request. A pool can have several health monitors associated
// with it. There are different types of health monitors supported:
//
// PING: used to ping the members using ICMP.
// TCP: used to connect to the members using TCP.
// HTTP: used to send an HTTP request to the member.
// HTTPS: used to send a secure HTTP request to the member.
//
// When a pool has several monitors associated with it, each member of the pool
// is monitored by all these monitors. If any monitor declares the member as
// unhealthy, then the member status is changed to INACTIVE and the member
// won't participate in its pool's load balancing. In other words, ALL monitors
// must declare the member to be healthy for it to stay ACTIVE.
type Monitor struct {
// ID is the unique ID for the Monitor.
ID string
// Name is the monitor name. Does not have to be unique.
Name string
// TenantID is the owner of the Monitor.
TenantID string `json:"tenant_id"`
// Type is the type of probe sent by the load balancer to verify the member
// state, which is PING, TCP, HTTP, or HTTPS.
Type string
// Delay is the time, in seconds, between sending probes to members.
Delay int
// Timeout is the maximum number of seconds for a monitor to wait for a
// connection to be established before it times out. This value must be less
// than the delay value.
Timeout int
// MaxRetries is the number of allowed connection failures before changing the
// status of the member to INACTIVE. A valid value is from 1 to 10.
MaxRetries int `json:"max_retries"`
// HTTPMethod is the HTTP method that the monitor uses for requests.
HTTPMethod string `json:"http_method"`
// URLPath is the HTTP path of the request sent by the monitor to test the
// health of a member. Must be a string beginning with a forward slash (/).
URLPath string `json:"url_path"`
// ExpectedCodes is the expected HTTP codes for a passing HTTP(S) monitor.
ExpectedCodes string `json:"expected_codes"`
// AdminStateUp is the administrative state of the health monitor, which is up
// (true) or down (false).
AdminStateUp bool `json:"admin_state_up"`
// Status is the status of the health monitor. Indicates whether the health
// monitor is operational.
Status string
}
// MonitorPage is the page returned by a pager when traversing over a
// collection of health monitors.
type MonitorPage struct {
pagination.LinkedPageBase
}
// NextPageURL is invoked when a paginated collection of monitors has reached
// the end of a page and the pager seeks to traverse over a new one. In order
// to do this, it needs to construct the next page's URL.
func (r MonitorPage) NextPageURL() (string, error) {
var s struct {
Links []gophercloud.Link `json:"health_monitors_links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return gophercloud.ExtractNextURL(s.Links)
}
// IsEmpty checks whether a PoolPage struct is empty.
func (r MonitorPage) IsEmpty() (bool, error) {
is, err := ExtractMonitors(r)
return len(is) == 0, err
}
// ExtractMonitors accepts a Page struct, specifically a MonitorPage struct,
// and extracts the elements into a slice of Monitor structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractMonitors(r pagination.Page) ([]Monitor, error) {
var s struct {
Monitors []Monitor `json:"health_monitors"`
}
err := (r.(MonitorPage)).ExtractInto(&s)
return s.Monitors, err
}
type commonResult struct {
gophercloud.Result
}
// Extract is a function that accepts a result and extracts a monitor.
func (r commonResult) Extract() (*Monitor, error) {
var s struct {
Monitor *Monitor `json:"health_monitor"`
}
err := r.ExtractInto(&s)
return s.Monitor, err
}
// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Monitor.
type CreateResult struct {
commonResult
}
// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Monitor.
type GetResult struct {
commonResult
}
// UpdateResult represents the result of an update operation. Call its Extract
// method to interpret it as a Monitor.
type UpdateResult struct {
commonResult
}
// DeleteResult represents the result of a delete operation. Call its Extract
// method to determine if the request succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}

View File

@@ -1,16 +0,0 @@
package monitors
import "github.com/gophercloud/gophercloud"
const (
rootPath = "lb"
resourcePath = "health_monitors"
)
func rootURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL(rootPath, resourcePath)
}
func resourceURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL(rootPath, resourcePath, id)
}

View File

@@ -1,31 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"requests.go",
"results.go",
"urls.go",
],
importpath = "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/pagination:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -1,81 +0,0 @@
/*
Package pools provides information and interaction with the Pools of the
Load Balancing as a Service extension for the OpenStack Networking service.
Example to List Pools
listOpts := pools.ListOpts{
SubnetID: "d9bd223b-f1a9-4f98-953b-df977b0f902d",
}
allPages, err := pools.List(networkClient, listOpts).AllPages()
if err != nil {
panic(err)
}
allPools, err := pools.ExtractPools(allPages)
if err != nil {
panic(err)
}
for _, pool := range allPools {
fmt.Printf("%+v\n", pool)
}
Example to Create a Pool
createOpts := pools.CreateOpts{
LBMethod: pools.LBMethodRoundRobin,
Protocol: "HTTP",
Name: "Example pool",
SubnetID: "1981f108-3c48-48d2-b908-30f7d28532c9",
Provider: "haproxy",
}
pool, err := pools.Create(networkClient, createOpts).Extract()
if err != nil {
panic(err)
}
Example to Update a Pool
poolID := "166db5e6-c72a-4d77-8776-3573e27ae271"
updateOpts := pools.UpdateOpts{
LBMethod: pools.LBMethodLeastConnections,
}
pool, err := pools.Update(networkClient, poolID, updateOpts).Extract()
if err != nil {
panic(err)
}
Example to Delete a Pool
poolID := "166db5e6-c72a-4d77-8776-3573e27ae271"
err := pools.Delete(networkClient, poolID).ExtractErr()
if err != nil {
panic(err)
}
Example to Associate a Monitor to a Pool
poolID := "166db5e6-c72a-4d77-8776-3573e27ae271"
monitorID := "8bbfbe1c-6faa-4d97-abdb-0df6c90df70b"
pool, err := pools.AssociateMonitor(networkClient, poolID, monitorID).Extract()
if err != nil {
panic(err)
}
Example to Disassociate a Monitor from a Pool
poolID := "166db5e6-c72a-4d77-8776-3573e27ae271"
monitorID := "8bbfbe1c-6faa-4d97-abdb-0df6c90df70b"
pool, err := pools.DisassociateMonitor(networkClient, poolID, monitorID).Extract()
if err != nil {
panic(err)
}
*/
package pools

View File

@@ -1,175 +0,0 @@
package pools
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Filtering is achieved by passing in struct field values that map to
// the floating IP attributes you want to see returned. SortKey allows you to
// sort by a particular network attribute. SortDir sets the direction, and is
// either `asc' or `desc'. Marker and Limit are used for pagination.
type ListOpts struct {
Status string `q:"status"`
LBMethod string `q:"lb_method"`
Protocol string `q:"protocol"`
SubnetID string `q:"subnet_id"`
TenantID string `q:"tenant_id"`
AdminStateUp *bool `q:"admin_state_up"`
Name string `q:"name"`
ID string `q:"id"`
VIPID string `q:"vip_id"`
Limit int `q:"limit"`
Marker string `q:"marker"`
SortKey string `q:"sort_key"`
SortDir string `q:"sort_dir"`
}
// List returns a Pager which allows you to iterate over a collection of
// pools. It accepts a ListOpts struct, which allows you to filter and sort
// the returned collection for greater efficiency.
//
// Default policy settings return only those pools that are owned by the
// tenant who submits the request, unless an admin user submits the request.
func List(c *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
q, err := gophercloud.BuildQueryString(&opts)
if err != nil {
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
return PoolPage{pagination.LinkedPageBase{PageResult: r}}
})
}
// LBMethod is a type used for possible load balancing methods.
type LBMethod string
// LBProtocol is a type used for possible load balancing protocols.
type LBProtocol string
// Supported attributes for create/update operations.
const (
LBMethodRoundRobin LBMethod = "ROUND_ROBIN"
LBMethodLeastConnections LBMethod = "LEAST_CONNECTIONS"
ProtocolTCP LBProtocol = "TCP"
ProtocolHTTP LBProtocol = "HTTP"
ProtocolHTTPS LBProtocol = "HTTPS"
)
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToLBPoolCreateMap() (map[string]interface{}, error)
}
// CreateOpts contains all the values needed to create a new pool.
type CreateOpts struct {
// Name of the pool.
Name string `json:"name" required:"true"`
// Protocol used by the pool members, you can use either
// ProtocolTCP, ProtocolHTTP, or ProtocolHTTPS.
Protocol LBProtocol `json:"protocol" required:"true"`
// TenantID is only required if the caller has an admin role and wants
// to create a pool for another tenant.
TenantID string `json:"tenant_id,omitempty"`
// SubnetID is the network on which the members of the pool will be located.
// Only members that are on this network can be added to the pool.
SubnetID string `json:"subnet_id,omitempty"`
// LBMethod is the algorithm used to distribute load between the members of
// the pool. The current specification supports LBMethodRoundRobin and
// LBMethodLeastConnections as valid values for this attribute.
LBMethod LBMethod `json:"lb_method" required:"true"`
// Provider of the pool.
Provider string `json:"provider,omitempty"`
}
// ToLBPoolCreateMap builds a request body based on CreateOpts.
func (opts CreateOpts) ToLBPoolCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "pool")
}
// Create accepts a CreateOptsBuilder and uses the values to create a new
// load balancer pool.
func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToLBPoolCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
return
}
// Get retrieves a particular pool based on its unique ID.
func Get(c *gophercloud.ServiceClient, id string) (r GetResult) {
_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
return
}
// UpdateOptsBuilder allows extensions to add additional parameters ot the
// Update request.
type UpdateOptsBuilder interface {
ToLBPoolUpdateMap() (map[string]interface{}, error)
}
// UpdateOpts contains the values used when updating a pool.
type UpdateOpts struct {
// Name of the pool.
Name string `json:"name,omitempty"`
// LBMethod is the algorithm used to distribute load between the members of
// the pool. The current specification supports LBMethodRoundRobin and
// LBMethodLeastConnections as valid values for this attribute.
LBMethod LBMethod `json:"lb_method,omitempty"`
}
// ToLBPoolUpdateMap builds a request body based on UpdateOpts.
func (opts UpdateOpts) ToLBPoolUpdateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "pool")
}
// Update allows pools to be updated.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToLBPoolUpdateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return
}
// Delete will permanently delete a particular pool based on its unique ID.
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = c.Delete(resourceURL(c, id), nil)
return
}
// AssociateMonitor will associate a health monitor with a particular pool.
// Once associated, the health monitor will start monitoring the members of the
// pool and will deactivate these members if they are deemed unhealthy. A
// member can be deactivated (status set to INACTIVE) if any of health monitors
// finds it unhealthy.
func AssociateMonitor(c *gophercloud.ServiceClient, poolID, monitorID string) (r AssociateResult) {
b := map[string]interface{}{"health_monitor": map[string]string{"id": monitorID}}
_, r.Err = c.Post(associateURL(c, poolID), b, &r.Body, nil)
return
}
// DisassociateMonitor will disassociate a health monitor with a particular
// pool. When dissociation is successful, the health monitor will no longer
// check for the health of the members of the pool.
func DisassociateMonitor(c *gophercloud.ServiceClient, poolID, monitorID string) (r AssociateResult) {
_, r.Err = c.Delete(disassociateURL(c, poolID, monitorID), nil)
return
}

View File

@@ -1,137 +0,0 @@
package pools
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// Pool represents a logical set of devices, such as web servers, that you
// group together to receive and process traffic. The load balancing function
// chooses a member of the pool according to the configured load balancing
// method to handle the new requests or connections received on the VIP address.
// There is only one pool per virtual IP.
type Pool struct {
// Status of the pool. Indicates whether the pool is operational.
Status string
// LBMethod is the load-balancer algorithm, which is round-robin,
// least-connections, and so on. This value, which must be supported, is
// dependent on the provider.
LBMethod string `json:"lb_method"`
// Protocol of the pool, which is TCP, HTTP, or HTTPS.
Protocol string
// Description for the pool.
Description string
// MonitorIDs are the IDs of associated monitors which check the health of
// the pool members.
MonitorIDs []string `json:"health_monitors"`
// SubnetID is the network on which the members of the pool will be located.
// Only members that are on this network can be added to the pool.
SubnetID string `json:"subnet_id"`
// TenantID is the owner of the pool.
TenantID string `json:"tenant_id"`
// AdminStateUp is the administrative state of the pool, which is up
// (true) or down (false).
AdminStateUp bool `json:"admin_state_up"`
// Name of the pool.
Name string
// MemberIDs is the list of member IDs that belong to the pool.
MemberIDs []string `json:"members"`
// ID is the unique ID for the pool.
ID string
// VIPID is the ID of the virtual IP associated with this pool.
VIPID string `json:"vip_id"`
// The provider.
Provider string
}
// PoolPage is the page returned by a pager when traversing over a
// collection of pools.
type PoolPage struct {
pagination.LinkedPageBase
}
// NextPageURL is invoked when a paginated collection of pools has reached
// the end of a page and the pager seeks to traverse over a new one. In order
// to do this, it needs to construct the next page's URL.
func (r PoolPage) NextPageURL() (string, error) {
var s struct {
Links []gophercloud.Link `json:"pools_links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return gophercloud.ExtractNextURL(s.Links)
}
// IsEmpty checks whether a PoolPage struct is empty.
func (r PoolPage) IsEmpty() (bool, error) {
is, err := ExtractPools(r)
return len(is) == 0, err
}
// ExtractPools accepts a Page struct, specifically a PoolPage struct,
// and extracts the elements into a slice of Router structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractPools(r pagination.Page) ([]Pool, error) {
var s struct {
Pools []Pool `json:"pools"`
}
err := (r.(PoolPage)).ExtractInto(&s)
return s.Pools, err
}
type commonResult struct {
gophercloud.Result
}
// Extract is a function that accepts a result and extracts a router.
func (r commonResult) Extract() (*Pool, error) {
var s struct {
Pool *Pool `json:"pool"`
}
err := r.ExtractInto(&s)
return s.Pool, err
}
// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Pool.
type CreateResult struct {
commonResult
}
// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Pool.
type GetResult struct {
commonResult
}
// UpdateResult represents the result of an update operation. Call its Extract
// method to interpret it as a Pool.
type UpdateResult struct {
commonResult
}
// DeleteResult represents the result of a delete operation. Call its
// ExtractErr method to interpret it as a Pool.
type DeleteResult struct {
gophercloud.ErrResult
}
// AssociateResult represents the result of an association operation. Call its Extract
// method to interpret it as a Pool.
type AssociateResult struct {
commonResult
}

View File

@@ -1,25 +0,0 @@
package pools
import "github.com/gophercloud/gophercloud"
const (
rootPath = "lb"
resourcePath = "pools"
monitorPath = "health_monitors"
)
func rootURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL(rootPath, resourcePath)
}
func resourceURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL(rootPath, resourcePath, id)
}
func associateURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL(rootPath, resourcePath, id, monitorPath)
}
func disassociateURL(c *gophercloud.ServiceClient, poolID, monitorID string) string {
return c.ServiceURL(rootPath, resourcePath, poolID, monitorPath, monitorID)
}

View File

@@ -1,31 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"requests.go",
"results.go",
"urls.go",
],
importpath = "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/pagination:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -1,65 +0,0 @@
/*
Package vips provides information and interaction with the Virtual IPs of the
Load Balancing as a Service extension for the OpenStack Networking service.
Example to List Virtual IPs
listOpts := vips.ListOpts{
SubnetID: "d9bd223b-f1a9-4f98-953b-df977b0f902d",
}
allPages, err := vips.List(networkClient, listOpts).AllPages()
if err != nil {
panic(err)
}
allVIPs, err := vips.ExtractVIPs(allPages)
if err != nil {
panic(err)
}
for _, vip := range allVIPs {
fmt.Printf("%+v\n", vip)
}
Example to Create a Virtual IP
createOpts := vips.CreateOpts{
Protocol: "HTTP",
Name: "NewVip",
AdminStateUp: gophercloud.Enabled,
SubnetID: "8032909d-47a1-4715-90af-5153ffe39861",
PoolID: "61b1f87a-7a21-4ad3-9dda-7f81d249944f",
ProtocolPort: 80,
Persistence: &vips.SessionPersistence{Type: "SOURCE_IP"},
}
vip, err := vips.Create(networkClient, createOpts).Extract()
if err != nil {
panic(err)
}
Example to Update a Virtual IP
vipID := "93f1bad4-0423-40a8-afac-3fc541839912"
i1000 := 1000
updateOpts := vips.UpdateOpts{
ConnLimit: &i1000,
Persistence: &vips.SessionPersistence{Type: "SOURCE_IP"},
}
vip, err := vips.Update(networkClient, vipID, updateOpts).Extract()
if err != nil {
panic(err)
}
Example to Delete a Virtual IP
vipID := "93f1bad4-0423-40a8-afac-3fc541839912"
err := vips.Delete(networkClient, vipID).ExtractErr()
if err != nil {
panic(err)
}
*/
package vips

View File

@@ -1,180 +0,0 @@
package vips
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Filtering is achieved by passing in struct field values that map to
// the floating IP attributes you want to see returned. SortKey allows you to
// sort by a particular network attribute. SortDir sets the direction, and is
// either `asc' or `desc'. Marker and Limit are used for pagination.
type ListOpts struct {
ID string `q:"id"`
Name string `q:"name"`
AdminStateUp *bool `q:"admin_state_up"`
Status string `q:"status"`
TenantID string `q:"tenant_id"`
SubnetID string `q:"subnet_id"`
Address string `q:"address"`
PortID string `q:"port_id"`
Protocol string `q:"protocol"`
ProtocolPort int `q:"protocol_port"`
ConnectionLimit int `q:"connection_limit"`
Limit int `q:"limit"`
Marker string `q:"marker"`
SortKey string `q:"sort_key"`
SortDir string `q:"sort_dir"`
}
// List returns a Pager which allows you to iterate over a collection of
// Virtual IPs. It accepts a ListOpts struct, which allows you to filter and
// sort the returned collection for greater efficiency.
//
// Default policy settings return only those virtual IPs that are owned by the
// tenant who submits the request, unless an admin user submits the request.
func List(c *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
q, err := gophercloud.BuildQueryString(&opts)
if err != nil {
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
return VIPPage{pagination.LinkedPageBase{PageResult: r}}
})
}
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create Request.
type CreateOptsBuilder interface {
ToVIPCreateMap() (map[string]interface{}, error)
}
// CreateOpts contains all the values needed to create a new virtual IP.
type CreateOpts struct {
// Name is the human-readable name for the VIP. Does not have to be unique.
Name string `json:"name" required:"true"`
// SubnetID is the network on which to allocate the VIP's address. A tenant
// can only create VIPs on networks authorized by policy (e.g. networks that
// belong to them or networks that are shared).
SubnetID string `json:"subnet_id" required:"true"`
// Protocol - can either be TCP, HTTP or HTTPS.
Protocol string `json:"protocol" required:"true"`
// ProtocolPort is the port on which to listen for client traffic.
ProtocolPort int `json:"protocol_port" required:"true"`
// PoolID is the ID of the pool with which the VIP is associated.
PoolID string `json:"pool_id" required:"true"`
// TenantID is only required if the caller has an admin role and wants
// to create a pool for another tenant.
TenantID string `json:"tenant_id,omitempty"`
// Address is the IP address of the VIP.
Address string `json:"address,omitempty"`
// Description is the human-readable description for the VIP.
Description string `json:"description,omitempty"`
// Persistence is the the of session persistence to use.
// Omit this field to prevent session persistence.
Persistence *SessionPersistence `json:"session_persistence,omitempty"`
// ConnLimit is the maximum number of connections allowed for the VIP.
ConnLimit *int `json:"connection_limit,omitempty"`
// AdminStateUp is the administrative state of the VIP. A valid value is
// true (UP) or false (DOWN).
AdminStateUp *bool `json:"admin_state_up,omitempty"`
}
// ToVIPCreateMap builds a request body from CreateOpts.
func (opts CreateOpts) ToVIPCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "vip")
}
// Create is an operation which provisions a new virtual IP based on the
// configuration defined in the CreateOpts struct. Once the request is
// validated and progress has started on the provisioning process, a
// CreateResult will be returned.
//
// Please note that the PoolID should refer to a pool that is not already
// associated with another vip. If the pool is already used by another vip,
// then the operation will fail with a 409 Conflict error will be returned.
//
// Users with an admin role can create VIPs on behalf of other tenants by
// specifying a TenantID attribute different than their own.
func Create(c *gophercloud.ServiceClient, opts CreateOpts) (r CreateResult) {
b, err := opts.ToVIPCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
return
}
// Get retrieves a particular virtual IP based on its unique ID.
func Get(c *gophercloud.ServiceClient, id string) (r GetResult) {
_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
return
}
// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToVIPUpdateMap() (map[string]interface{}, error)
}
// UpdateOpts contains all the values needed to update an existing virtual IP.
// Attributes not listed here but appear in CreateOpts are immutable and cannot
// be updated.
type UpdateOpts struct {
// Name is the human-readable name for the VIP. Does not have to be unique.
Name *string `json:"name,omitempty"`
// PoolID is the ID of the pool with which the VIP is associated.
PoolID *string `json:"pool_id,omitempty"`
// Description is the human-readable description for the VIP.
Description *string `json:"description,omitempty"`
// Persistence is the the of session persistence to use.
// Omit this field to prevent session persistence.
Persistence *SessionPersistence `json:"session_persistence,omitempty"`
// ConnLimit is the maximum number of connections allowed for the VIP.
ConnLimit *int `json:"connection_limit,omitempty"`
// AdminStateUp is the administrative state of the VIP. A valid value is
// true (UP) or false (DOWN).
AdminStateUp *bool `json:"admin_state_up,omitempty"`
}
// ToVIPUpdateMap builds a request body based on UpdateOpts.
func (opts UpdateOpts) ToVIPUpdateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "vip")
}
// Update is an operation which modifies the attributes of the specified VIP.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToVIPUpdateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 202},
})
return
}
// Delete will permanently delete a particular virtual IP based on its unique ID.
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = c.Delete(resourceURL(c, id), nil)
return
}

View File

@@ -1,156 +0,0 @@
package vips
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// SessionPersistence represents the session persistence feature of the load
// balancing service. It attempts to force connections or requests in the same
// session to be processed by the same member as long as it is ative. Three
// types of persistence are supported:
//
// SOURCE_IP: With this mode, all connections originating from the same source
// IP address, will be handled by the same member of the pool.
// HTTP_COOKIE: With this persistence mode, the load balancing function will
// create a cookie on the first request from a client. Subsequent
// requests containing the same cookie value will be handled by
// the same member of the pool.
// APP_COOKIE: With this persistence mode, the load balancing function will
// rely on a cookie established by the backend application. All
// requests carrying the same cookie value will be handled by the
// same member of the pool.
type SessionPersistence struct {
// Type is the type of persistence mode.
Type string `json:"type"`
// CookieName is the name of cookie if persistence mode is set appropriately.
CookieName string `json:"cookie_name,omitempty"`
}
// VirtualIP is the primary load balancing configuration object that specifies
// the virtual IP address and port on which client traffic is received, as well
// as other details such as the load balancing method to be use, protocol, etc.
// This entity is sometimes known in LB products under the name of a "virtual
// server", a "vserver" or a "listener".
type VirtualIP struct {
// ID is the unique ID for the VIP.
ID string `json:"id"`
// TenantID is the owner of the VIP.
TenantID string `json:"tenant_id"`
// Name is the human-readable name for the VIP. Does not have to be unique.
Name string `json:"name"`
// Description is the human-readable description for the VIP.
Description string `json:"description"`
// SubnetID is the ID of the subnet on which to allocate the VIP address.
SubnetID string `json:"subnet_id"`
// Address is the IP address of the VIP.
Address string `json:"address"`
// Protocol of the VIP address. A valid value is TCP, HTTP, or HTTPS.
Protocol string `json:"protocol"`
// ProtocolPort is the port on which to listen to client traffic that is
// associated with the VIP address. A valid value is from 0 to 65535.
ProtocolPort int `json:"protocol_port"`
// PoolID is the ID of the pool with which the VIP is associated.
PoolID string `json:"pool_id"`
// PortID is the ID of the port which belongs to the load balancer.
PortID string `json:"port_id"`
// Persistence indicates whether connections in the same session will be
// processed by the same pool member or not.
Persistence SessionPersistence `json:"session_persistence"`
// ConnLimit is the maximum number of connections allowed for the VIP.
// Default is -1, meaning no limit.
ConnLimit int `json:"connection_limit"`
// AdminStateUp is the administrative state of the VIP. A valid value is
// true (UP) or false (DOWN).
AdminStateUp bool `json:"admin_state_up"`
// Status is the status of the VIP. Indicates whether the VIP is operational.
Status string `json:"status"`
}
// VIPPage is the page returned by a pager when traversing over a
// collection of virtual IPs.
type VIPPage struct {
pagination.LinkedPageBase
}
// NextPageURL is invoked when a paginated collection of routers has reached
// the end of a page and the pager seeks to traverse over a new one. In order
// to do this, it needs to construct the next page's URL.
func (r VIPPage) NextPageURL() (string, error) {
var s struct {
Links []gophercloud.Link `json:"vips_links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return gophercloud.ExtractNextURL(s.Links)
}
// IsEmpty checks whether a VIPPage struct is empty.
func (r VIPPage) IsEmpty() (bool, error) {
is, err := ExtractVIPs(r)
return len(is) == 0, err
}
// ExtractVIPs accepts a Page struct, specifically a VIPPage struct,
// and extracts the elements into a slice of VirtualIP structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractVIPs(r pagination.Page) ([]VirtualIP, error) {
var s struct {
VIPs []VirtualIP `json:"vips"`
}
err := (r.(VIPPage)).ExtractInto(&s)
return s.VIPs, err
}
type commonResult struct {
gophercloud.Result
}
// Extract is a function that accepts a result and extracts a VirtualIP.
func (r commonResult) Extract() (*VirtualIP, error) {
var s struct {
VirtualIP *VirtualIP `json:"vip" json:"vip"`
}
err := r.ExtractInto(&s)
return s.VirtualIP, err
}
// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a VirtualIP
type CreateResult struct {
commonResult
}
// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a VirtualIP
type GetResult struct {
commonResult
}
// UpdateResult represents the result of an update operation. Call its Extract
// method to interpret it as a VirtualIP
type UpdateResult struct {
commonResult
}
// DeleteResult represents the result of a delete operation. Call its
// ExtractErr method to determine if the request succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}

View File

@@ -1,16 +0,0 @@
package vips
import "github.com/gophercloud/gophercloud"
const (
rootPath = "lb"
resourcePath = "vips"
)
func rootURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL(rootPath, resourcePath)
}
func resourceURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL(rootPath, resourcePath, id)
}