-
Notifications
You must be signed in to change notification settings - Fork 1
/
vtn_terminal.js
339 lines (282 loc) · 10.1 KB
/
vtn_terminal.js
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
var vtn_terminal = null; // VTN terminal object
var vtn_cli_help = {}; // Help for commands
var term_cfg = {
prompt: 'VTN > ',
greetings: 'ODL VTN Coordinator CLI\n\r-----------------------',
outputLimit: 0
};
// IP address of the ODL conroller
var ODL_IP_addr = (getCookie("odl_vtn_coordinator_addr") == null) ? '127.0.0.1' : getCookie("odl_vtn_coordinator_addr");
// Base URI for VTN coodinator RESTfull API
var vtn_coord_base_URI = 'http://' + ODL_IP_addr + ':8080';
// HTTP request custom headers for VTN Coordinators
var vtn_coord_hdr = {
'content-type': 'application/json',
'username': 'admin',
'password': 'adminpass',
'ipaddr': vtn_coord_base_URI
};
if (ODL_DEMO == false) {
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/controllers.json',
type: 'GET',
dataType: 'json',
headers: vtn_coord_hdr
}).done(function( data ) {
set_serv_state("VTN", true);
});
}
vtn_cli_help.echo = "Sample echo function: echo [string]";
function vtn_echo(parm1) {
vtn_terminal.echo(parm1);
}
vtn_cli_help.set_co = "Set VTN Coordinator IP: set_co [IP address]";
function vtn_set_coord(param) {
ODL_IP_addr = param;
vtn_coord_base_URI = 'http://' + ODL_IP_addr + ':8080';
vtn_coord_hdr = {
'content-type': 'application/json',
'username': 'admin',
'password': 'adminpass',
'ipaddr': vtn_coord_base_URI
};
setCookie("odl_vtn_coordinator_addr", param, "Mon, 01-Jan-2100 00:00:00 GMT", "/");
if (ODL_DEMO == false) {
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/controllers.json',
type: 'GET',
dataType: 'json',
headers: vtn_coord_hdr
}).done(function( data ) {
set_serv_state("VTN", true);
});
}
location.reload();
}
vtn_cli_help.set_demo = "Set demo mode: set_demo [true|false]";
function vtn_set_demo(param) {
ODL_DEMO = (param == "true");
setCookie("odl_vtn_coordinator_demo", param, "Mon, 01-Jan-2100 00:00:00 GMT", "/");
location.reload();
}
vtn_cli_help.lst_ctls = "List controllers: lst_ctls";
function vtn_list_ctls() {
if (ODL_DEMO == true) return;
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/controllers.json',
type: 'GET',
dataType: 'json',
headers: vtn_coord_hdr
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
set_serv_state("VTN", true);
}).fail(function() {
set_serv_state("VTN", false);
});
}
// curl -v -X POST -H 'content-type: application/json' -H 'username: admin' -H 'password: adminpass' -H 'ipaddr:172.20.6.157' -d '{"controller": {"controller_id": "controller_1", "ipaddr":"172.20.6.158", "type": "odc", "version": "1.0", "auditstatus":"enable"}}' http://172.20.6.157:8080/vtn-webapi/controllers.json
vtn_cli_help.crt_ctl = "Create Controller: crt_ctl [controller_id] [IP address]";
function vtn_crt_ctl(param1, param2) {
var post_data = JSON.stringify({
controller: {
controller_id: param1,
ipaddr: param2,
type: 'odc',
version: '1.0',
auditstatus: 'enable'
}
});
ODL_ADDR = param2;
setCookie("odl_addr", param2, "Mon, 01-Jan-2100 00:00:00 GMT", "/");
if (ODL_DEMO == false) {
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/controllers.json',
type: 'POST',
dataType: 'json',
headers: vtn_coord_hdr,
processData: false,
data: post_data
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
});
}
location.reload();
}
// curl -X DELETE -H 'content-type: application/json' -H 'username: admin' -H 'password: adminpass' -H 'ipaddr:172.20.6.157' http://172.20.6.157:8080/vtn-webapi/controllers/controller_1.json
vtn_cli_help.dlt_ctl = "Delete Controller: dlt_ctl [controller_id]";
function vtn_dlt_ctl(param1) {
if (ODL_DEMO == true) return;
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/controllers/' + param1 +'.json',
type: 'DELETE',
dataType: 'json',
headers: vtn_coord_hdr
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
location.reload();
});
}
// curl -v -X POST -H 'content-type: application/json' -H 'username: admin' -H 'password: adminpass' -H 'ipaddr:172.20.6.157' -d '{"vtn" : {"vtn_name":"vtn1","description":"test VTN" }}' http://172.20.6.157:8080/vtn-webapi/vtns.json
vtn_cli_help.crt_vtn = "Create a VTN: crt_vtn [VTN name] [description]";
function vtn_crt_vtn(param1, param2) {
var post_data = JSON.stringify({
vtn: {
vtn_name: param1,
description: param2
}
});
if (ODL_DEMO == true) return;
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/vtns.json',
type: 'POST',
dataType: 'json',
headers: vtn_coord_hdr,
processData: false,
data: post_data
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
});
}
// curl -X GET -H 'content-type: application/json' -H 'username: admin' -H 'password: adminpass' -H 'ipaddr:172.20.6.157' http://172.20.6.157:8080/vtn-webapi/vtns.json
vtn_cli_help.lst_vtns = "List VTNs: lst_vtn";
function vtn_list_vtns() {
if (ODL_DEMO == true) return;
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/vtns.json',
type: 'GET',
dataType: 'json',
headers: vtn_coord_hdr
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
});
}
//curl -v -X POST -H 'content-type: application/json' -H 'username: admin' -H 'password: adminpass' -H 'ipaddr:172.20.6.157' -d '{"vbridge" : {"vbr_name":"vBridge1","controller_id":"controller_1","domain_id":"(DEFAULT)" }}' http://172.20.6.157:8080/vtn-webapi/vtns/vtn1/vbridges.json
vtn_cli_help.crt_vbr = "Create vBridge: crt_vbr [bridge name] [controller ID]";
function vtn_crt_vbr(param1, param2) {
var post_data = JSON.stringify({
vbridge: {
vbr_name: param1,
controller_id: param2,
domain_id: '(DEFAULT)'
}
});
if (ODL_DEMO == true) return;
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/vtns/vtn1/vbridges.json',
type: 'POST',
dataType: 'json',
headers: vtn_coord_hdr,
processData: false,
data: post_data
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
});
}
// curl -X GET -H 'content-type: application/json' -H 'username: admin' -H 'password: adminpass' -H 'ipaddr:172.20.6.157' http://172.20.6.157:8080/vtn-webapi/vtns/vtn1/vbridges.json
vtn_cli_help.lst_vbrs = "List vBridges: lst_vbrs";
function vtn_list_vbrs() {
if (ODL_DEMO == true) return;
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/vtns/vtn1/vbridges.json',
type: 'GET',
dataType: 'json',
headers: vtn_coord_hdr
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
});
}
// curl -v -X POST -H 'content-type: application/json' -H 'username: admin' -H 'password: adminpass' -H 'ipaddr:172.20.6.157' -d '{"interface": {"if_name": "if1","description": "if_desc1"}}' http://172.20.6.157:8080/vtn-webapi/vtns/vtn1/vbridges/vBridge1/interfaces.json
vtn_cli_help.crt_vbr_if = "Create Interface on vBridge: crt_vbr_if [VTN name] [bridge name] [interface name] [interface desccription]";
function vtn_crt_vbr_if(param1, param2, param3, param4) {
var post_data = JSON.stringify({
interface: {
if_name: param3,
description: param4
}
});
if (ODL_DEMO == true) return;
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/vtns/' + param1 + '/vbridges/' + param2 + '/interfaces.json',
type: 'POST',
dataType: 'json',
headers: vtn_coord_hdr,
processData: false,
data: post_data
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
});
}
// curl -X GET -H 'content-type: application/json' -H 'username: admin' -H 'password: adminpass' -H 'ipaddr:172.20.6.157' http://172.20.6.157:8080/vtn-webapi/vtns/vtn1/vbridges/vBridge1/interfaces.json
vtn_cli_help.lst_vbr_ifs = "List vBridge interfaces: lst_vbr_ifs [VTN name] [bridge name]";
function vtn_list_vbr_ifs(param1, param2) {
if (ODL_DEMO == true) return;
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/vtns/' + param1 + '/vbridges/' + param2 + '/interfaces.json',
type: 'GET',
dataType: 'json',
headers: vtn_coord_hdr
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
});
}
// curl -X GET -H 'content-type: application/json' -H 'username: admin' -H 'password: adminpass' -H 'ipaddr:172.20.6.157' http://172.20.6.157:8080/vtn-webapi/controllers/controller_1/domains/\(DEFAULT\)/logical_ports.json
vtn_cli_help.lst_lports = "List of logical ports configured: lst_lports [controller_id]";
function vtn_list_lports(param1) {
if (ODL_DEMO == true) return;
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/controllers/' + param1 +'/domains/\(DEFAULT\)/logical_ports.json',
type: 'GET',
dataType: 'json',
headers: vtn_coord_hdr
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
});
}
// curl -v -X PUT -H 'content-type: application/json' -H 'username: admin' -H 'password: adminpass' -H 'ipaddr:172.20.6.157' -d '{"portmap":{"logical_port_id": "PP-00:00:00:00:00:00:00:03-s3-eth1"}}' http://172.20.6.157:8080/vtn-webapi/vtns/vtn1/vbridges/vBridge1/interfaces/if1/portmap.json
vtn_cli_help.map_vif2lport = "Map vBridge virtual interfac to the controller's logical port: map_vif2lport [VTN name] [bridge name] [interface name] [lport ID]";
function vtn_map_vif2lport(param1, param2, param3, param4) {
var post_data = JSON.stringify({
portmap: {
logical_port_id: param4
}
});
if (ODL_DEMO == true) return;
$.ajax({
url: vtn_coord_base_URI + '/vtn-webapi/vtns/' + param1 + '/vbridges/' + param2 + '/interfaces/' + param3 + '/portmap.json',
type: 'PUT',
dataType: 'json',
headers: vtn_coord_hdr,
processData: false,
data: post_data
}).done(function( data ) {
vtn_terminal.echo(JSON.stringify(data));
location.reload();
});
}
vtn_cli_help.help = "Prints this help: help";
function vtn_help() {
for (var cmd in vtn_cli_commands) {
vtn_terminal.echo(cmd + "\t\t- " + vtn_cli_help[cmd]);
}
}
var vtn_cli_commands = {
help: vtn_help,
echo: vtn_echo,
set_co: vtn_set_coord,
set_demo: vtn_set_demo,
lst_ctls: vtn_list_ctls,
crt_ctl: vtn_crt_ctl,
dlt_ctl: vtn_dlt_ctl,
crt_vtn: vtn_crt_vtn,
lst_vtns: vtn_list_vtns,
crt_vbr: vtn_crt_vbr,
lst_vbrs: vtn_list_vbrs,
crt_vbr_if: vtn_crt_vbr_if,
lst_vbr_ifs: vtn_list_vbr_ifs,
lst_lports: vtn_list_lports,
map_vif2lport: vtn_map_vif2lport
};
// Init terminal object and attach it to #vtn_term ID
jQuery(document).ready(function($) {
vtn_terminal = $('#vtn_term').terminal(vtn_cli_commands, term_cfg);
});