This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Request.go
123 lines (104 loc) · 3.75 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
123
package nic
import (
cblog "github.com/cloud-barista/cb-log"
"github.com/cloud-barista/poc-cicd-spider/cloud-control-manager/cloud-driver/drivers/cloudit/client"
"github.com/cloud-barista/poc-cicd-spider/cloud-control-manager/cloud-driver/drivers/cloudit/client/iam/securitygroup"
"github.com/sirupsen/logrus"
)
var cblogger *logrus.Logger
func init() {
// cblog is a global variable.
cblogger = cblog.GetLogger("CB-SPIDER")
}
type VNicReqInfo struct {
SubnetAddr string `json:"subnetAddr" required:"true"`
VmId string `json:"vmId" required:"true"`
Type string `json:"type" required:"true"`
Secgroups []securitygroup.SecurityGroupRules `json:"secgroups" required:"true"`
IP string `json:"ip" required:"true"`
}
type VmNicInfo struct {
TenantId string
VmId string
Type string
Mac string
Dev string
Ip string
SubnetAddr string
Creator string
CreatedAt string
VmName string
NetworkName string
AdaptiveIp string
State string
Template string
SpecName string
CpuNum string
MemSize string
VolumeSize string
Qos int
SecGroups []SecurityGroupInfo `json:"secgroupMapInfo"`
AdaptiveMapInfo interface{}
}
type SecurityGroupInfo struct {
Id string `json:"secgroup_id"`
Name string
TenantId string `json:"tenant_id"`
State string
Mac string
Protection int
}
func List(restClient *client.RestClient, serverId string, requestOpts *client.RequestOpts) (*[]VmNicInfo, error) {
requestURL := restClient.CreateRequestBaseURL(client.ACE, "servers", serverId, "nics")
cblogger.Info(requestURL)
var result client.Result
if _, result.Err = restClient.Get(requestURL, &result.Body, requestOpts); result.Err != nil {
return nil, result.Err
}
var nic []VmNicInfo
if err := result.ExtractInto(&nic); err != nil {
return nil, err
}
return &nic, nil
}
func Get(restClient *client.RestClient, serverId string, macAddr string, requestOpts *client.RequestOpts) (*VmNicInfo, error) {
requestURL := restClient.CreateRequestBaseURL(client.ACE, "servers", serverId, "nics", macAddr)
cblogger.Info(requestURL)
var result client.Result
if _, result.Err = restClient.Get(requestURL, &result.Body, requestOpts); result.Err != nil {
return nil, result.Err
}
var nic VmNicInfo
if err := result.ExtractInto(&nic); err != nil {
return nil, err
}
return &nic, nil
}
func Create(restClient *client.RestClient, serverId string, requestOpts *client.RequestOpts) (*VmNicInfo, error) {
requestURL := restClient.CreateRequestBaseURL(client.ACE, "servers", serverId, "nics")
var result client.Result
if _, result.Err = restClient.Post(requestURL, nil, &result.Body, requestOpts); result.Err != nil {
return nil, result.Err
}
var nicInfo VmNicInfo
if err := result.ExtractInto(&nicInfo); err != nil {
return nil, err
} else {
return &nicInfo, nil
}
}
func Delete(restClient *client.RestClient, serverId string, macAddr string, requestOpts *client.RequestOpts) error {
requestURL := restClient.CreateRequestBaseURL(client.ACE, "servers", serverId, "nics", macAddr)
var result client.Result
if _, result.Err = restClient.Delete(requestURL, requestOpts); result.Err != nil {
return result.Err
}
return nil
}
// updateNIC
func Put(restClient *client.RestClient, serverId string, requestOpts *client.RequestOpts, nicMac string) {
requestURL := restClient.CreateRequestBaseURL(client.ACE, "servers", serverId, "nic", nicMac, "securitygroup")
cblogger.Info(requestURL)
var result client.Result
_, _ = restClient.Put(requestURL, nil, &result.Body, requestOpts)
}