-
Notifications
You must be signed in to change notification settings - Fork 11
/
mcis.go
164 lines (130 loc) · 3.81 KB
/
mcis.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package tumblebug
import (
"fmt"
"net/http"
"strings"
"github.com/cloud-barista/cb-mcks/src/core/app"
)
/* instance of a MCIS */
func NewMCIS(ns string, name string) *MCIS {
return &MCIS{
Model: Model{Name: name, Namespace: ns},
VMs: []VM{},
}
}
/* instance of a VM */
func NewVM(namespace string, name string, mcisName string) *VM {
return &VM{
Model: Model{Name: name, Namespace: namespace},
mcisName: mcisName,
UserAccount: VM_USER_ACCOUNT,
}
}
/* new instance of NLB */
func NewNLB(ns string, mcisName string, groupId string) *NLBReq {
nlb := &NLBReq{
NLBBase: NLBBase{
Model: Model{Name: groupId, Namespace: ns},
Type: "PUBLIC",
Scope: "REGION", Listener: NLBProtocolBase{Protocol: "TCP", Port: "6443"},
TargetGroup: TargetGroup{NLBProtocolBase: NLBProtocolBase{Protocol: "TCP", Port: "6443"}, MCIS: mcisName, VmGroupId: groupId},
},
HealthChecker: HealthCheckReq{
NLBProtocolBase: NLBProtocolBase{Protocol: "TCP", Port: "22"},
Interval: "default", Threshold: "default", Timeout: "default",
},
}
if strings.Contains(nlb.NLBBase.Config, string(app.CSP_GCP)) {
nlb.HealthChecker.NLBProtocolBase.Protocol = "HTTP"
nlb.HealthChecker.NLBProtocolBase.Port = "80"
}
return nlb
}
/* MCIS */
func (self *MCIS) GET() (bool, error) {
return self.execute(http.MethodGet, fmt.Sprintf("/ns/%s/mcis/%s", self.Namespace, self.Name), nil, &self)
}
func (self *MCIS) POST() error {
_, err := self.execute(http.MethodPost, fmt.Sprintf("/ns/%s/mcis", self.Namespace), self, &self)
if err != nil {
return err
}
return nil
}
func (self *MCIS) DELETE() (bool, error) {
exist, err := self.GET()
if err != nil {
return exist, err
}
if exist {
_, err := self.execute(http.MethodDelete, fmt.Sprintf("/ns/%s/mcis/%s", self.Namespace, self.Name), nil, app.Status{})
if err != nil {
return exist, err
}
}
return exist, nil
}
func (self *MCIS) TERMINATE() error {
_, err := self.execute(http.MethodGet, fmt.Sprintf("/ns/%s/control/mcis/%s?action=terminate", self.Namespace, self.Name), nil, app.Status{})
if err != nil {
return err
}
return nil
}
func (self *MCIS) REFINE() error {
_, err := self.execute(http.MethodGet, fmt.Sprintf("/ns/%s/control/mcis/%s?action=refine", self.Namespace, self.Name), nil, app.Status{})
if err != nil {
return err
}
return nil
}
/* VM */
func (self *VM) GET() (bool, error) {
return self.execute(http.MethodGet, fmt.Sprintf("/ns/%s/mcis/%s/vm/%s", self.Namespace, self.mcisName, self.Name), nil, &self)
}
func (self *VM) POST() error {
_, err := self.execute(http.MethodPost, fmt.Sprintf("/ns/%s/mcis/%s/vm", self.Namespace, self.mcisName), self, &self)
if err != nil {
return err
}
return nil
}
func (self *VM) DELETE() (bool, error) {
exist, err := self.GET()
if err != nil {
return exist, err
}
if exist {
_, err := self.execute(http.MethodDelete, fmt.Sprintf("/ns/%s/mcis/%s/vm/%s", self.Namespace, self.mcisName, self.Name), nil, app.Status{})
if err != nil {
return exist, err
}
}
return exist, nil
}
// NLB
func (self *NLBReq) GET() (bool, error) {
NLBRes := new(NLBRes)
return self.execute(http.MethodGet, fmt.Sprintf("/ns/%s/mcis/%s/nlb/%s", self.Namespace, self.TargetGroup.MCIS, self.Name), nil, &NLBRes)
}
func (self *NLBReq) POST() error {
NLBRes := new(NLBRes)
_, err := self.execute(http.MethodPost, fmt.Sprintf("/ns/%s/mcis/%s/nlb", self.Namespace, self.TargetGroup.MCIS), self, &NLBRes)
if err != nil {
return err
}
return nil
}
func (self *NLBReq) DELETE() (bool, error) {
exist, err := self.GET()
if err != nil {
return exist, err
}
if exist {
_, err := self.execute(http.MethodDelete, fmt.Sprintf("/ns/%s/mcis/%s/nlb", self.Namespace, self.TargetGroup.MCIS), fmt.Sprintf(`{"connectionName" : "%s"}`, self.Config), app.Status{})
if err != nil {
return exist, err
}
}
return exist, nil
}