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

     1  package pools
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/pagination"
     6  )
     7  
     8  // SessionPersistence represents the session persistence feature of the load
     9  // balancing service. It attempts to force connections or requests in the same
    10  // session to be processed by the same member as long as it is ative. Three
    11  // types of persistence are supported:
    12  //
    13  // SOURCE_IP: With this mode, all connections originating from the same source
    14  // IP address, will be handled by the same Member of the Pool.
    15  //
    16  // HTTP_COOKIE: With this persistence mode, the load balancing function will
    17  // create a cookie on the first request from a client. Subsequent
    18  // requests containing the same cookie value will be handled by
    19  // the same Member of the Pool.
    20  //
    21  // APP_COOKIE: With this persistence mode, the load balancing function will
    22  // rely on a cookie established by the backend application. All
    23  // requests carrying the same cookie value will be handled by the
    24  // same Member of the Pool.
    25  type SessionPersistence struct {
    26  	// The type of persistence mode.
    27  	Type string `json:"type,omitempty"`
    28  
    29  	// Name of cookie if persistence mode is set appropriately.
    30  	CookieName string `json:"cookie_name,omitempty"`
    31  
    32  	// Specifies the sticky session timeout duration in minutes.
    33  	// This parameter is invalid when type is set to APP_COOKIE.
    34  	PersistenceTimeout int `json:"persistence_timeout,omitempty"`
    35  }
    36  
    37  // LoadBalancerID represents a load balancer.
    38  type LoadBalancerID struct {
    39  	ID string `json:"id"`
    40  }
    41  
    42  // ListenerID represents a listener.
    43  type ListenerID struct {
    44  	ID string `json:"id"`
    45  }
    46  
    47  // Pool represents a logical set of devices, such as web servers, that you
    48  // group together to receive and process traffic. The load balancing function
    49  // chooses a Member of the Pool according to the configured load balancing
    50  // method to handle the new requests or connections received on the VIP address.
    51  type Pool struct {
    52  	// The load-balancer algorithm, which is round-robin, least-connections, and
    53  	// so on. This value, which must be supported, is dependent on the provider.
    54  	// Round-robin must be supported.
    55  	LBMethod string `json:"lb_algorithm"`
    56  
    57  	// The protocol of the Pool, which is TCP, HTTP, or HTTPS.
    58  	Protocol string `json:"protocol"`
    59  
    60  	// Description for the Pool.
    61  	Description string `json:"description"`
    62  
    63  	// A list of listeners objects IDs.
    64  	Listeners []ListenerID `json:"listeners"` // []map[string]interface{}
    65  
    66  	// A list of member objects IDs.
    67  	Members []Member `json:"members"`
    68  
    69  	// The ID of associated health monitor.
    70  	MonitorID string `json:"healthmonitor_id"`
    71  
    72  	// The network on which the members of the Pool will be located. Only members
    73  	// that are on this network can be added to the Pool.
    74  	SubnetID string `json:"subnet_id"`
    75  
    76  	// The administrative state of the Pool, which is up (true) or down (false).
    77  	AdminStateUp bool `json:"admin_state_up"`
    78  
    79  	// Pool name. Does not have to be unique.
    80  	Name string `json:"name"`
    81  
    82  	// The unique ID for the Pool.
    83  	ID string `json:"id"`
    84  
    85  	// A list of load balancer objects IDs.
    86  	Loadbalancers []LoadBalancerID `json:"loadbalancers"`
    87  
    88  	// Indicates whether connections in the same session will be processed by the
    89  	// same Pool member or not.
    90  	Persistence SessionPersistence `json:"session_persistence"`
    91  
    92  	// The provisioning status of the pool.
    93  	// This value is ACTIVE, PENDING_* or ERROR.
    94  	ProvisioningStatus string `json:"provisioning_status"`
    95  
    96  	// The IP address version.
    97  	IpVersion string `json:"ip_version"`
    98  
    99  	// Whether enable port transparent transmission.
   100  	AnyPortEnable bool `json:"any_port_enable"`
   101  
   102  	// Update protection status
   103  	ProtectionStatus *string `json:"protection_status"`
   104  
   105  	// Update protection reason
   106  	ProtectionReason string `json:"protection_reason"`
   107  
   108  	// Slow start.
   109  	SlowStart SlowStart `json:"slow_start"`
   110  
   111  	// Whether to enable deletion protection for the load balancer.
   112  	DeletionProtectionEnable bool `json:"member_deletion_protection_enable"`
   113  
   114  	// The type of the backend server group.
   115  	Type string `json:"type"`
   116  
   117  	// The ID of the VPC where the backend server group works.
   118  	VpcId string `json:"vpc_id"`
   119  
   120  	// The creation time.
   121  	CreatedAt string `json:"created_at"`
   122  
   123  	// The updated time.
   124  	UpdatedAt string `json:"updated_at"`
   125  }
   126  
   127  // PoolPage is the page returned by a pager when traversing over a
   128  // collection of pools.
   129  type PoolPage struct {
   130  	pagination.LinkedPageBase
   131  }
   132  
   133  // NextPageURL is invoked when a paginated collection of pools has reached
   134  // the end of a page and the pager seeks to traverse over a new one. In order
   135  // to do this, it needs to construct the next page's URL.
   136  func (r PoolPage) NextPageURL() (string, error) {
   137  	var s struct {
   138  		Links []golangsdk.Link `json:"pools_links"`
   139  	}
   140  	err := r.ExtractInto(&s)
   141  	if err != nil {
   142  		return "", err
   143  	}
   144  	return golangsdk.ExtractNextURL(s.Links)
   145  }
   146  
   147  // IsEmpty checks whether a PoolPage struct is empty.
   148  func (r PoolPage) IsEmpty() (bool, error) {
   149  	is, err := ExtractPools(r)
   150  	return len(is) == 0, err
   151  }
   152  
   153  // ExtractPools accepts a Page struct, specifically a PoolPage struct,
   154  // and extracts the elements into a slice of Pool structs. In other words,
   155  // a generic collection is mapped into a relevant slice.
   156  func ExtractPools(r pagination.Page) ([]Pool, error) {
   157  	var s struct {
   158  		Pools []Pool `json:"pools"`
   159  	}
   160  	err := (r.(PoolPage)).ExtractInto(&s)
   161  	return s.Pools, err
   162  }
   163  
   164  type commonResult struct {
   165  	golangsdk.Result
   166  }
   167  
   168  // Extract is a function that accepts a result and extracts a pool.
   169  func (r commonResult) Extract() (*Pool, error) {
   170  	var s struct {
   171  		Pool *Pool `json:"pool"`
   172  	}
   173  	err := r.ExtractInto(&s)
   174  	return s.Pool, err
   175  }
   176  
   177  // CreateResult represents the result of a Create operation. Call its Extract
   178  // method to interpret the result as a Pool.
   179  type CreateResult struct {
   180  	commonResult
   181  }
   182  
   183  // GetResult represents the result of a Get operation. Call its Extract
   184  // method to interpret the result as a Pool.
   185  type GetResult struct {
   186  	commonResult
   187  }
   188  
   189  // UpdateResult represents the result of an Update operation. Call its Extract
   190  // method to interpret the result as a Pool.
   191  type UpdateResult struct {
   192  	commonResult
   193  }
   194  
   195  // DeleteResult represents the result of a Delete operation. Call its
   196  // ExtractErr method to determine if the request succeeded or failed.
   197  type DeleteResult struct {
   198  	golangsdk.ErrResult
   199  }
   200  
   201  // Member represents the application running on a backend server.
   202  type Member struct {
   203  	// Name of the Member.
   204  	Name string `json:"name"`
   205  
   206  	// Weight of Member.
   207  	Weight int `json:"weight"`
   208  
   209  	// The administrative state of the member, which is up (true) or down (false).
   210  	AdminStateUp bool `json:"admin_state_up"`
   211  
   212  	// Owner of the Member.
   213  	TenantID string `json:"tenant_id"`
   214  
   215  	// Parameter value for the subnet UUID.
   216  	SubnetID string `json:"subnet_cidr_id"`
   217  
   218  	// The Pool to which the Member belongs.
   219  	PoolID string `json:"pool_id"`
   220  
   221  	// The IP address of the Member.
   222  	Address string `json:"address"`
   223  
   224  	// The port on which the application is hosted.
   225  	ProtocolPort int `json:"protocol_port"`
   226  
   227  	// The unique ID for the Member.
   228  	ID string `json:"id"`
   229  
   230  	// The provisioning status of the member.
   231  	// This value is ACTIVE, PENDING_* or ERROR.
   232  	ProvisioningStatus string `json:"provisioning_status"`
   233  }
   234  
   235  // MemberPage is the page returned by a pager when traversing over a
   236  // collection of Members in a Pool.
   237  type MemberPage struct {
   238  	pagination.LinkedPageBase
   239  }
   240  
   241  // NextPageURL is invoked when a paginated collection of members has reached
   242  // the end of a page and the pager seeks to traverse over a new one. In order
   243  // to do this, it needs to construct the next page's URL.
   244  func (r MemberPage) NextPageURL() (string, error) {
   245  	var s struct {
   246  		Links []golangsdk.Link `json:"members_links"`
   247  	}
   248  	err := r.ExtractInto(&s)
   249  	if err != nil {
   250  		return "", err
   251  	}
   252  	return golangsdk.ExtractNextURL(s.Links)
   253  }
   254  
   255  // IsEmpty checks whether a MemberPage struct is empty.
   256  func (r MemberPage) IsEmpty() (bool, error) {
   257  	is, err := ExtractMembers(r)
   258  	return len(is) == 0, err
   259  }
   260  
   261  // ExtractMembers accepts a Page struct, specifically a MemberPage struct,
   262  // and extracts the elements into a slice of Members structs. In other words,
   263  // a generic collection is mapped into a relevant slice.
   264  func ExtractMembers(r pagination.Page) ([]Member, error) {
   265  	var s struct {
   266  		Members []Member `json:"members"`
   267  	}
   268  	err := (r.(MemberPage)).ExtractInto(&s)
   269  	return s.Members, err
   270  }
   271  
   272  type commonMemberResult struct {
   273  	golangsdk.Result
   274  }
   275  
   276  // ExtractMember is a function that accepts a result and extracts a member.
   277  func (r commonMemberResult) Extract() (*Member, error) {
   278  	var s struct {
   279  		Member *Member `json:"member"`
   280  	}
   281  	err := r.ExtractInto(&s)
   282  	return s.Member, err
   283  }
   284  
   285  // CreateMemberResult represents the result of a CreateMember operation.
   286  // Call its Extract method to interpret it as a Member.
   287  type CreateMemberResult struct {
   288  	commonMemberResult
   289  }
   290  
   291  // GetMemberResult represents the result of a GetMember operation.
   292  // Call its Extract method to interpret it as a Member.
   293  type GetMemberResult struct {
   294  	commonMemberResult
   295  }
   296  
   297  // UpdateMemberResult represents the result of an UpdateMember operation.
   298  // Call its Extract method to interpret it as a Member.
   299  type UpdateMemberResult struct {
   300  	commonMemberResult
   301  }
   302  
   303  // DeleteMemberResult represents the result of a DeleteMember operation.
   304  // Call its ExtractErr method to determine if the request succeeded or failed.
   305  type DeleteMemberResult struct {
   306  	golangsdk.ErrResult
   307  }