github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/lbaas/vips/results.go (about) 1 package vips 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // SessionPersistence represents the session persistence feature of the load 9 // balancing service. It attempts to force connections or requests in the same 10 // session to be processed by the same member as long as it is ative. Three 11 // types of persistence are supported: 12 // 13 // SOURCE_IP: With this mode, all connections originating from the same source 14 // 15 // IP address, will be handled by the same member of the pool. 16 // 17 // HTTP_COOKIE: With this persistence mode, the load balancing function will 18 // 19 // create a cookie on the first request from a client. Subsequent 20 // requests containing the same cookie value will be handled by 21 // the same member of the pool. 22 // 23 // APP_COOKIE: With this persistence mode, the load balancing function will 24 // 25 // rely on a cookie established by the backend application. All 26 // requests carrying the same cookie value will be handled by the 27 // same member of the pool. 28 type SessionPersistence struct { 29 // Type is the type of persistence mode. 30 Type string `json:"type"` 31 32 // CookieName is the name of cookie if persistence mode is set appropriately. 33 CookieName string `json:"cookie_name,omitempty"` 34 } 35 36 // VirtualIP is the primary load balancing configuration object that specifies 37 // the virtual IP address and port on which client traffic is received, as well 38 // as other details such as the load balancing method to be use, protocol, etc. 39 // This entity is sometimes known in LB products under the name of a "virtual 40 // server", a "vserver" or a "listener". 41 type VirtualIP struct { 42 // ID is the unique ID for the VIP. 43 ID string `json:"id"` 44 45 // TenantID is the owner of the VIP. 46 TenantID string `json:"tenant_id"` 47 48 // Name is the human-readable name for the VIP. Does not have to be unique. 49 Name string `json:"name"` 50 51 // Description is the human-readable description for the VIP. 52 Description string `json:"description"` 53 54 // SubnetID is the ID of the subnet on which to allocate the VIP address. 55 SubnetID string `json:"subnet_id"` 56 57 // Address is the IP address of the VIP. 58 Address string `json:"address"` 59 60 // Protocol of the VIP address. A valid value is TCP, HTTP, or HTTPS. 61 Protocol string `json:"protocol"` 62 63 // ProtocolPort is the port on which to listen to client traffic that is 64 // associated with the VIP address. A valid value is from 0 to 65535. 65 ProtocolPort int `json:"protocol_port"` 66 67 // PoolID is the ID of the pool with which the VIP is associated. 68 PoolID string `json:"pool_id"` 69 70 // PortID is the ID of the port which belongs to the load balancer. 71 PortID string `json:"port_id"` 72 73 // Persistence indicates whether connections in the same session will be 74 // processed by the same pool member or not. 75 Persistence SessionPersistence `json:"session_persistence"` 76 77 // ConnLimit is the maximum number of connections allowed for the VIP. 78 // Default is -1, meaning no limit. 79 ConnLimit int `json:"connection_limit"` 80 81 // AdminStateUp is the administrative state of the VIP. A valid value is 82 // true (UP) or false (DOWN). 83 AdminStateUp bool `json:"admin_state_up"` 84 85 // Status is the status of the VIP. Indicates whether the VIP is operational. 86 Status string `json:"status"` 87 } 88 89 // VIPPage is the page returned by a pager when traversing over a 90 // collection of virtual IPs. 91 type VIPPage struct { 92 pagination.LinkedPageBase 93 } 94 95 // NextPageURL is invoked when a paginated collection of routers has reached 96 // the end of a page and the pager seeks to traverse over a new one. In order 97 // to do this, it needs to construct the next page's URL. 98 func (r VIPPage) NextPageURL() (string, error) { 99 var s struct { 100 Links []gophercloud.Link `json:"vips_links"` 101 } 102 err := r.ExtractInto(&s) 103 if err != nil { 104 return "", err 105 } 106 return gophercloud.ExtractNextURL(s.Links) 107 } 108 109 // IsEmpty checks whether a VIPPage struct is empty. 110 func (r VIPPage) IsEmpty() (bool, error) { 111 if r.StatusCode == 204 { 112 return true, nil 113 } 114 115 is, err := ExtractVIPs(r) 116 return len(is) == 0, err 117 } 118 119 // ExtractVIPs accepts a Page struct, specifically a VIPPage struct, 120 // and extracts the elements into a slice of VirtualIP structs. In other words, 121 // a generic collection is mapped into a relevant slice. 122 func ExtractVIPs(r pagination.Page) ([]VirtualIP, error) { 123 var s struct { 124 VIPs []VirtualIP `json:"vips"` 125 } 126 err := (r.(VIPPage)).ExtractInto(&s) 127 return s.VIPs, err 128 } 129 130 type commonResult struct { 131 gophercloud.Result 132 } 133 134 // Extract is a function that accepts a result and extracts a VirtualIP. 135 func (r commonResult) Extract() (*VirtualIP, error) { 136 var s struct { 137 VirtualIP *VirtualIP `json:"vip"` 138 } 139 err := r.ExtractInto(&s) 140 return s.VirtualIP, err 141 } 142 143 // CreateResult represents the result of a create operation. Call its Extract 144 // method to interpret it as a VirtualIP 145 type CreateResult struct { 146 commonResult 147 } 148 149 // GetResult represents the result of a get operation. Call its Extract 150 // method to interpret it as a VirtualIP 151 type GetResult struct { 152 commonResult 153 } 154 155 // UpdateResult represents the result of an update operation. Call its Extract 156 // method to interpret it as a VirtualIP 157 type UpdateResult struct { 158 commonResult 159 } 160 161 // DeleteResult represents the result of a delete operation. Call its 162 // ExtractErr method to determine if the request succeeded or failed. 163 type DeleteResult struct { 164 gophercloud.ErrResult 165 }