github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/results.go (about) 1 package loadbalancers 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/openstack/networking/v2/extensions/lbaas_v2/listeners" 6 "github.com/huaweicloud/golangsdk/openstack/networking/v2/extensions/lbaas_v2/pools" 7 "github.com/huaweicloud/golangsdk/pagination" 8 ) 9 10 // LoadBalancer is the primary load balancing configuration object that 11 // specifies the virtual IP address on which client traffic is received, as well 12 // as other details such as the load balancing method to be use, protocol, etc. 13 type LoadBalancer struct { 14 // Human-readable description for the Loadbalancer. 15 Description string `json:"description"` 16 17 // The administrative state of the Loadbalancer. 18 // A valid value is true (UP) or false (DOWN). 19 AdminStateUp bool `json:"admin_state_up"` 20 21 // Owner of the LoadBalancer. 22 TenantID string `json:"tenant_id"` 23 24 // The provisioning status of the LoadBalancer. 25 // This value is ACTIVE, PENDING_CREATE or ERROR. 26 ProvisioningStatus string `json:"provisioning_status"` 27 28 // The IP address of the Loadbalancer. 29 VipAddress string `json:"vip_address"` 30 31 // The UUID of the port associated with the IP address. 32 VipPortID string `json:"vip_port_id"` 33 34 // The UUID of the subnet on which to allocate the virtual IP for the 35 // Loadbalancer address. 36 VipSubnetID string `json:"vip_subnet_id"` 37 38 // The unique ID for the LoadBalancer. 39 ID string `json:"id"` 40 41 // The operating status of the LoadBalancer. This value is ONLINE or OFFLINE. 42 OperatingStatus string `json:"operating_status"` 43 44 // Human-readable name for the LoadBalancer. Does not have to be unique. 45 Name string `json:"name"` 46 47 // The UUID of a flavor if set. 48 Flavor string `json:"flavor"` 49 50 // The name of the provider. 51 Provider string `json:"provider"` 52 53 // Listeners are the listeners related to this Loadbalancer. 54 Listeners []listeners.Listener `json:"listeners"` 55 56 // Pools are the pools related to this Loadbalancer. 57 Pools []pools.Pool `json:"pools"` 58 } 59 60 // StatusTree represents the status of a loadbalancer. 61 type StatusTree struct { 62 Loadbalancer *LoadBalancer `json:"loadbalancer"` 63 } 64 65 // LoadBalancerPage is the page returned by a pager when traversing over a 66 // collection of load balancers. 67 type LoadBalancerPage struct { 68 pagination.LinkedPageBase 69 } 70 71 // NextPageURL is invoked when a paginated collection of load balancers has 72 // reached the end of a page and the pager seeks to traverse over a new one. 73 // In order to do this, it needs to construct the next page's URL. 74 func (r LoadBalancerPage) NextPageURL() (string, error) { 75 var s struct { 76 Links []golangsdk.Link `json:"loadbalancers_links"` 77 } 78 err := r.ExtractInto(&s) 79 if err != nil { 80 return "", err 81 } 82 return golangsdk.ExtractNextURL(s.Links) 83 } 84 85 // IsEmpty checks whether a LoadBalancerPage struct is empty. 86 func (r LoadBalancerPage) IsEmpty() (bool, error) { 87 is, err := ExtractLoadBalancers(r) 88 return len(is) == 0, err 89 } 90 91 // ExtractLoadBalancers accepts a Page struct, specifically a LoadbalancerPage 92 // struct, and extracts the elements into a slice of LoadBalancer structs. In 93 // other words, a generic collection is mapped into a relevant slice. 94 func ExtractLoadBalancers(r pagination.Page) ([]LoadBalancer, error) { 95 var s struct { 96 LoadBalancers []LoadBalancer `json:"loadbalancers"` 97 } 98 err := (r.(LoadBalancerPage)).ExtractInto(&s) 99 return s.LoadBalancers, err 100 } 101 102 type commonResult struct { 103 golangsdk.Result 104 } 105 106 // Extract is a function that accepts a result and extracts a loadbalancer. 107 func (r commonResult) Extract() (*LoadBalancer, error) { 108 var s struct { 109 LoadBalancer *LoadBalancer `json:"loadbalancer"` 110 } 111 err := r.ExtractInto(&s) 112 return s.LoadBalancer, err 113 } 114 115 // GetStatusesResult represents the result of a GetStatuses operation. 116 // Call its Extract method to interpret it as a StatusTree. 117 type GetStatusesResult struct { 118 golangsdk.Result 119 } 120 121 // Extract is a function that accepts a result and extracts the status of 122 // a Loadbalancer. 123 func (r GetStatusesResult) Extract() (*StatusTree, error) { 124 var s struct { 125 Statuses *StatusTree `json:"statuses"` 126 } 127 err := r.ExtractInto(&s) 128 return s.Statuses, err 129 } 130 131 // CreateResult represents the result of a create operation. Call its Extract 132 // method to interpret it as a LoadBalancer. 133 type CreateResult struct { 134 commonResult 135 } 136 137 // GetResult represents the result of a get operation. Call its Extract 138 // method to interpret it as a LoadBalancer. 139 type GetResult struct { 140 commonResult 141 } 142 143 // UpdateResult represents the result of an update operation. Call its Extract 144 // method to interpret it as a LoadBalancer. 145 type UpdateResult struct { 146 commonResult 147 } 148 149 // DeleteResult represents the result of a delete operation. Call its 150 // ExtractErr method to determine if the request succeeded or failed. 151 type DeleteResult struct { 152 golangsdk.ErrResult 153 }