github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/lbaas/vips/requests.go (about) 1 package vips 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // ListOpts allows the filtering and sorting of paginated collections through 9 // the API. Filtering is achieved by passing in struct field values that map to 10 // the floating IP attributes you want to see returned. SortKey allows you to 11 // sort by a particular network attribute. SortDir sets the direction, and is 12 // either `asc' or `desc'. Marker and Limit are used for pagination. 13 type ListOpts struct { 14 ID string `q:"id"` 15 Name string `q:"name"` 16 AdminStateUp *bool `q:"admin_state_up"` 17 Status string `q:"status"` 18 TenantID string `q:"tenant_id"` 19 SubnetID string `q:"subnet_id"` 20 Address string `q:"address"` 21 PortID string `q:"port_id"` 22 Protocol string `q:"protocol"` 23 ProtocolPort int `q:"protocol_port"` 24 ConnectionLimit int `q:"connection_limit"` 25 Limit int `q:"limit"` 26 Marker string `q:"marker"` 27 SortKey string `q:"sort_key"` 28 SortDir string `q:"sort_dir"` 29 } 30 31 // List returns a Pager which allows you to iterate over a collection of 32 // Virtual IPs. It accepts a ListOpts struct, which allows you to filter and 33 // sort the returned collection for greater efficiency. 34 // 35 // Default policy settings return only those virtual IPs that are owned by the 36 // tenant who submits the request, unless an admin user submits the request. 37 func List(c *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { 38 q, err := golangsdk.BuildQueryString(&opts) 39 if err != nil { 40 return pagination.Pager{Err: err} 41 } 42 u := rootURL(c) + q.String() 43 return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page { 44 return VIPPage{pagination.LinkedPageBase{PageResult: r}} 45 }) 46 } 47 48 // CreateOptsBuilder allows extensions to add additional parameters to the 49 // Create Request. 50 type CreateOptsBuilder interface { 51 ToVIPCreateMap() (map[string]interface{}, error) 52 } 53 54 // CreateOpts contains all the values needed to create a new virtual IP. 55 type CreateOpts struct { 56 // Name is the human-readable name for the VIP. Does not have to be unique. 57 Name string `json:"name" required:"true"` 58 59 // SubnetID is the network on which to allocate the VIP's address. A tenant 60 // can only create VIPs on networks authorized by policy (e.g. networks that 61 // belong to them or networks that are shared). 62 SubnetID string `json:"subnet_id" required:"true"` 63 64 // Protocol - can either be TCP, HTTP or HTTPS. 65 Protocol string `json:"protocol" required:"true"` 66 67 // ProtocolPort is the port on which to listen for client traffic. 68 ProtocolPort int `json:"protocol_port" required:"true"` 69 70 // PoolID is the ID of the pool with which the VIP is associated. 71 PoolID string `json:"pool_id" required:"true"` 72 73 // TenantID is only required if the caller has an admin role and wants 74 // to create a pool for another tenant. 75 TenantID string `json:"tenant_id,omitempty"` 76 77 // Address is the IP address of the VIP. 78 Address string `json:"address,omitempty"` 79 80 // Description is the human-readable description for the VIP. 81 Description string `json:"description,omitempty"` 82 83 // Persistence is the the of session persistence to use. 84 // Omit this field to prevent session persistence. 85 Persistence *SessionPersistence `json:"session_persistence,omitempty"` 86 87 // ConnLimit is the maximum number of connections allowed for the VIP. 88 ConnLimit *int `json:"connection_limit,omitempty"` 89 90 // AdminStateUp is the administrative state of the VIP. A valid value is 91 // true (UP) or false (DOWN). 92 AdminStateUp *bool `json:"admin_state_up,omitempty"` 93 } 94 95 // ToVIPCreateMap builds a request body from CreateOpts. 96 func (opts CreateOpts) ToVIPCreateMap() (map[string]interface{}, error) { 97 return golangsdk.BuildRequestBody(opts, "vip") 98 } 99 100 // Create is an operation which provisions a new virtual IP based on the 101 // configuration defined in the CreateOpts struct. Once the request is 102 // validated and progress has started on the provisioning process, a 103 // CreateResult will be returned. 104 // 105 // Please note that the PoolID should refer to a pool that is not already 106 // associated with another vip. If the pool is already used by another vip, 107 // then the operation will fail with a 409 Conflict error will be returned. 108 // 109 // Users with an admin role can create VIPs on behalf of other tenants by 110 // specifying a TenantID attribute different than their own. 111 func Create(c *golangsdk.ServiceClient, opts CreateOpts) (r CreateResult) { 112 b, err := opts.ToVIPCreateMap() 113 if err != nil { 114 r.Err = err 115 return 116 } 117 _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) 118 return 119 } 120 121 // Get retrieves a particular virtual IP based on its unique ID. 122 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 123 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 124 return 125 } 126 127 // UpdateOptsBuilder allows extensions to add additional parameters to the 128 // Update request. 129 type UpdateOptsBuilder interface { 130 ToVIPUpdateMap() (map[string]interface{}, error) 131 } 132 133 // UpdateOpts contains all the values needed to update an existing virtual IP. 134 // Attributes not listed here but appear in CreateOpts are immutable and cannot 135 // be updated. 136 type UpdateOpts struct { 137 // Name is the human-readable name for the VIP. Does not have to be unique. 138 Name *string `json:"name,omitempty"` 139 140 // PoolID is the ID of the pool with which the VIP is associated. 141 PoolID *string `json:"pool_id,omitempty"` 142 143 // Description is the human-readable description for the VIP. 144 Description *string `json:"description,omitempty"` 145 146 // Persistence is the the of session persistence to use. 147 // Omit this field to prevent session persistence. 148 Persistence *SessionPersistence `json:"session_persistence,omitempty"` 149 150 // ConnLimit is the maximum number of connections allowed for the VIP. 151 ConnLimit *int `json:"connection_limit,omitempty"` 152 153 // AdminStateUp is the administrative state of the VIP. A valid value is 154 // true (UP) or false (DOWN). 155 AdminStateUp *bool `json:"admin_state_up,omitempty"` 156 } 157 158 // ToVIPUpdateMap builds a request body based on UpdateOpts. 159 func (opts UpdateOpts) ToVIPUpdateMap() (map[string]interface{}, error) { 160 return golangsdk.BuildRequestBody(opts, "vip") 161 } 162 163 // Update is an operation which modifies the attributes of the specified VIP. 164 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 165 b, err := opts.ToVIPUpdateMap() 166 if err != nil { 167 r.Err = err 168 return 169 } 170 _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ 171 OkCodes: []int{200, 202}, 172 }) 173 return 174 } 175 176 // Delete will permanently delete a particular virtual IP based on its unique ID. 177 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 178 _, r.Err = c.Delete(resourceURL(c, id), nil) 179 return 180 }