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

     1  package nodes
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/openstack"
     6  )
     7  
     8  // List returns collection of nodes.
     9  func List(client *golangsdk.ServiceClient, clusterID string) (r ListResult) {
    10  	_, r.Err = client.Get(listURL(client, clusterID), &r.Body, openstack.StdRequestOpts())
    11  	return
    12  }
    13  
    14  // Get retrieves a particular nodes based on its unique ID and cluster ID.
    15  func Get(c *golangsdk.ServiceClient, clusterID, k8sName string) (r GetResult) {
    16  	_, r.Err = c.Get(nodeURL(c, clusterID, k8sName), &r.Body, openstack.StdRequestOpts())
    17  	return
    18  }
    19  
    20  // UpdateOptsBuilder allows extensions to add additional parameters to the
    21  // Update request.
    22  type UpdateOptsBuilder interface {
    23  	ToNodeUpdateMap() (map[string]interface{}, error)
    24  }
    25  
    26  // UpdateOpts contains all the values needed to update a new node
    27  type UpdateOpts struct {
    28  	Metadata Metadata `json:"metadata,omitempty"`
    29  }
    30  
    31  type Metadata struct {
    32  	Labels map[string]interface{} `json:"labels,omitempty"`
    33  }
    34  
    35  // ToNodeUpdateMap builds an update body based on UpdateOpts.
    36  func (opts UpdateOpts) ToNodeUpdateMap() (map[string]interface{}, error) {
    37  	return golangsdk.BuildRequestBody(opts, "")
    38  }
    39  
    40  // Update allows nodes to be updated.
    41  func Update(c *golangsdk.ServiceClient, clusterID, k8sName string, opts UpdateOptsBuilder) (r UpdateResult) {
    42  	b, err := opts.ToNodeUpdateMap()
    43  	if err != nil {
    44  		r.Err = err
    45  		return
    46  	}
    47  	_, r.Err = c.Patch(nodeURL(c, clusterID, k8sName), b, &r.Body, &golangsdk.RequestOpts{
    48  		OkCodes: []int{200},
    49  		MoreHeaders: map[string]string{
    50  			"Content-Type": "application/merge-patch+json",
    51  		},
    52  	})
    53  	return
    54  }