github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/elb/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 // Enterprise project ID 60 EnterpriseProjectID string `json:"enterprise_project_id"` 61 } 62 63 // StatusTree represents the status of a loadbalancer. 64 type StatusTree struct { 65 Loadbalancer *LoadBalancer `json:"loadbalancer"` 66 } 67 68 // LoadBalancerPage is the page returned by a pager when traversing over a 69 // collection of load balancers. 70 type LoadBalancerPage struct { 71 pagination.LinkedPageBase 72 } 73 74 // NextPageURL is invoked when a paginated collection of load balancers has 75 // reached the end of a page and the pager seeks to traverse over a new one. 76 // In order to do this, it needs to construct the next page's URL. 77 func (r LoadBalancerPage) NextPageURL() (string, error) { 78 var s struct { 79 Links []golangsdk.Link `json:"loadbalancers_links"` 80 } 81 err := r.ExtractInto(&s) 82 if err != nil { 83 return "", err 84 } 85 return golangsdk.ExtractNextURL(s.Links) 86 } 87 88 // IsEmpty checks whether a LoadBalancerPage struct is empty. 89 func (r LoadBalancerPage) IsEmpty() (bool, error) { 90 is, err := ExtractLoadBalancers(r) 91 return len(is) == 0, err 92 } 93 94 // ExtractLoadBalancers accepts a Page struct, specifically a LoadbalancerPage 95 // struct, and extracts the elements into a slice of LoadBalancer structs. In 96 // other words, a generic collection is mapped into a relevant slice. 97 func ExtractLoadBalancers(r pagination.Page) ([]LoadBalancer, error) { 98 var s struct { 99 LoadBalancers []LoadBalancer `json:"loadbalancers"` 100 } 101 err := (r.(LoadBalancerPage)).ExtractInto(&s) 102 return s.LoadBalancers, err 103 } 104 105 type commonResult struct { 106 golangsdk.Result 107 } 108 109 // Extract is a function that accepts a result and extracts a loadbalancer. 110 func (r commonResult) Extract() (*LoadBalancer, error) { 111 var s struct { 112 LoadBalancer *LoadBalancer `json:"loadbalancer"` 113 } 114 err := r.ExtractInto(&s) 115 return s.LoadBalancer, err 116 } 117 118 // GetStatusesResult represents the result of a GetStatuses operation. 119 // Call its Extract method to interpret it as a StatusTree. 120 type GetStatusesResult struct { 121 golangsdk.Result 122 } 123 124 // Extract is a function that accepts a result and extracts the status of 125 // a Loadbalancer. 126 func (r GetStatusesResult) Extract() (*StatusTree, error) { 127 var s struct { 128 Statuses *StatusTree `json:"statuses"` 129 } 130 err := r.ExtractInto(&s) 131 return s.Statuses, err 132 } 133 134 // CreateResult represents the result of a create operation. Call its Extract 135 // method to interpret it as a LoadBalancer. 136 type CreateResult struct { 137 commonResult 138 } 139 140 // GetResult represents the result of a get operation. Call its Extract 141 // method to interpret it as a LoadBalancer. 142 type GetResult struct { 143 commonResult 144 } 145 146 // UpdateResult represents the result of an update operation. Call its Extract 147 // method to interpret it as a LoadBalancer. 148 type UpdateResult struct { 149 commonResult 150 } 151 152 // DeleteResult represents the result of a delete operation. Call its 153 // ExtractErr method to determine if the request succeeded or failed. 154 type DeleteResult struct { 155 golangsdk.ErrResult 156 }