-
Notifications
You must be signed in to change notification settings - Fork 0
/
pools.go
93 lines (84 loc) · 2.93 KB
/
pools.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
81
82
83
84
85
86
87
88
89
90
91
92
93
package ecogo
import (
"context"
"fmt"
"net/http"
"path"
"time"
)
var (
poolPath = path.Join(apiV1Path, "pool")
poolPathUD = path.Join(poolPath, "%d")
)
var _ PoolServiceI = &PoolService{}
type PoolServiceI interface {
Create(ctx context.Context, clusterID uint, opt *PoolOpt) error
Update(ctx context.Context, clusterID, poolID uint, opt *PoolOpt) error
Delete(ctx context.Context, clusterID, poolID uint) error
}
type PoolService struct {
client *Client
}
type Pool struct {
ID uint `json:"id" yaml:"id"`
NodeCount int `json:"nodeCount" yaml:"nodeCount"`
MaxNodeCount int `json:"maxNodeCount" yaml:"maxNodeCount"`
MinNodeCount int `json:"minNodeCount" yaml:"minNodeCount"`
VolumeSize int `json:"volumeSize" yaml:"volumeSize"`
SetTaint bool `json:"set-taint" yaml:"setTaint"`
Created time.Time `json:"created" yaml:"created"`
Role string `json:"k8s-role" yaml:"role"`
Name string `json:"name" yaml:"name"`
Flavor string `json:"flavor" yaml:"flavor"`
State string `json:"state" yaml:"state"`
Status string `json:"status" yaml:"status"`
VolumeType string `json:"volumeType" yaml:"volumeType"`
}
type PoolOpt struct {
NodeCount int `json:"nodeCount" yaml:"nodeCount"`
MaxNodeCount int `json:"maxNodeCount" yaml:"maxNodeCount"`
MinNodeCount int `json:"minNodeCount" yaml:"minNodeCount"`
VolumeSize int `json:"volumeSize" yaml:"volumeSize"`
Repair bool `json:"repair" yaml:"repair"`
SetTaint bool `json:"set-taint" yaml:"setTaint"`
Role string `json:"k8s-role" yaml:"role"`
VolumeType string `json:"volumeType" yaml:"volumeType"`
Name string `json:"name" yaml:"name"`
Flavor string `json:"flavor" yaml:"flavor"`
}
func (s *PoolService) Create(ctx context.Context, clusterID uint, opt *PoolOpt) error {
requestPath := fmt.Sprintf(poolPath, s.client.projectID, s.client.regionID, clusterID)
req, err := s.client.NewRequest(ctx, http.MethodPost, requestPath, opt)
if err != nil {
return err
}
var resp string
if _, err = s.client.Do(ctx, req, &resp); err != nil {
return err
}
return nil
}
func (s *PoolService) Update(ctx context.Context, clusterID, poolID uint, opt *PoolOpt) error {
requestPath := fmt.Sprintf(poolPathUD, s.client.projectID, s.client.regionID, clusterID, poolID)
req, err := s.client.NewRequest(ctx, http.MethodPatch, requestPath, opt)
if err != nil {
return err
}
var resp string
if _, err = s.client.Do(ctx, req, &resp); err != nil {
return err
}
return nil
}
func (s *PoolService) Delete(ctx context.Context, clusterID, poolID uint) error {
requestPath := fmt.Sprintf(poolPathUD, s.client.projectID, s.client.regionID, clusterID, poolID)
req, err := s.client.NewRequest(ctx, http.MethodDelete, requestPath, nil)
if err != nil {
return err
}
var resp string
if _, err = s.client.Do(ctx, req, &resp); err != nil {
return err
}
return nil
}