github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/elb/v2/loadbalancers/results.go (about)

     1  package loadbalancers
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/openstack/elb/v2/listeners"
     6  	"github.com/chnsz/golangsdk/openstack/elb/v2/pools"
     7  	"github.com/chnsz/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  	// The public ip of the loadbalancer.
    63  	PublicIps []PublicIp `json:"publicips"`
    64  
    65  	// Update protection status
    66  	ProtectionStatus string `json:"protection_status"`
    67  
    68  	// Update protection reason
    69  	ProtectionReason string `json:"protection_reason"`
    70  
    71  	// Billing info
    72  	BillingInfo string `json:"billing_info"`
    73  
    74  	// Charge mode
    75  	ChargeMode string `json:"charge_mode"`
    76  
    77  	// Frozen scene
    78  	FrozenScene string `json:"frozen_scene"`
    79  
    80  	// The create time.
    81  	CreatedAt string `json:"created_at"`
    82  
    83  	// The update time.
    84  	UpdatedAt string `json:"updated_at"`
    85  }
    86  
    87  type PublicIp struct {
    88  	// The ID of the public ip.
    89  	PublicIpId string `json:"publicip_id"`
    90  
    91  	// The IP address of the public IP.
    92  	PublicIpAddress string `json:"publicip_address"`
    93  
    94  	// The version of the IP.
    95  	IpVersion int `json:"ip_version"`
    96  }
    97  
    98  // StatusTree represents the status of a loadbalancer.
    99  type StatusTree struct {
   100  	Loadbalancer *LoadBalancer `json:"loadbalancer"`
   101  }
   102  
   103  // LoadBalancerPage is the page returned by a pager when traversing over a
   104  // collection of load balancers.
   105  type LoadBalancerPage struct {
   106  	pagination.LinkedPageBase
   107  }
   108  
   109  // NextPageURL is invoked when a paginated collection of load balancers has
   110  // reached the end of a page and the pager seeks to traverse over a new one.
   111  // In order to do this, it needs to construct the next page's URL.
   112  func (r LoadBalancerPage) NextPageURL() (string, error) {
   113  	var s struct {
   114  		Links []golangsdk.Link `json:"loadbalancers_links"`
   115  	}
   116  	err := r.ExtractInto(&s)
   117  	if err != nil {
   118  		return "", err
   119  	}
   120  	return golangsdk.ExtractNextURL(s.Links)
   121  }
   122  
   123  // IsEmpty checks whether a LoadBalancerPage struct is empty.
   124  func (r LoadBalancerPage) IsEmpty() (bool, error) {
   125  	is, err := ExtractLoadBalancers(r)
   126  	return len(is) == 0, err
   127  }
   128  
   129  // ExtractLoadBalancers accepts a Page struct, specifically a LoadbalancerPage
   130  // struct, and extracts the elements into a slice of LoadBalancer structs. In
   131  // other words, a generic collection is mapped into a relevant slice.
   132  func ExtractLoadBalancers(r pagination.Page) ([]LoadBalancer, error) {
   133  	var s struct {
   134  		LoadBalancers []LoadBalancer `json:"loadbalancers"`
   135  	}
   136  	err := (r.(LoadBalancerPage)).ExtractInto(&s)
   137  	return s.LoadBalancers, err
   138  }
   139  
   140  type commonResult struct {
   141  	golangsdk.Result
   142  }
   143  
   144  // Extract is a function that accepts a result and extracts a loadbalancer.
   145  func (r commonResult) Extract() (*LoadBalancer, error) {
   146  	var s struct {
   147  		LoadBalancer *LoadBalancer `json:"loadbalancer"`
   148  	}
   149  	err := r.ExtractInto(&s)
   150  	return s.LoadBalancer, err
   151  }
   152  
   153  // GetStatusesResult represents the result of a GetStatuses operation.
   154  // Call its Extract method to interpret it as a StatusTree.
   155  type GetStatusesResult struct {
   156  	golangsdk.Result
   157  }
   158  
   159  // Extract is a function that accepts a result and extracts the status of
   160  // a Loadbalancer.
   161  func (r GetStatusesResult) Extract() (*StatusTree, error) {
   162  	var s struct {
   163  		Statuses *StatusTree `json:"statuses"`
   164  	}
   165  	err := r.ExtractInto(&s)
   166  	return s.Statuses, err
   167  }
   168  
   169  // CreateResult represents the result of a create operation. Call its Extract
   170  // method to interpret it as a LoadBalancer.
   171  type CreateResult struct {
   172  	commonResult
   173  }
   174  
   175  // GetResult represents the result of a get operation. Call its Extract
   176  // method to interpret it as a LoadBalancer.
   177  type GetResult struct {
   178  	commonResult
   179  }
   180  
   181  // UpdateResult represents the result of an update operation. Call its Extract
   182  // method to interpret it as a LoadBalancer.
   183  type UpdateResult struct {
   184  	commonResult
   185  }
   186  
   187  // DeleteResult represents the result of a delete operation. Call its
   188  // ExtractErr method to determine if the request succeeded or failed.
   189  type DeleteResult struct {
   190  	golangsdk.ErrResult
   191  }