-
Notifications
You must be signed in to change notification settings - Fork 47
/
Request.go
122 lines (101 loc) · 3.32 KB
/
Request.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
package adaptiveip
import (
//"fmt"
cblog "github.com/cloud-barista/cb-log"
"github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/cloudit/client"
"github.com/sirupsen/logrus"
)
var cblogger *logrus.Logger
func init() {
// cblog is a global variable.
cblogger = cblog.GetLogger("CB-SPIDER")
}
type PublicIPReqInfo struct {
IP string `json:"ip" required:"true"`
Name string `json:"name" required:"true"`
PrivateIP string `json:"privateIp" required:"true"` // PublicIP가 적용되는 VM의 Private IP
Protection int `json:"protection" required:"false"`
}
type IPInfo struct {
IP string `json:"addr"`
gateway string
prefix string
state string
netmask string
}
type AdaptiveIPInfo struct {
ID string
IP string
Name string
Rules interface{}
TenantId string
Creator string
State string
CreatedAt string
PrivateIp string
Protection int
RuleCount int
VmName string
Description string
}
func List(restClient *client.RestClient, requestOpts *client.RequestOpts) (*[]AdaptiveIPInfo, error) {
requestURL := restClient.CreateRequestBaseURL(client.DNA, "adaptive-ips")
cblogger.Info(requestURL)
var result client.Result
if _, result.Err = restClient.Get(requestURL, &result.Body, requestOpts); result.Err != nil {
return nil, result.Err
}
var adaptiveIP []AdaptiveIPInfo
if err := result.ExtractInto(&adaptiveIP); err != nil {
return nil, err
}
return &adaptiveIP, nil
}
func ListAvailableIP(restClient *client.RestClient, requestOpts *client.RequestOpts) (*[]IPInfo, error) {
requestURL := restClient.CreateRequestBaseURL(client.DNA, "ips")
cblogger.Info(requestURL)
var result client.Result
if _, result.Err = restClient.Get(requestURL, &result.Body, requestOpts); result.Err != nil {
return nil, result.Err
}
var availableIP []IPInfo
if err := result.ExtractInto(&availableIP); err != nil {
return nil, err
}
return &availableIP, nil
}
func Get(restClient *client.RestClient, adaptiveIPId string, requestOpts *client.RequestOpts) (*AdaptiveIPInfo, error) {
requestURL := restClient.CreateRequestBaseURL(client.DNA, "adaptive-ips", adaptiveIPId, "detail")
cblogger.Info(requestURL)
var result client.Result
if _, result.Err = restClient.Get(requestURL, &result.Body, requestOpts); result.Err != nil {
return nil, result.Err
}
var adaptiveIP AdaptiveIPInfo
if err := result.ExtractInto(&adaptiveIP); err != nil {
return nil, err
}
return &adaptiveIP, nil
}
func Create(restClient *client.RestClient, requestOpts *client.RequestOpts) (*AdaptiveIPInfo, error) {
requestURL := restClient.CreateRequestBaseURL(client.DNA, "adaptive-ips")
cblogger.Info(requestURL)
var result client.Result
if _, result.Err = restClient.Post(requestURL, nil, &result.Body, requestOpts); result.Err != nil {
return nil, result.Err
}
var adaptiveIP AdaptiveIPInfo
if err := result.ExtractInto(&adaptiveIP); err != nil {
return nil, err
}
return &adaptiveIP, nil
}
func Delete(restClient *client.RestClient, adaptiveIP string, requestOpts *client.RequestOpts) error {
requestURL := restClient.CreateRequestBaseURL(client.DNA, "adaptive-ips", adaptiveIP)
cblogger.Info(requestURL)
var result client.Result
if _, result.Err = restClient.Delete(requestURL, requestOpts); result.Err != nil {
return result.Err
}
return nil
}