blob: 5fe7ad2009c5292bbcb0b25fda62b9a3b470a1e1 [file] [log] [blame]
Srikanth Vavilapalli1725e492014-12-01 17:50:52 -08001#
2# Copyright (c) 2010,2011,2012,2013 Big Switch Networks, Inc.
3#
4# Licensed under the Eclipse Public License, Version 1.0 (the
5# "License"); you may not use this file except in compliance with the
6# License. You may obtain a copy of the License at
7#
8# http://www.eclipse.org/legal/epl-v10.html
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied. See the License for the specific language governing
14# permissions and limitations under the License.
15#
16"""
17import command
18
19INTERNAL_SUBMODE_COMMAND_DESCRIPTION = {
20 'name' : 'internal',
21 'mode' : 'config',
22 'no-supported' : False,
23 'help' : 'Enter Internal CLI debugging mode',
24 'short-help' : 'Enter CLI internal debugging mode',
25 'doc' : 'internal|internal',
26 'doc-example' : 'internal|internal-example',
27 'command-type' : 'config-submode',
28 'obj-type' : None,
29 'current-mode-obj-id' : None,
30 'parent-field' : None,
31 'submode-name' : 'config-internal',
32 'args' : (),
33}
34
35INTERNAL_SHOW_INTERFACES_COMMAND_DESCRIPTION = {
36 'name' : 'show',
37 'mode' : 'config-internal',
38 'no-supported' : False,
39 'short-help' : 'Show system interfaces',
40 'doc' : 'internal|show-interfaces',
41 'doc-example' : 'internal|show-interfaces-example',
42 'args' : (
43 'system',
44 {
45 'token' : 'interfaces',
46 'action' : 'display-rest' ,
47 'url' : 'system/interfaces/',
48 'format' : 'system-interfaces',
49 },
50 {
51 'field' : 'detail',
52 'type' : 'enum',
53 'values' : ('details','brief'),
54 'optional' : True,
55 'doc' : 'format|+'
56 }
57 )
58}
59DEBUG_INTERNAL_TOPOLOGY_COMMAND_DESCRIPTION = {
60 'name' : 'internal',
61 'mode' : 'config-internal',
62 'command-type' : 'display-rest',
63 'url' : [
64 'internal-debugs/topology-manager/%(dpid)s',
65 'internal-debugs/topology-manager/',
66 ],
67 'format' : 'switch',
68 'short-help' : 'internal topology display',
69 'doc' : 'internal|internal-topology',
70 'args' : (
71 'topology',
72 {
73 'choices' : (
74 {
75 'field' : 'dpid',
76 'type' : 'dpid',
77 'optional' : 'true',
78 },
79 )
80 }
81 )
82}
83
84DEBUG_INTERNAL_CLUSTER_COMMAND_DESCRIPTION = {
85 'name' : 'internal',
86 'mode' : 'config-internal',
87 'command-type' : 'display-rest',
88 'url' : 'realtimestatus/network/cluster',
89 'format' : 'switch',
90 'short-help' : 'internal switch cluster display',
91 'args' : (
92 'cluster',
93 )
94}
95
96
97SHOW_VNS_ACCESS_LIST_ENTRY_COMMAND_DESCRIPTION = {
98 'name' : 'show',
99 'obj-type' : 'vns-access-list-entry',
100 'short-help' : 'Show vns-access-list-entry db table',
101 'doc' : 'internal|show-vns-access-list-entry',
102 'mode' : 'config-internal',
103 'command-type' : 'display-table',
104 'args' : (
105 'vns-access-list-entry',
106 {
107 'optional' : True,
108 'field' : 'vns',
109 'type' : 'identifier',
110 'completion' : 'complete-from-another',
111 'other' : 'vns-definition',
112 'help-name' : "<vns-id>",
113 'detail' : 'default',
114 },
115 {
116 'optional' : True,
117 'field' : 'acl',
118 'tag' : 'acl',
119 },
120 {
121 'optional' : True,
122 'field' : 'rule',
123 'tag' : 'rule',
124 },
125 )
126}
127
128
129SHOW_PORT_COMMAND_DESCRIPTION = {
130 'name' : 'show',
131 'obj-type' : 'port',
132 'short-help' : 'Show port db table',
133 'doc' : 'internal|show-port',
134 'mode' : 'config-internal',
135 'command-type' : 'display-table',
136 'args' : (
137 'port',
138 {
139 'field' : 'id',
140 'optional' : True,
141 'type' : 'obj-type',
142 'completion' : 'complete-object-field',
143 'parent-id' : None,
144 },
145 {
146 'field' : 'dpid',
147 'optional' : True,
148 'tag' : 'switch',
149 'completion' : 'complete-from-another',
150 'other' : 'switches',
151 'data-handler' : 'alias-to-value',
152 },
153 {
154 'field' : 'number',
155 'tag' : 'port',
156 'optional' : True,
157 'completion' : 'complete-object-field',
158 },
159 {
160 'field' : 'detail',
161 'optional' : True,
162 'type' : 'enum',
163 'values' : ('details', 'brief'),
164 }
165 )
166}
167
168
169SHOW_VNS_INTERFACE_COMMAND_DESCRIPTION = {
170 'name' : 'show',
171 'obj-type' : 'vns-interface',
172 'short-help' : 'Show vns-interface db table',
173 'doc' : 'internal|show-vns-interface',
174 'mode' : 'config-internal',
175 'command-type' : 'display-table',
176 'args' : (
177 'vns-interface',
178 {
179 'field' : 'id',
180 'tag' : 'vns',
181 'type' : 'string',
182 'optional' : True,
183 'parent-id' : 'vns',
184 'completion' : 'complete-object-field',
185 },
186 {
187 'field' : 'switch',
188 'tag' : 'switch',
189 'type' : 'dpid',
190 'optional' : True,
191 },
192 {
193 'field' : 'number',
194 'tag' : 'number',
195 'type' : 'integer',
196 'help-name' : 'OF Port Number',
197 'optional' : True,
198 },
199 )
200}
201
202
203SHOW_VNS_INTERFACE_RULE_COMMAND_DESCRIPTION = {
204 'name' : 'show',
205 'obj-type' : 'vns-interface-rule',
206 'short-help' : 'Show vns-interface-rule db table',
207 'doc' : 'internal|show-vns-interface-rule',
208 'mode' : 'config-internal',
209 'command-type' : 'display-table',
210 'args' : (
211 'vns-interface-rule',
212 {
213 'field' : 'vns',
214 'tag' : 'vns',
215 'optional' : True,
216 'type' : 'string',
217 'parent-id' : 'vns',
218 'completion' : 'complete-object-field',
219 },
220 {
221 'field' : 'rule',
222 'tag' : 'rule',
223 'type' : 'string',
224 'optional' : True,
225 'completion' : 'complete-object-field',
226 },
227 )
228}
229
230
231INTERNAL_SHOW_DEVICE_COMMAND_DESCRIPTION = {
232 'name' : 'show',
233 'mode' : 'config-internal',
234 'no-supported' : False,
235 'short-help' : 'Show controller devices',
236 'doc' : 'internal|show-controller-devices',
237 'args' : (
238 'controller',
239 {
240 'choices' : (
241 {
242 'token' : 'devices',
243 'action' : 'display-rest' ,
244 'url' : 'device',
245 'format' : 'controller-devices',
246 },
247 (
248 {
249 'token' : 'vns',
250 'action' : 'display-rest' ,
251 'url' : 'vns',
252 'format' : 'controller-vns',
253 },
254 {
255 'optional' : True,
256 'choices' : (
257 {
258 'token' : 'interfaces',
259 'optional' : True,
260 'action' : 'display-rest' ,
261 'url' : 'vns/interface',
262 'format' : 'controller-vns-interfaces',
263 },
264 {
265 'token' : 'device-interfaces',
266 'optional' : True,
267 'action' : 'display-rest' ,
268 'url' : 'vns/device-interface',
269 'format' : 'controller-vns-device-interface',
270 },
271 )
272 },
273 ),
274 )
275 },
276 {
277 'field' : 'detail',
278 'type' : 'enum',
279 'values' : ('details','brief'),
280 'optional' : True,
281 }
282 )
283}
284
285
286def display_schema(data):
287 return command.sdnsh.sdndb.schema_detail(data['path'])
288
289command.add_action('display-schema', display_schema,
290 {'kwargs' : { 'data' : '$data' } } )
291
292INTERNAL_SHOW_SCHEMA_COMMAND_DESCRIPTION = {
293 'name' : 'show',
294 'mode' : 'config-internal',
295 'feature' : 'experimental',
296 'no-supported' : False,
297 'short-help' : 'Show controller devices',
298 'action' : 'display-schema',
299 'args' : (
300 'schema',
301 {
302 'field' : 'path',
303 'type' : 'string',
304 },
305 ),
306}
307
308
309def lint_action(data):
310 words = []
311 if 'command' in data:
312 words.append(data['command'])
313 command.lint_command(words)
314
315command.add_action('lint-action', lint_action,
316 {'kwargs' : { 'data' : '$data' } } )
317
318INTERNAL_LINT_COMMAND_DESCRIPTION = {
319 'name' : 'lint',
320 'mode' : 'config-internal',
321 'no-supported' : False,
322 'action' : 'lint-action',
323 'args' : {
324 'optional' : True,
325 'field' : 'command',
326 'type' : 'string',
327 }
328}
329
330
331def permute_action(data):
332 words = []
333 if 'command' in data:
334 words.append(data['command'])
335 return command.permute_command(words, data.get('qualify'))
336
337command.add_action('permute-action', permute_action,
338 {'kwargs' : { 'data' : '$data' } } )
339
340
341INTERNAL_PERMUTE_COMMAND_DESCRIPTION = {
342 'name' : 'permute',
343 'mode' : 'config-internal',
344 'no-supported' : False,
345 'action' : 'permute-action',
346 'data' : { 'qualify' : False },
347 'args' : (
348 {
349 'optional' : True,
350 'field' : 'command',
351 'type' : 'string',
352 },
353 )
354}
355
356
357INTERNAL_QUALIFY_COMMAND_DESCRIPTION = {
358 'name' : 'qualify', # berate
359 'mode' : 'config-internal',
360 'no-supported' : False,
361 'action' : 'permute-action',
362 'data' : { 'qualify' : True },
363 'args' : (
364 {
365 'optional' : True,
366 'field' : 'command',
367 'type' : 'string',
368 },
369 )
370}
371
372
373def clidoc_action(data):
374 words = []
375 if 'command' in data:
376 words.append(data['command'])
377 return command.get_clidoc(words)
378
379command.add_action('clidoc-action', clidoc_action,
380 {'kwargs' : { 'data' : '$data' }, } )
381
382
383INTERNAL_CLIDOC_COMMAND_DESCRIPTION = {
384 'name' : 'clidoc',
385 'mode' : 'config-internal',
386 'no-supported' : False,
387 'action' : 'clidoc-action',
388 'args' : {
389 'optional' : True,
390 'field' : 'command',
391 'type' : 'string',
392 }
393}
394
395def cliwiki_action(data):
396 words = []
397 if 'command' in data:
398 words.append(data['command'])
399 return command.get_cliwiki(words)
400
401command.add_action('cliwiki-action', cliwiki_action,
402 {'kwargs' : { 'data' : '$data' }, } )
403INTERNAL_CLIWIKI_COMMAND_DESCRIPTION = {
404 'name' : 'cliwiki',
405 'mode' : 'config-internal',
406 'no-supported' : False,
407 'action' : 'cliwiki-action',
408 'args' : {
409 'optional' : True,
410 'field' : 'command',
411 'type' : 'string',
412 }
413}
414
415SHOW_CLI_COMMAND_DESCRIPTION = {
416 'name' : 'show',
417 'mode' : 'config-internal',
418 'short-help' : 'Show CLI details',
419 'doc' : 'internal|show-cli',
420 'action' : 'display-cli',
421 'no-supported' : False,
422 'args' : (
423 'cli',
424 {
425 'optional' : True,
426 'field' : 'detail',
427 'type' : 'enum',
428 'values' : ('details'),
429 },
430 )
431}
432
433
434#
435# FORMATS
436#
437
438import fmtcnv
439
440
441SYSTEM_INTERFACES_FORMAT = {
442 'system-interfaces' : {
443 'field-orderings': {
444 'default' : [
445 'Idx',
446 # 'name',
447 'addr',
448 'netmask',
449 'broadcast',
450 # 'peer',
451 ],
452 'details' : [
453 'Idx',
454 'name',
455 'addr',
456 'netmask',
457 'broadcast',
458 'peer',
459 ],
460 'brief' : [
461 'Idx',
462 'addr',
463 ]
464 },
465 'fields' : {
466 'name' : {
467 'verbose-name' : 'IF Name',
468 },
469 'addr' : {
470 'verbose-name' : 'IP Address',
471 },
472 'peer' : {
473 },
474 'netmask' : {
475 },
476 'broadcast' : {
477 },
478 }
479 },
480}
481
482
483PORT_FORMAT = {
484 'port' : {
485 'field-orderings' : {
486 'default' : [ 'Idx', 'switch', 'number', 'name', 'hardware-address',
487 'config', 'state', 'current-features',
488 'advertised-features', 'supported-features', 'peer-features' ],
489 },
490 'fields' : {
491 'switch' : { 'formatter' : fmtcnv.replace_switch_with_alias
492 },
493 'number' : { 'formatter' : fmtcnv.decode_openflow_port
494 },
495 'config' : { 'formatter' : fmtcnv.decode_port_config
496 },
497 'state' : { 'formatter' : fmtcnv.decode_port_state
498 },
499 'current-features' : { 'formatter' : fmtcnv.decode_port_features
500 },
501 'advertised-features' : { 'formatter' : fmtcnv.decode_port_features
502 },
503 'supported-features' : { 'formatter' : fmtcnv.decode_port_features
504 },
505 'peer-features' : { 'formatter' : fmtcnv.decode_port_features
506 },
507 }
508 },
509}
510
511
512CONTROLLER_VNS_FORMAT = {
513 'controller-vns' : {
514 'field-orderings' : {
515 'default' : [ 'Idx',
516 'name',
517 'active',
518 'priority',
519 'arpManagerMode',
520 'broadcastMode',
521 'dhcpManagerMode',
522 'dhcpIp',
523 ],
524 },
525 'fields' : {
526 'name' : {
527 'verbose-name' : 'Name',
528 },
529 'active' : {
530 'verbose-name' : 'Active',
531 },
532 'priority' : {
533 'verbose-name' : 'Priority',
534 },
535 'arpManagerMode' : {
536 'verbose-name' : 'Arp Mode',
537 },
538 'broadcastMode' : {
539 'verbose-name' : 'Broadcast Mode',
540 },
541 'dhcpManagerMode' : {
542 'verbose-name' : 'Dhcp Modd',
543 },
544 'dhcpIp' : {
545 'verbose-name' : 'dhcpIp',
546 },
547 },
548 },
549}
550
551
552CONTROLLER_VNS_INTERFACES = {
553 'controller-vns-interfaces' : {
554 'field-orderings' : {
555 'default' : [ 'Idx',
556 ],
557 },
558 },
559}
560
561
562CONTROLLER_VNS_DEFICE_INTERFACES = {
563 'controller-vns-device-interfaces' : {
564 'field-orderings' : {
565 'default' : [ 'Idx',
566 'device',
567 'iface',
568 ],
569 },
570 },
571}
572
573
574CONTROLLER_DEVICES_FORMAT = {
575 'controller-devices' : {
576 'field-orderings' : {
577 'default' : [ 'Idx',
578 'mac',
579 'attachment-point',
580 'ipv4',
581 'vlan',
582 ]
583 },
584
585 'fields' : {
586 'mac' : {
587 'verbose-name' : 'MAC Address',
588 'formatter' : fmtcnv.convert_to_string,
589 },
590 'ipv4' : {
591 'verbose-name' : 'IP Address',
592 'formatter' : fmtcnv.convert_to_string,
593 },
594 'attachment-point' : {
595 'verbose-name' : 'Attachment Point',
596 'formatter' : fmtcnv.convert_to_string,
597 },
598 'vlan' : {
599 'verbose-name' : 'Vlans',
600 'formatter' : fmtcnv.convert_to_string,
601 },
602 },
603 },
604}
605
606DEVICEMANAGER_DEVICE_FORMAT = {
607 'devicemanager-device' : {
608 'field-orderings' : {
609 'default' : [
610 'Idx',
611 'host',
612 'attachment-points',
613 'network-addresses'
614 ]
615 },
616
617 'fields' : {
618 'host' : { 'formatter' : fmtcnv.print_host_and_alias,
619 },
620 'attachment-points' : {
621 'verbose-name' : 'Attachment Point',
622 'formatter' : fmtcnv.print_devicemanager_attachment_points,
623 },
624 'network-addresses' : {
625 'verbose-name' : 'IP Address',
626 'formatter' : fmtcnv.print_devicemanager_ip_addresses,
627 },
628
629 },
630 },
631}
632
633
634CLI_FORMAT = {
635 'cli' : {
636 'field-orderings' : {
637 'default' : [
638 'version',
639 'debug',
640 'desc'
641 'format',
642 'modes',
643 ]
644 },
645
646 'fields' : {
647 'version' : { 'verbose-name' : 'Syntax Version',
648 },
649 'debug' : { 'verbose-name' : 'Debug Level',
650 },
651 'desc' : { 'verbose-name' : 'Desc Modules',
652 },
653 'format' : { 'verbose-name' : 'Format Modules',
654 },
655 'modes' : { 'verbose-name' : 'Submodes',
656 },
657 },
658 },
659}
660
661CLI_MODES_FORMAT = {
662 'cli-modes' : {
663 'field-orderings' : {
664 'default' : [ 'Idx', 'mode', 'command', 'submode',
665 ]
666 }
667 },
668}
669"""