github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/vpc/v1/publicips/requests.go (about)

     1  package publicips
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  type PublicIPRequest struct {
     9  	// Specifies the type of the elastic IP address. The value can the
    10  	// 5_telcom, 5_union, 5_bgp, or 5_sbgp. China Northeast: 5_telcom and 5_union China
    11  	// South: 5_sbgp China East: 5_sbgp China North: 5_bgp and 5_sbgp The value must be a
    12  	// type supported by the system. The value can be 5_telcom, 5_union, or 5_bgp.
    13  	Type string `json:"type" required:"true"`
    14  
    15  	// Specifies the elastic IP address to be obtained. The value must
    16  	// be a valid IP address in the available IP address segment.
    17  	IpAddress string `json:"ip_address,omitempty"`
    18  
    19  	// Value range: 4, 6, respectively, to create ipv4 and ipv6, when not created ipv4 by default
    20  	IPVersion int `json:"ip_version,omitempty"`
    21  }
    22  
    23  type BandWidth struct {
    24  	// Specifies the bandwidth name. The value is a string of 1 to 64
    25  	// characters that can contain letters, digits, underscores (_), and hyphens (-). This
    26  	// parameter is mandatory when share_type is set to PER and is optional when share_type
    27  	// is set to WHOLE with an ID specified.
    28  	Name string `json:"name,omitempty"`
    29  
    30  	// Specifies the bandwidth size. The value ranges from 1 Mbit/s to
    31  	// 300 Mbit/s. This parameter is mandatory when share_type is set to PER and is optional
    32  	// when share_type is set to WHOLE with an ID specified.
    33  	Size int `json:"size,omitempty"`
    34  
    35  	// Specifies the ID of the bandwidth. You can specify an earlier
    36  	// shared bandwidth when applying for an elastic IP address for the bandwidth whose type
    37  	// is set to WHOLE. The bandwidth whose type is set to WHOLE exclusively uses its own
    38  	// ID. The value can be the ID of the bandwidth whose type is set to WHOLE.
    39  	ID string `json:"id,omitempty"`
    40  
    41  	// Specifies whether the bandwidth is shared or exclusive. The
    42  	// value can be PER or WHOLE.
    43  	ShareType string `json:"share_type" required:"true"`
    44  
    45  	// Specifies the charging mode (by traffic or by bandwidth). The
    46  	// value can be bandwidth or traffic. If the value is an empty character string or no
    47  	// value is specified, default value bandwidth is used.
    48  	ChargeMode string `json:"charge_mode,omitempty"`
    49  }
    50  
    51  type CreateOpts struct {
    52  	// Specifies the elastic IP address objects.
    53  	Publicip PublicIPRequest `json:"publicip" required:"true"`
    54  
    55  	// Specifies the bandwidth objects.
    56  	Bandwidth BandWidth `json:"bandwidth" required:"true"`
    57  	//	Enterprise project ID. The maximum length is 36 bytes, with the U-ID format of the hyphen "-", or the string "0".
    58  	// When creating an elastic public IP address, bind the enterprise project ID to the elastic public network IP.
    59  	EnterpriseProjectId string `json:"enterprise_project_id,omitempty"`
    60  }
    61  
    62  type CreateOptsBuilder interface {
    63  	ToCreatePublicIPMap() (map[string]interface{}, error)
    64  }
    65  
    66  func (opts CreateOpts) ToCreatePublicIPMap() (map[string]interface{}, error) {
    67  	b, err := golangsdk.BuildRequestBody(opts, "")
    68  	if err != nil {
    69  		return nil, err
    70  	}
    71  	return b, nil
    72  }
    73  
    74  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    75  	b, err := opts.ToCreatePublicIPMap()
    76  	if err != nil {
    77  		r.Err = err
    78  		return
    79  	}
    80  
    81  	_, r.Err = client.Post(CreateURL(client), b, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}})
    82  	return
    83  }
    84  
    85  func Delete(client *golangsdk.ServiceClient, publicipId string) (r DeleteResult) {
    86  	url := DeleteURL(client, publicipId)
    87  	_, r.Err = client.Delete(url, nil)
    88  	return
    89  }
    90  
    91  func Get(client *golangsdk.ServiceClient, publicipId string) (r GetResult) {
    92  	url := GetURL(client, publicipId)
    93  	_, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{})
    94  	return
    95  }
    96  
    97  type ListOpts struct {
    98  	// Specifies the resource ID of pagination query. If the parameter
    99  	// is left blank, only resources on the first page are queried.
   100  	Marker string `q:"marker"`
   101  
   102  	// Specifies the number of records returned on each page. The
   103  	// value ranges from 0 to intmax.
   104  	Limit int `q:"limit"`
   105  
   106  	// Value range: 4, 6, respectively, to create ipv4 and ipv6, when not created ipv4 by default
   107  	IPVersion int `q:"ip_version"`
   108  
   109  	// enterprise_project_id
   110  	// You can use this field to filter the elastic public IP under an enterprise project.
   111  	EnterpriseProjectId string `q:"enterprise_project_id"`
   112  }
   113  
   114  type ListOptsBuilder interface {
   115  	ToListPublicIPQuery() (string, error)
   116  }
   117  
   118  func (opts ListOpts) ToListPublicIPQuery() (string, error) {
   119  	q, err := golangsdk.BuildQueryString(opts)
   120  	if err != nil {
   121  		return "", err
   122  	}
   123  	return q.String(), err
   124  }
   125  
   126  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
   127  	url := ListURL(client)
   128  	if opts != nil {
   129  		query, err := opts.ToListPublicIPQuery()
   130  		if err != nil {
   131  			return pagination.Pager{Err: err}
   132  		}
   133  		url += query
   134  	}
   135  
   136  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   137  		return PublicIPPage{pagination.LinkedPageBase{PageResult: r}}
   138  	})
   139  }
   140  
   141  type UpdateOpts struct {
   142  	// Specifies the port ID.
   143  	PortId string `json:"port_id,omitempty"`
   144  
   145  	// Value range: 4, 6, respectively, to create ipv4 and ipv6, when not created ipv4 by default
   146  	IPVersion int `json:"ip_version,omitempty"`
   147  }
   148  
   149  type UpdateOptsBuilder interface {
   150  	ToUpdatePublicIPMap() (map[string]interface{}, error)
   151  }
   152  
   153  func (opts UpdateOpts) ToUpdatePublicIPMap() (map[string]interface{}, error) {
   154  	b, err := golangsdk.BuildRequestBody(opts, "publicip")
   155  	if err != nil {
   156  		return nil, err
   157  	}
   158  	return b, nil
   159  }
   160  
   161  func Update(client *golangsdk.ServiceClient, publicipId string, opts UpdateOptsBuilder) (r UpdateResult) {
   162  	b, err := opts.ToUpdatePublicIPMap()
   163  	if err != nil {
   164  		r.Err = err
   165  		return
   166  	}
   167  
   168  	_, r.Err = client.Put(UpdateURL(client, publicipId), b, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}})
   169  	return
   170  }