-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontainers.go
80 lines (69 loc) · 2.31 KB
/
containers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package cloudability
import (
"encoding/json"
"strconv"
)
const containersEndpoint = "/containers/"
// ContainersEndpoint - Cloudability Containers Provisioning Endpoint
type ContainersEndpoint struct {
*v3Endpoint
}
// Containers - Cloudability ContainersProvisioning Endpoint
func (c *Client) Containers() *ContainersEndpoint {
return &ContainersEndpoint{newV3Endpoint(c, containersEndpoint)}
}
type Cluster struct {
ID int `json:"id,omitempty"`
ClusterName string `json:"clusterName"`
KubernetesVersion string `json:"kubernetesVersion,omitempty"`
ClusterVersion string `json:"clusterVersion,omitempty"`
CreatedAt string `json:"createdAt"`
}
type clustersResponse struct {
Result []Cluster `json:"result"`
}
type clusterPayload struct {
ClusterName string `json:"clusterName"`
KubernetesVersion string `json:"kubernetesVersion,omitempty"`
ClusterVersion string `json:"clusterVersion,omitempty"`
}
// GetCluster - Get an existing cluster by ID.
func (e ContainersEndpoint) GetCluster(id string) (*Cluster, error) {
var result clustersResponse
err := e.get(e, "provisioning/", &result)
if err != nil {
return nil, err
}
for _, cluster := range result.Result {
if strconv.Itoa(cluster.ID) == id {
return &cluster, nil
}
}
return nil, err
}
// GetClusterConfig - Get an existing cluster config by ID
func (e ContainersEndpoint) GetClusterConfig(id string) (string, error) {
return e.Client.doRaw(e, "GET", "provisioning/"+id+"/config")
}
// NewCluster - Create a new cluster.
func (e *ContainersEndpoint) NewCluster(clusterProvisioning *Cluster) (*Cluster, error) {
clusterProvisioningPayload := new(clusterPayload)
jsonCluster, err := json.Marshal(clusterProvisioning)
if err != nil {
return nil, err
}
err = json.Unmarshal(jsonCluster, clusterProvisioningPayload)
if err != nil {
return nil, err
}
var result v3Result[*Cluster]
err = e.post(e, "provisioning/", clusterProvisioningPayload, &result)
return result.Result, err
}
// UpdateCluster - Update an existing container by ID.
func (e *ContainersEndpoint) UpdateCluster(clusterProvisioning *Cluster) error {
payload := new(clusterPayload)
jsonCluster, _ := json.Marshal(clusterProvisioning)
json.Unmarshal(jsonCluster, payload)
return e.put(e, "provisioning/"+strconv.Itoa(clusterProvisioning.ID), payload)
}