github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/elb/v3/loadbalancers/requests.go (about)

     1  package loadbalancers
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     7  )
     8  
     9  // ListOptsBuilder allows extensions to add additional parameters to the
    10  // List request.
    11  type ListOptsBuilder interface {
    12  	ToLoadbalancerListQuery() (string, error)
    13  }
    14  
    15  type ListOpts struct {
    16  	ID                   []string `q:"id"`
    17  	Name                 []string `q:"name"`
    18  	Description          []string `q:"description"`
    19  	ProvisioningStatus   []string `q:"provisioning_status"`
    20  	OperatingStatus      []string `q:"operating_status"`
    21  	VpcID                []string `q:"vpc_id"`
    22  	VipPortID            []string `q:"vip_port_id"`
    23  	VipAddress           []string `q:"vip_address"`
    24  	VipSubnetCidrID      []string `q:"vip_subnet_cidr_id"`
    25  	L4FlavorID           []string `q:"l4_flavor_id"`
    26  	L4ScaleFlavorID      []string `q:"l4_scale_flavor_id"`
    27  	AvailabilityZoneList []string `q:"availability_zone_list"`
    28  	L7FlavorID           []string `q:"l7_flavor_id"`
    29  	L7ScaleFlavorID      []string `q:"l7_scale_flavor_id"`
    30  	Limit                int      `q:"limit"`
    31  	Marker               string   `q:"marker"`
    32  }
    33  
    34  // ToLoadbalancerListQuery formats a ListOpts into a query string.
    35  func (opts ListOpts) ToLoadbalancerListQuery() (string, error) {
    36  	q, err := golangsdk.BuildQueryString(opts)
    37  	return q.String(), err
    38  }
    39  
    40  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    41  	url := rootURL(client)
    42  	if opts != nil {
    43  		query, err := opts.ToLoadbalancerListQuery()
    44  		if err != nil {
    45  			return pagination.Pager{Err: err}
    46  		}
    47  		url += query
    48  	}
    49  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    50  		return LoadbalancerPage{PageWithInfo: pagination.NewPageWithInfo(r)}
    51  	})
    52  }
    53  
    54  // CreateOptsBuilder allows extensions to add additional parameters to the
    55  // Create request.
    56  type CreateOptsBuilder interface {
    57  	ToLoadBalancerCreateMap() (map[string]interface{}, error)
    58  }
    59  
    60  // CreateOpts is the common options' struct used in this package's Create
    61  // operation.
    62  type CreateOpts struct {
    63  	// Human-readable name for the Loadbalancer. Does not have to be unique.
    64  	Name string `json:"name,omitempty"`
    65  
    66  	// Human-readable description for the Loadbalancer.
    67  	Description string `json:"description,omitempty"`
    68  
    69  	// The IP address of the Loadbalancer.
    70  	VipAddress string `json:"vip_address,omitempty"`
    71  
    72  	// The network on which to allocate the Loadbalancer's address.
    73  	VipSubnetCidrID string `json:"vip_subnet_cidr_id,omitempty"`
    74  
    75  	// The V6 network on which to allocate the Loadbalancer's address.
    76  	IpV6VipSubnetID string `json:"ipv6_vip_virsubnet_id,omitempty"`
    77  
    78  	// The UUID of a l4 flavor.
    79  	L4Flavor string `json:"l4_flavor_id,omitempty"`
    80  
    81  	// Guaranteed.
    82  	Guaranteed *bool `json:"guaranteed,omitempty"`
    83  
    84  	// The VPC ID.
    85  	VpcID string `json:"vpc_id,omitempty"`
    86  
    87  	// Availability Zone List.
    88  	AvailabilityZoneList []string `json:"availability_zone_list" required:"true"`
    89  
    90  	// The tags of the Loadbalancer.
    91  	Tags []tags.ResourceTag `json:"tags,omitempty"`
    92  
    93  	// The administrative state of the Loadbalancer. A valid value is true (UP)
    94  	// or false (DOWN).
    95  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
    96  
    97  	// The UUID of a l7 flavor.
    98  	L7Flavor string `json:"l7_flavor_id,omitempty"`
    99  
   100  	// IPv6 Bandwidth.
   101  	IPV6Bandwidth *BandwidthRef `json:"ipv6_bandwidth,omitempty"`
   102  
   103  	// Public IP IDs.
   104  	PublicIpIDs []string `json:"publicip_ids,omitempty"`
   105  
   106  	// Public IP.
   107  	PublicIp *PublicIp `json:"publicip,omitempty"`
   108  
   109  	// ELB VirSubnet IDs.
   110  	ElbSubnetIDs []string `json:"elb_virsubnet_ids,omitempty"`
   111  
   112  	// IP Target Enable.
   113  	IpTargetEnable *bool `json:"ip_target_enable,omitempty"`
   114  
   115  	// Specifies whether to enable deletion protection for the load balancer.
   116  	DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"`
   117  }
   118  
   119  type BandwidthRef struct {
   120  	// Share Bandwidth ID
   121  	ID string `json:"id" required:"true"`
   122  }
   123  
   124  type PublicIp struct {
   125  	// IP Version.
   126  	IpVersion int `json:"ip_version,omitempty"`
   127  
   128  	// Network Type
   129  	NetworkType string `json:"network_type" required:"true"`
   130  
   131  	// Billing Info.
   132  	BillingInfo string `json:"billing_info,omitempty"`
   133  
   134  	// Description.
   135  	Description string `json:"description,omitempty"`
   136  
   137  	// Bandwidth
   138  	Bandwidth Bandwidth `json:"bandwidth" required:"true"`
   139  }
   140  
   141  type Bandwidth struct {
   142  	// Name
   143  	Name string `json:"name" required:"true"`
   144  
   145  	// Size
   146  	Size int `json:"size" required:"true"`
   147  
   148  	// Charge Mode
   149  	ChargeMode string `json:"charge_mode" required:"true"`
   150  
   151  	// Share Type
   152  	ShareType string `json:"share_type" required:"true"`
   153  }
   154  
   155  // ToLoadBalancerCreateMap builds a request body from CreateOpts.
   156  func (opts CreateOpts) ToLoadBalancerCreateMap() (map[string]interface{}, error) {
   157  	return golangsdk.BuildRequestBody(opts, "loadbalancer")
   158  }
   159  
   160  // Create is an operation which provisions a new loadbalancer based on the
   161  // configuration defined in the CreateOpts struct. Once the request is
   162  // validated and progress has started on the provisioning process, a
   163  // CreateResult will be returned.
   164  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   165  	b, err := opts.ToLoadBalancerCreateMap()
   166  	if err != nil {
   167  		r.Err = err
   168  		return
   169  	}
   170  	_, r.Err = client.Post(rootURL(client), b, &r.Body, nil)
   171  	return
   172  }
   173  
   174  // Get retrieves a particular Loadbalancer based on its unique ID.
   175  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
   176  	_, r.Err = client.Get(resourceURL(client, id), &r.Body, nil)
   177  	return
   178  }
   179  
   180  // UpdateOptsBuilder allows extensions to add additional parameters to the
   181  // Update request.
   182  type UpdateOptsBuilder interface {
   183  	ToLoadBalancerUpdateMap() (map[string]interface{}, error)
   184  }
   185  
   186  // UpdateOpts is the common options' struct used in this package's Update
   187  // operation.
   188  type UpdateOpts struct {
   189  	// Human-readable name for the Loadbalancer. Does not have to be unique.
   190  	Name string `json:"name,omitempty"`
   191  
   192  	// Human-readable description for the Loadbalancer.
   193  	Description *string `json:"description,omitempty"`
   194  
   195  	// The administrative state of the Loadbalancer. A valid value is true (UP)
   196  	// or false (DOWN).
   197  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
   198  
   199  	// The IP address of the Loadbalancer.
   200  	VipAddress string `json:"vip_address,omitempty"`
   201  
   202  	// The network on which to allocate the Loadbalancer's address.
   203  	VipSubnetCidrID *string `json:"vip_subnet_cidr_id,omitempty"`
   204  
   205  	// The V6 network on which to allocate the Loadbalancer's address.
   206  	IpV6VipSubnetID *string `json:"ipv6_vip_virsubnet_id,omitempty"`
   207  
   208  	// The UUID of a l4 flavor.
   209  	L4Flavor string `json:"l4_flavor_id,omitempty"`
   210  
   211  	// The UUID of a l7 flavor.
   212  	L7Flavor string `json:"l7_flavor_id,omitempty"`
   213  
   214  	// IPv6 Bandwidth.
   215  	IpV6Bandwidth *BandwidthRef `json:"ipv6_bandwidth,omitempty"`
   216  
   217  	// ELB VirSubnet IDs.
   218  	ElbSubnetIDs []string `json:"elb_virsubnet_ids,omitempty"`
   219  
   220  	// IP Target Enable.
   221  	IpTargetEnable *bool `json:"ip_target_enable,omitempty"`
   222  
   223  	// Specifies whether to enable deletion protection for the load balancer.
   224  	DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"`
   225  }
   226  
   227  // ToLoadBalancerUpdateMap builds a request body from UpdateOpts.
   228  func (opts UpdateOpts) ToLoadBalancerUpdateMap() (map[string]interface{}, error) {
   229  	return golangsdk.BuildRequestBody(opts, "loadbalancer")
   230  }
   231  
   232  // Update is an operation which modifies the attributes of the specified
   233  // LoadBalancer.
   234  func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
   235  	b, err := opts.ToLoadBalancerUpdateMap()
   236  	if err != nil {
   237  		r.Err = err
   238  		return
   239  	}
   240  	_, r.Err = client.Put(resourceURL(client, id), b, &r.Body, &golangsdk.RequestOpts{
   241  		OkCodes: []int{200, 202},
   242  	})
   243  	return
   244  }
   245  
   246  // Delete will permanently delete a particular LoadBalancer based on its
   247  // unique ID.
   248  func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
   249  	_, r.Err = client.Delete(resourceURL(client, id), nil)
   250  	return
   251  }
   252  
   253  // GetStatuses will return the status of a particular LoadBalancer.
   254  func GetStatuses(client *golangsdk.ServiceClient, id string) (r GetStatusesResult) {
   255  	_, r.Err = client.Get(statusURL(client, id), &r.Body, nil)
   256  	return
   257  }