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

     1  package bandwidths
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  func Get(client *golangsdk.ServiceClient, bandwidthId string) (r GetResult) {
     9  	url := GetURL(client, bandwidthId)
    10  	_, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{
    11  		OkCodes: []int{200},
    12  	})
    13  	return
    14  }
    15  
    16  type ListOpts struct {
    17  	// Specifies the resource ID of pagination query. If the parameter
    18  	// is left blank, only resources on the first page are queried.
    19  	Marker string `q:"marker"`
    20  
    21  	// Specifies the number of records returned on each page.
    22  	Limit int `q:"limit"`
    23  
    24  	// enterprise_project_id
    25  	// You can use this field to filter the bandwidth under an enterprise project.
    26  	EnterpriseProjectId string `q:"enterprise_project_id"`
    27  }
    28  
    29  type ListOptsBuilder interface {
    30  	ToListQuery() (string, error)
    31  }
    32  
    33  func (opts ListOpts) ToListQuery() (string, error) {
    34  	q, err := golangsdk.BuildQueryString(opts)
    35  	if err != nil {
    36  		return "", err
    37  	}
    38  	return q.String(), err
    39  }
    40  
    41  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    42  	url := ListURL(client)
    43  	if opts != nil {
    44  		query, err := opts.ToListQuery()
    45  		if err != nil {
    46  			return pagination.Pager{Err: err}
    47  		}
    48  		url += query
    49  	}
    50  
    51  	return pagination.NewPager(client, url,
    52  		func(r pagination.PageResult) pagination.Page {
    53  			return BandWidthPage{pagination.LinkedPageBase{PageResult: r}}
    54  		})
    55  }
    56  
    57  type UpdateOpts struct {
    58  	// Specifies the bandwidth name. The value is a string of 1 to 64
    59  	// characters that can contain letters, digits, underscores (_), and hyphens (-).
    60  	Name string `json:"name,omitempty"`
    61  
    62  	// Specifies the bandwidth size. The value ranges from 1 Mbit/s to
    63  	// 300 Mbit/s.
    64  	Size int `json:"size,omitempty"`
    65  }
    66  
    67  type UpdateOptsBuilder interface {
    68  	ToBandwidthsUpdateMap() (map[string]interface{}, error)
    69  }
    70  
    71  func (opts UpdateOpts) ToBandwidthsUpdateMap() (map[string]interface{}, error) {
    72  	b, err := golangsdk.BuildRequestBody(&opts, "bandwidth")
    73  	if err != nil {
    74  		return nil, err
    75  	}
    76  	return b, nil
    77  }
    78  
    79  func Update(client *golangsdk.ServiceClient, bandwidthId string, opts UpdateOptsBuilder) (r UpdateResult) {
    80  	b, err := opts.ToBandwidthsUpdateMap()
    81  	if err != nil {
    82  		r.Err = err
    83  		return
    84  	}
    85  
    86  	_, r.Err = client.Put(UpdateURL(client, bandwidthId), b, &r.Body, &golangsdk.RequestOpts{
    87  		OkCodes: []int{200},
    88  	})
    89  	return
    90  }