-
Notifications
You must be signed in to change notification settings - Fork 1
/
tvm.go
56 lines (41 loc) · 1.04 KB
/
tvm.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
package tumblebug
import (
"fmt"
"net/http"
"github.com/cloud-barista/poc-cicd-ladybug/src/core/model"
logger "github.com/sirupsen/logrus"
)
type TVM struct {
Model
VM model.VM
}
func NewTVm(ns string, mcisName string) *TVM {
return &TVM{
Model: Model{namespace: ns, Name: mcisName},
}
}
func (self *TVM) GET() (bool, error) {
return self.execute(http.MethodGet, fmt.Sprintf("/ns/%s/mcis/%s/vm/%s", self.namespace, self.Name, self.VM.Name), nil, &self.VM)
}
func (self *TVM) POST() error {
_, err := self.execute(http.MethodPost, fmt.Sprintf("/ns/%s/mcis/%s/vm", self.namespace, self.Name), self.VM, &self.VM)
if err != nil {
return err
}
return nil
}
func (self *TVM) DELETE() error {
exist, err := self.GET()
if err != nil {
return err
}
if exist {
_, err := self.execute(http.MethodDelete, fmt.Sprintf("/ns/%s/mcis/%s/vm/%s", self.namespace, self.Name, self.VM.Name), nil, model.Status{})
if err != nil {
return err
}
} else {
logger.Infof("delete VM skip (name=%s, cause=not found)", self.VM.Name)
}
return nil
}