-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] Refactor CCE clusters v3 (#761)
- Loading branch information
1 parent
12bde9d
commit 38656d0
Showing
16 changed files
with
380 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package clusters | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
// CreateOpts contains all the values needed to create a new cluster | ||
type CreateOpts struct { | ||
// API type, fixed value Cluster | ||
Kind string `json:"kind" required:"true"` | ||
// API version, fixed value v3 | ||
ApiVersion string `json:"apiversion" required:"true"` | ||
// Metadata required to create a cluster | ||
Metadata CreateMetaData `json:"metadata" required:"true"` | ||
// specifications to create a cluster | ||
Spec Spec `json:"spec" required:"true"` | ||
} | ||
|
||
// Metadata required to create a cluster | ||
type CreateMetaData struct { | ||
// Cluster unique name | ||
Name string `json:"name" required:"true"` | ||
// Cluster tag, key/value pair format | ||
Labels map[string]string `json:"labels,omitempty"` | ||
// Cluster annotation, key/value pair format | ||
Annotations map[string]string `json:"annotations,omitempty"` | ||
} | ||
|
||
// Create accepts a CreateOpts struct and uses the values to create a new | ||
// logical cluster. | ||
func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Clusters, error) { | ||
b, err := build.RequestBody(opts, "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// POST /api/v3/projects/{project_id}/clusters | ||
raw, err := client.Post(client.ServiceURL("clusters"), b, nil, &golangsdk.RequestOpts{ | ||
OkCodes: []int{201}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res Clusters | ||
return &res, extract.Into(raw.Body, &res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package clusters | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
) | ||
|
||
type DeleteQueryParams struct { | ||
ErrorStatus string `q:"errorStatus,omitempty"` | ||
DeleteEfs string `q:"delete_efs,omitempty"` | ||
DeleteENI string `q:"delete_eni,omitempty"` | ||
DeleteEvs string `q:"delete_evs,omitempty"` | ||
DeleteNet string `q:"delete_net,omitempty"` | ||
DeleteObs string `q:"delete_obs,omitempty"` | ||
DeleteSfs string `q:"delete_sfs,omitempty"` | ||
} | ||
|
||
// Delete will permanently delete a particular cluster based on its unique ID. | ||
func Delete(client *golangsdk.ServiceClient, clusterId string, opts DeleteQueryParams) error { | ||
|
||
url, err := golangsdk.NewURLBuilder().WithEndpoints("clusters", clusterId).WithQueryParams(opts).Build() | ||
if err != nil { | ||
return err | ||
} | ||
_, err = client.Delete(client.ServiceURL(url.String()), &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
MoreHeaders: map[string]string{"Content-Type": "application/json"}, | ||
JSONBody: nil, | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package clusters | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
// Get retrieves a particular cluster based on its unique ID. | ||
func Get(client *golangsdk.ServiceClient, clusterId string) (*Clusters, error) { | ||
// GET /api/v3/projects/{project_id}/clusters/{cluster_id} | ||
raw, err := client.Get(client.ServiceURL("clusters", clusterId), nil, &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
MoreHeaders: map[string]string{"Content-Type": "application/json"}, | ||
JSONBody: nil, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res Clusters | ||
return &res, extract.Into(raw.Body, &res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package clusters | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
// GetCert retrieves a particular cluster certificate based on its unique ID. (Depreciated) | ||
func GetCert(client *golangsdk.ServiceClient, clusterId string) (*Certificate, error) { | ||
// GET /api/v3/projects/{project_id}/clusters/{cluster_id}/clustercert | ||
raw, err := client.Get(client.ServiceURL("clusters", clusterId, "clustercert"), nil, &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
MoreHeaders: map[string]string{"Content-Type": "application/json"}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res Certificate | ||
return &res, extract.Into(raw.Body, &res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package clusters | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
type ExpirationOpts struct { | ||
Duration int `json:"duration" required:"true"` | ||
} | ||
|
||
// GetCertWithExpiration retrieves a particular cluster certificate based on its unique ID. | ||
func GetCertWithExpiration(client *golangsdk.ServiceClient, clusterId string, opts ExpirationOpts) (*Certificate, error) { | ||
b, err := build.RequestBody(opts, "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// POST /api/v3/projects/{project_id}/clusters/{cluster_id}/clustercert | ||
raw, err := client.Post(client.ServiceURL("clusters", clusterId, "clustercert"), b, nil, &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
MoreHeaders: map[string]string{"Content-Type": "application/json"}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res Certificate | ||
return &res, extract.Into(raw.Body, &res) | ||
} |
Oops, something went wrong.