-
Notifications
You must be signed in to change notification settings - Fork 1
/
vpc.go
74 lines (59 loc) · 1.76 KB
/
vpc.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
package tumblebug
import (
"fmt"
"net/http"
"github.com/cloud-barista/poc-cicd-ladybug/src/core/model"
logger "github.com/sirupsen/logrus"
)
type VPC struct {
Model
Config string `json:"connectionName"`
CidrBlock string `json:"cidrBlock"`
Subnets []Subnet `json:"subnetInfoList"`
Description string `json:"description"`
CspVNetId string `json:"cspVNetId"` // output
CspVNetName string `json:"cspVNetName"` // output
Status string `json:"status"` // output
KeyValueList []KeyValue `json:"keyValueList"` // output
}
type Subnet struct {
Name string `json:"Name"`
CidrBlock string `json:"IPv4_CIDR"`
}
func NewVPC(ns string, name string, conf string) *VPC {
return &VPC{
Model: Model{Name: name, namespace: ns},
Config: conf,
CidrBlock: "192.168.0.0/16",
Subnets: []Subnet{
{
Name: fmt.Sprintf("%s-subnet", name),
CidrBlock: "192.168.1.0/24"},
},
}
}
func (self *VPC) GET() (bool, error) {
return self.execute(http.MethodGet, fmt.Sprintf("/ns/%s/resources/vNet/%s", self.namespace, self.Name), fmt.Sprintf(`{"connectionName" : "%s"}`, self.Config), &self)
}
func (self *VPC) POST() error {
_, err := self.execute(http.MethodPost, fmt.Sprintf("/ns/%s/resources/vNet", self.namespace), self, &self)
if err != nil {
return err
}
return nil
}
func (self *VPC) DELETE() error {
exist, err := self.GET()
if err != nil {
return err
}
if exist {
_, err := self.execute(http.MethodDelete, fmt.Sprintf("/ns/%s/resources/vNet/%s", self.namespace, self.Name), fmt.Sprintf(`{"connectionName" : "%s"}`, self.Config), model.Status{})
if err != nil {
return err
}
} else {
logger.Infof("delete vpc skip.. (name=%s, cause=not found)", self.Name)
}
return nil
}