From dbcc29a60378ac4dcce315d763a492630155183b Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Wed, 30 Oct 2019 06:58:27 +0000 Subject: [PATCH] Add update eip support --- openstack/cce/v3/clusters/requests.go | 31 +++++++++++++++++++++++++++ openstack/cce/v3/clusters/results.go | 6 ++++++ openstack/cce/v3/clusters/urls.go | 9 ++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/openstack/cce/v3/clusters/requests.go b/openstack/cce/v3/clusters/requests.go index b2881b518..d6c509578 100644 --- a/openstack/cce/v3/clusters/requests.go +++ b/openstack/cce/v3/clusters/requests.go @@ -199,3 +199,34 @@ func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { }) return } + +type UpdateIpOpts struct { + Action string `json:"action" required:"true"` + Spec IpSpec `json:"spec,omitempty"` + ElasticIp string `json:"elasticIp"` +} + +type IpSpec struct { + ID string `json:"id" required:"true"` +} + +type UpdateIpOptsBuilder interface { + ToMasterIpUpdateMap() (map[string]interface{}, error) +} + +func (opts UpdateIpOpts) ToMasterIpUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "spec") +} + +// Update the access information of a specified cluster. +func UpdateMasterIp(c *golangsdk.ServiceClient, id string, opts UpdateIpOptsBuilder) (r UpdateIpResult) { + b, err := opts.ToMasterIpUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(masterIpURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/openstack/cce/v3/clusters/results.go b/openstack/cce/v3/clusters/results.go index 9a3850802..71d9ccb72 100644 --- a/openstack/cce/v3/clusters/results.go +++ b/openstack/cce/v3/clusters/results.go @@ -287,3 +287,9 @@ func (r GetCertResult) Extract() (*Certificate, error) { err := r.ExtractInto(&s) return &s, err } + +// UpdateIpResult represents the result of an update operation. Call its Extract +// method to interpret it as a Cluster. +type UpdateIpResult struct { + golangsdk.ErrResult +} diff --git a/openstack/cce/v3/clusters/urls.go b/openstack/cce/v3/clusters/urls.go index af2c00c43..1248ce0fd 100644 --- a/openstack/cce/v3/clusters/urls.go +++ b/openstack/cce/v3/clusters/urls.go @@ -3,8 +3,9 @@ package clusters import "github.com/huaweicloud/golangsdk" const ( - rootPath = "clusters" - certPath = "clustercert" + rootPath = "clusters" + certPath = "clustercert" + masterIpPath = "mastereip" ) func rootURL(client *golangsdk.ServiceClient) string { @@ -18,3 +19,7 @@ func resourceURL(c *golangsdk.ServiceClient, id string) string { func certificateURL(c *golangsdk.ServiceClient, id string) string { return c.ServiceURL(rootPath, id, certPath) } + +func masterIpURL(c *golangsdk.ServiceClient, id string) string { + return c.ServiceURL(rootPath, id, masterIpPath) +}