-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
207 lines (157 loc) · 4.79 KB
/
main.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package main
import (
"fmt"
//"time"
pkg "github.com/cloud-club/Aviator-service/pkg"
auth "github.com/cloud-club/Aviator-service/types/auth"
types "github.com/cloud-club/Aviator-service/types/server"
)
func getImageProductList(ncp *pkg.NcpService) {
ncp.ServerImageProduct = pkg.NewImageProductService(&ncp.Key)
imageProductList, err := ncp.ServerImageProduct.Get(pkg.API_URL + pkg.GET_SERVER_IMAGE_PRODUCT_LIST_PATH)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(imageProductList)
}
func getProductList(ncp *pkg.NcpService) {
ncp.ServerProduct = pkg.NewProductService(&ncp.Key)
gpr := &types.GetProductRequest{ServerImageProductCode: "SW.VSVR.OS.LNX64.CNTOS.0703.B050"}
productList, err := ncp.ServerProduct.Get(pkg.API_URL+pkg.GET_SERVER_PRODUCT_LIST_PATH, gpr)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(productList)
}
func getNetworkInterfaceList(ncp *pkg.NcpService) {
ncp.Network = pkg.NewNetworkInterfaceService(&ncp.Key)
networkInterfaceList, err := ncp.Network.Get(pkg.API_URL + pkg.GET_NETWORKINTERFACE_LIST_PATH)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(networkInterfaceList)
}
func getAccessControlGroupList(ncp *pkg.NcpService) {
ncp.AccessControlGroup = pkg.NewAccessControlGroupService(&ncp.Key)
accessControlGroupList, err := ncp.AccessControlGroup.Get(pkg.API_URL + pkg.GET_ACG_LIST_PATH)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(accessControlGroupList)
}
func getSubnetList(ncp *pkg.NcpService) {
ncp.Subnet = pkg.NewSubnetService(&ncp.Key)
subnetList, err := ncp.Subnet.Get(pkg.VPC_API_URL + pkg.GET_SUBNET_LIST_PATH)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(subnetList)
}
func getVpcList(ncp *pkg.NcpService) {
ncp.Vpc = pkg.NewVpcService(&ncp.Key)
vpcList, err := ncp.Vpc.Get(pkg.VPC_API_URL + pkg.GET_VPC_LIST)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(vpcList)
}
func create(ncp *pkg.NcpService) {
csr := &types.CreateServerRequest{ServerImageProductCode: "SW.VSVR.OS.LNX64.CNTOS.0703.B050", VpcNo: "52833", SubnetNo: "120320", NetworkInterfaceOrder: 0, AccessControlGroupNoListN: "148207", ServerProductCode: "SVR.VSVR.HICPU.C002.M004.NET.HDD.B050.G002"}
response, err := ncp.Server.Create(pkg.API_URL+pkg.CREATE_SERVER_INSTANCE_PATH, csr, []int{1, 1})
if err != nil {
fmt.Println(err)
return
}
//Print response
fmt.Println(response)
}
func stop(ncp *pkg.NcpService) {
ssr := &types.StopServerRequest{ServerNo: "21741451"}
stopServerResponse, err := ncp.Server.Stop(pkg.API_URL+pkg.STOP_SERVER_INSTANCE_PATH, ssr)
if err != nil {
fmt.Println(err)
return
}
//Print response
fmt.Println(stopServerResponse)
}
func list(ncp *pkg.NcpService) {
lsr := &types.ListServerRequest{RegionCode: "KR"}
serverListResponse, err := ncp.Server.List(pkg.API_URL+pkg.GET_SERVER_INSTANCE_PATH, lsr)
if err != nil {
fmt.Println(err)
return
}
//Print response
fmt.Println(serverListResponse)
// fmt.Println("server: ", serverListResponse.ServerInstanceList[0])
// fmt.Println("status: ", serverListResponse.ServerInstanceList[0].ServerInstanceStatus.Code)
}
func update(ncp *pkg.NcpService) {
usr := &types.UpdateServerRequest{ServerInstanceNo: "21741451", ServerProductCode: "SVR.VSVR.STAND.C032.M128.NET.HDD.B050.G002"}
updateServerResponse, err := ncp.Server.Update(pkg.API_URL+pkg.UPDATE_SERVER_INSTANCE_PATH, usr)
if err != nil {
fmt.Println(err)
return
}
//Print response
fmt.Println(updateServerResponse)
}
func delete(ncp *pkg.NcpService) {
dsr := &types.DeleteServerRequest{ServerNo: "21741451"}
deleteServerResponse, err := ncp.Server.Delete(pkg.API_URL+pkg.DELETE_SERVER_INSTANCE_PATH, dsr)
if err != nil {
fmt.Println(err)
return
}
//Print response
fmt.Println(deleteServerResponse)
}
func start(ncp *pkg.NcpService) {
ssr := &types.StartServerRequest{ServerNo: "21763788"}
_, err := ncp.Server.Start(pkg.API_URL+pkg.START_SERVER_INSTANCE_PATH, ssr)
if err != nil {
fmt.Println(err)
return
}
}
func main() {
ncp := pkg.NewNcpService("ncp service token")
ncp.Key = *auth.NewKeyService("6CmrDJ4KaswJ10g25GEP", "OvZ7QHH0Bi3AwGn5rlsD7xoC986bEOiIjdbwMFCo")
ncp.Server = pkg.NewServerService(&ncp.Key)
// Check image product list
getImageProductList(ncp)
// Check product list
getProductList(ncp)
// Get network interface list
getNetworkInterfaceList(ncp)
// Get access control group list
getAccessControlGroupList(ncp)
// Get subnet list
getSubnetList(ncp)
// Get VPC list
getVpcList(ncp)
list(ncp)
// Create server instance
//create(ncp)
//6. Get server instance list
//list(ncp)
// 7. Stop server instance
//stop(ncp)
// list(ncp)
// Start server instance
// start(ncp)
// list(ncp)
// Update server instance
// update(ncp)
// time.Sleep(20 * time.Second)
// list(ncp)
// // Terminate server instance
// delete(ncp)
}