github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/elbaas/backendmember/results.go (about)

     1  package backendmember
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // Backend is the primary load balancing configuration object that specifies
     9  // the loadbalancer and port on which client traffic is received, as well
    10  // as other details such as the load balancing method to be use, protocol, etc.
    11  type Backend struct {
    12  	// Specifies the private IP address of the backend ECS.
    13  	ServerAddress string `json:"server_address"`
    14  	// Specifies the backend ECS ID.
    15  	ID string `json:"id"`
    16  	// Specifies the floating IP address assigned to the backend ECS.
    17  	Address string `json:"address"`
    18  	// Specifies the backend ECS status. The value is ACTIVE, PENDING, or ERROR.
    19  	Status string `json:"status"`
    20  	// Specifies the health check status. The value is NORMAL, ABNORMAL, or UNAVAILABLE.
    21  	HealthStatus string `json:"health_status"`
    22  	// Specifies the time when information about the backend ECS was updated.
    23  	UpdateTime string `json:"update_time"`
    24  	// Specifies the time when the backend ECS was created.
    25  	CreateTime string `json:"create_time"`
    26  	// Specifies the backend ECS name.
    27  	ServerName string `json:"server_name"`
    28  	// Specifies the original back member ID.
    29  	ServerID string `json:"server_id"`
    30  	// Specifies the listener to which the backend ECS belongs.
    31  	Listeners []map[string]interface{} `json:"listeners"`
    32  }
    33  
    34  // ListenerPage is the page returned by a pager when traversing over a
    35  // collection of routers.
    36  type BackendPage struct {
    37  	pagination.LinkedPageBase
    38  }
    39  
    40  // NextPageURL is invoked when a paginated collection of routers has reached
    41  // the end of a page and the pager seeks to traverse over a new one. In order
    42  // to do this, it needs to construct the next page's URL.
    43  func (r BackendPage) NextPageURL() (string, error) {
    44  	return "", nil
    45  }
    46  
    47  // IsEmpty checks whether a RouterPage struct is empty.
    48  func (r BackendPage) IsEmpty() (bool, error) {
    49  	is, err := ExtractBackend(r)
    50  	return len(is) == 0, err
    51  }
    52  
    53  // ExtractBackend accepts a Page struct, specifically a ListenerPage struct,
    54  // and extracts the elements into a slice of Listener structs. In other words,
    55  // a generic collection is mapped into a relevant slice.
    56  func ExtractBackend(r pagination.Page) ([]Backend, error) {
    57  	var Backends []Backend
    58  	err := (r.(BackendPage)).ExtractInto(&Backends)
    59  	return Backends, err
    60  }
    61  
    62  type commonResult struct {
    63  	golangsdk.Result
    64  }
    65  
    66  // Extract is a function that accepts a result and extracts a router.
    67  func (r commonResult) Extract() (*Backend, error) {
    68  	//fmt.Printf("Extracting Backend...\n")
    69  	var Backends []Backend
    70  	err := r.ExtractInto(&Backends)
    71  	if err != nil {
    72  		//fmt.Printf("Error: %s.\n", err.Error())
    73  		return nil, err
    74  	} else {
    75  		if len(Backends) == 0 {
    76  			return nil, nil
    77  		}
    78  		return &Backends[0], nil
    79  	}
    80  }
    81  
    82  // AddResult represents the result of a create operation.
    83  type AddResult struct {
    84  	commonResult
    85  }
    86  
    87  // GetResult represents the result of a get operation.
    88  type GetResult struct {
    89  	commonResult
    90  }
    91  
    92  func (r GetResult) Extract() ([]Backend, error) {
    93  	var b []Backend
    94  	err := r.ExtractInto(&b)
    95  	return b, err
    96  }
    97  
    98  // RemoveResult represents the result of a delete operation.
    99  type RemoveResult struct {
   100  	golangsdk.ErrResult
   101  }