blob: 8ea1f19b4519a76fd89223e49595915b3fbd5741 [file] [log] [blame]
Srikanth Vavilapalli1725e492014-12-01 17:50:52 -08001#
2# Copyright (c) 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
18import fmtcnv
19'''
20def vns_origin_external(data):
21 """
22 Return origin-name when the vns wasn't created by the cli,
23 return None otherwise.
24 """
25 pk = command.mi.pk('vns-definition')
26 if not pk in data:
27 return;
28
29 vns = command.sdnsh.get_table_from_store('vns-definition',
30 pk,
31 data[pk])
32 if len(vns) == 0:
33 return None
34
35 local = ['cli', 'rest']
36 if 'origin' in vns[0] and not vns[0]['origin'] in local:
37 return vns[0]['origin']
38 return None
39
40
41def vns_warn_external_config(data):
42 """
43 From the named vns, look up the entry, if it exists in the
44 database, validate the 'origin' is either null, or 'cli',
45 otherwise provide a warning about this particular vns
46 (along with the originator name)
47 """
48 external_origin = vns_origin_external(data)
49 if external_origin:
50 command.sdnsh.warning('vns %s may not be intended for cli update, '
51 'origin/creator "%s" ' % (data['id'], external_origin))
52
53command.add_action('vns-warn-external-config', vns_warn_external_config,
54 {'kwargs': {'data' : '$data',}})
55
56def complete_tenantname_preprocess(data):
57 data['tenant']='default'
58 if 'name' in data:
59 data['tenant']= data['name']
60 del data['name']
61 else:
62 current_mode=command.sdnsh.current_mode()
63 if not current_mode.startswith('config-tenant'):
64 data['tenant']='default'
65 if current_mode.startswith('config-tenant'):
66 for x in command.sdnsh.mode_stack:
67 if x['mode_name'] == 'config-tenant':
68 data['tenant'] = x['obj']
69
70
71command.add_completion('complete-tenantname-preprocess', complete_tenantname_preprocess,
72 {'kwargs': {'data': '$data',
73 }})
74
75def vns_confirm_external_delete(data):
76 """
77 From the named vns, look up the entry, if it exists in the
78 database, validate the 'origin' is either null, or 'cli',
79 otherwise provide a warning about this particular vns
80 (along with the originator name)
81 """
82 external_origin = vns_origin_external(data)
83 if external_origin:
84 confirm = command.action_registry['confirm'][0] # XXX accessor?
85 confirm('vns %s may not be intended for cli delete, '
86 'origin/creator "%s"\nEnter y or yes to continue delete: '
87 % (data['id'], external_origin))
88
89command.add_action('vns-confirm-external-delete', vns_confirm_external_delete,
90 {'kwargs': {'data' : '$data',}})
91
92command.add_action('vns-confirm-external-delete', vns_confirm_external_delete,
93 {'kwargs': {'data' : '$data',}})
94'''
95"""
96#
97# ----------------------------------------------------------------------
98# vns-definition submode commands
99#
100
101# notice the submode is called 'config-def-vns', this was
102# changed from 'config-vns-def' so that the vns submode,
103# which is called 'config-vns', wouldn't be a string-prefix
104# submode of config-vns. Various command, such as the
105# vns-submode access-list command were showing up in the
106# vns-definition submode due to this prefixing.
107
108VNS_DEFINITION_COMMAND_DESCRIPTION = {
109 'name' : 'vns-definition',
110 'help' : 'Enter VNS definition submode',
111 'mode' : 'config*',
112 'command-type' : 'config-submode',
113 'obj-type' : 'vns-definition',
114 'submode-name' : 'config-tenant-def-vns',
115 'feature' : 'vns',
116 'short-help' : 'Enter VNS definition submode',
117 'doc' : 'vns|vns-definition',
118 'doc-example' : 'vns|vns-definition-example',
119 'args' : (
120 {
121 'field' : 'vnsname',
122 'type' : 'identifier',
123 'completion' : ['complete-tenantname-preprocess',
124 'complete-object-field'],
125 'other' : 'vns-definition|vnsname',
126# 'scoped' : 'tenant',
127 'syntax-help' : 'Enter a vns name',
128 'doc' : 'vns|vns-id',
129 'doc-example' : 'vns|vns-id-example',
130 'doc-include' : [ 'type-doc' ],
131 'action' : (
132 {
133 'proc' : 'vns-warn-external-config',
134 },
135 {
136 'proc' : 'tenant-show-preprocess',
137 },
138 {
139 'proc' : 'push-mode-stack',
140 },
141 ),
142 'no-action' : (
143 {
144 'proc' : 'vns-confirm-external-delete',
145 },
146 {
147 'proc' : 'tenant-show-preprocess',
148 },
149 {
150 'proc' : 'delete-objects',
151 },
152 )
153 }
154 ),
155}
156
157vns_show_action = (
158 {
159 'proc' : 'tenant-show-preprocess',
160 },
161 {
162 'proc' : 'query-table',
163 },
164 {
165 'proc' : 'display',
166 'format' : 'vns-definition',
167 },
168)
169
170VNS_SHOW_COMMAND_DESCRIPTION = {
171 'name' : 'show',
172 'mode' : 'login',
173 'all-help' : 'Show VNS details',
174 'short-help' : 'Show all defined VNSs belong to current tenant',
175 'command-type' : 'display-table',
176 'obj-type' : 'vns-definition',
177 'action' : vns_show_action,
178 'doc' : 'vns|show',
179 'doc-example' : 'vns|show-example',
180 'args' : (
181 'vns',
182 ),
183}
184VNS_SHOW_ID_COMMAND_DESCRIPTION = {
185 'name' : 'show',
186 'obj-type' : 'vns-definition',
187 'mode' : 'login',
188 'command-type' : 'display-table',
189 'action' : vns_show_action,
190 'short-help' : 'Show specific VNS, identified by name',
191 'doc' : 'vns|show-id',
192 'doc-example' : 'vns|show-id-example',
193 'args' : (
194 'vns',
195 {
196 'choices' : (
197 {
198 'field' : 'vnsname',
199 'type' : 'identifier',
200# 'completion' : 'complete-object-field',
201 'completion' : ['complete-tenantname-preprocess',
202 'complete-from-another'],
203 'other' : 'vns-definition|vnsname',
204 'scoped' : 'tenant',
205 'help-name' : "vns-id",
206 },
207 {
208 'field' : 'vnsname',
209 'type' : 'enum',
210 'values' : 'all',
211 }
212 ),
213 },
214 {
215 'field' : 'detail',
216 'optional' : True,
217 'type' : 'enum',
218 'values' : ('details', 'brief'),
219 'doc' : 'format|+',
220 }
221 )
222}
223
224VNS_SHOW_ID_DETAILS_COMMAND_DESCRIPTION = {
225 'name' : 'show',
226 'obj-type' : 'vns-definition',
227 'mode' : 'login',
228 'command-type' : 'display-table',
229 'short-help' : 'Show VNS associated details based on name',
230 'doc' : 'vns|show-id',
231 'doc-example' : 'vns|show-id-example',
232 'args' : (
233 'vns',
234 {
235 'choices' : (
236 {
237 'field' : 'vnsname',
238 'type' : 'identifier',
239 'completion' : ['complete-tenantname-preprocess',
240 'complete-from-another'],
241 'other' : 'vns-definition|vnsname',
242 'scoped' : 'tenant',
243 'help-name' : "vns-id",
244 },
245 {
246 'field' : 'vnsname',
247 'type' : 'enum',
248 'values' : 'all',
249 }
250 ),
251 },
252 {
253 'choices' : (
254 {
255 'field' : 'vns-interface',
256 'type' : 'enum',
257 'values' : 'interfaces',
258 'obj-type' : 'vns-interface',
259 'action' : ({'proc' : 'tenant-show-preprocess'},
260 'legacy-cli'),
261 'short-help' : 'Show VNS associated interfaces',
262 },
263 {
264 'field' : 'mac-address-table',
265 'type' : 'enum',
266 'values' : 'mac-address-table',
267 'obj-type' : 'host-vns-interface-vns',
268 'action' : ({'proc' : 'tenant-show-preprocess'},
269 'legacy-cli'),
270 'short-help' : 'Show VNS associated mac addresses',
271 },
272 {
273 'field' : 'interface-rules',
274 'type' : 'enum',
275 'values' : 'interface-rules',
276 'action' : ({'proc' : 'tenant-show-preprocess'},
277 'display-table'),
278 'obj-type' : 'vns-interface-rule',
279 'short-help' : 'Show VNS configured interfaces-rules',
280 'doc' : 'vns|show-id-interface-rules',
281 },
282 {
283 'field' : 'access-lists',
284 'type' : 'enum',
285 'values' : 'access-lists',
286 'action' : ({'proc' : 'tenant-show-preprocess'},
287 'display-table'),
288 'obj-type' : 'vns-access-list-entry',
289 'detail' : 'acl-brief',
290 'short-help' : 'Show VNS configured access-lists',
291 'doc' : 'vns|show-id-access-lists',
292 },
293 {
294 'field' : 'running-config',
295 'type' : 'enum',
296 'values' : 'running-config',
297 'action' : ({'proc' : 'tenant-show-preprocess'},
298 'legacy-cli'),
299 'short-help' : 'Show VNS running-config',
300 },
301 {
302 'field' : 'legacy-cli',
303 'type' : 'enum',
304 'values' : 'switch',
305 'action' : ({'proc' : 'tenant-show-preprocess'},
306 'legacy-cli'),
307 'obj-type' : 'vns-switch-ports',
308 'short-help' : 'Show VNS associated switches',
309 },
310 (
311 {
312 'field' : 'legacy-cli',
313 'type' : 'enum',
314 'values' : 'flow',
315 'obj-type' : 'vns-flow',
316 'action' : ({'proc' : 'tenant-show-preprocess'},
317 'legacy-cli'),
318 'short-help' : 'Show VNS associated flows',
319 'doc' : 'vns|show-id-flow',
320 },
321 {
322 'field' : 'detail',
323 'type' : 'enum',
324 'values' : ('brief',
325 'full-detail',
326 'details',
327 'summary',
328 ),
329 'optional' : True,
330 'short-help' : 'Detail level',
331 'doc' : 'format|+'
332 }
333 )
334 )
335 }
336 ),
337}
338
339HOST_VNS_INTERFACE_VNS_FORMAT = {
340 'host-vns-interface-vns' : { # with vns know, no vns column
341 'source' : 'only display',
342
343 'field-orderings' : {
344 'default' : [ 'Idx', 'tenant', 'vns', 'address-space', 'host', 'vlan', 'ips', 'attachment-points', 'last-seen' ],
345 'vns' : [ 'Idx', 'address-space', 'host', 'vlan', 'ips', 'attachment-points', 'last-seen' ],
346 },
347 'fields' : {
348 'Idx' : { 'verbose-name' : '#',
349 },
350 'host' : { 'verbose-name' : 'MAC Address',
351 'formatter' : fmtcnv.print_host_and_alias,
352 },
353 'address-space' : {
354 'verbose-name' : 'Address Space',
355 },
356 'vlan' : {
357 'verbose-name' : 'VLAN',
358 },
359 'ips' : { 'verbose-name' : 'IP Address',
360 'formatter' : fmtcnv.print_ip_addresses,
361 'entry_formatter' : fmtcnv.print_all_ip_addresses,
362 },
363 'attachment-points' : { 'verbose-name' : 'Attachment Point',
364 'formatter' : fmtcnv.print_host_attachment_point,
365 'entry_formatter' : fmtcnv.print_all_host_attachment_points,
366 },
367 'last-seen' : { 'verbose-name' : 'Last Seen',
368 'formatter' : fmtcnv.print_time_since_utc
369 },
370 'tenant' : {'verbose-name' : 'Tenant',
371 }
372 }
373 },
374}
375
376
377
378VNS_DEF_DESCRIPTION_COMMAND_DESCRIPTION = {
379 'name' : 'description',
380 'mode' : 'config-tenant-def-vns',
381 'command-type' : 'config',
382 'short-help' : 'Provide description for a VNS instance',
383 'doc' : 'vns|description',
384 'doc-example' : 'vns|description-example',
385 'args' : (
386 {
387 'field' : 'description',
388 'type' : 'string',
389 }
390 ),
391}
392
393
394VNS_DEF_ACTIVE_COMMAND_DESCRIPTION = {
395 'name' : 'active',
396 'mode' : 'config-tenant-def-vns',
397 'short-help' : 'Set vns active',
398 'doc' : 'vns|active',
399 'doc-example' : 'vns|active-example',
400 'doc-include' : [ 'default' ],
401 'args' : (),
402 'action' : (
403 {
404 'proc' : 'write-fields',
405 'data' : { 'active' : True },
406 'syntax-help' : 'mark the vns as active',
407 }
408 ),
409 'no-action' : (
410 {
411 'proc' : 'write-fields',
412 'data' : { 'active' : False },
413 'syntax-help' : 'mark the vns as inactive',
414 }
415 )
416}
417
418VNS_DEF_ORIGIN_COMMAND_DESCRIPTION = {
419 'name' : 'origin',
420 'mode' : 'config-tenant-def-vns',
421 'command-type' : 'config',
422 'short-help' : 'Describe vns origin',
423 'doc' : 'vns|origin',
424 'doc-example' : 'vns|origin-example',
425 'args' : (
426 {
427 'field' : 'origin',
428 'type' : 'string',
429 'action' : (
430 {
431 'proc' : 'vns-warn-external-config',
432 },
433 {
434 'proc' : 'write-fields',
435 },
436 ),
437 },
438 ),
439}
440
441VNS_DEF_USE_ADDRESS_SPACE_COMMAND_DESCRIPTION = {
442 'name' : 'use',
443 'short-help' : 'Associate address space',
444 'all-help' : 'Associate VNS with other objects',
445 'mode' : 'config-tenant-def-vns',
446 'command-type' : 'config',
447 'obj-type' : 'vns-definition',
448 'doc' : 'vns|use-address-space',
449 'doc-example' : 'vns|use-address-space-example',
450 'doc-include' : 'default',
451 'args' : (
452 'address-space',
453 {
454 'field' : 'address-space',
455 'type' : 'identifier',
456 'completion' : [
457 'complete-object-field',
458 'complete-from-another',
459 ],
460 'other' : 'address-space',
461 'syntax-help' : 'Enter associated address-space name',
462 'optional-for-no' : False,
463 'match-for-no' : 'address-space',
464 }
465 )
466}
467
468VNS_DEF_ARP_MODE_COMMAND_DESCRIPTION = {
469 'name' : 'arp-mode',
470 'short-help' : 'Configure arp mode',
471 'doc' : 'vns|arp-mode',
472 'doc-example' : 'vns|arp-mode-example',
473 'mode' : 'config-tenant-def-vns',
474 'command-type' : 'config',
475 'doc-include' : [ 'default' ],
476 'args' : (
477 {
478 'field' : 'arp-mode',
479 'type' : 'enum',
480 'values' : ('always-flood', 'flood-if-unknown', 'drop-if-unknown'),
481 'doc' : 'vns|arp-mode-value-+',
482 }
483 ),
484}
485
486VNS_DEF_BROADCAST_COMMAND_DESCRIPTION = {
487 'name' : 'broadcast',
488 'mode' : 'config-tenant-def-vns',
489 'command-type' : 'config',
490 'short-help' : 'Configure broadcast mode',
491 'doc' : 'vns|broadcast',
492 'doc-example' : 'vns|broadcast-example',
493 'doc-include' : [ 'default' ],
494 'args' : (
495 {
496 'field' : 'broadcast',
497 'type' : 'enum',
498 'values' : ('always-flood', 'forward-to-known', 'drop'),
499 'doc' : 'vns|broadcast-value-+',
500 }
501 ),
502}
503
504VNS_DEF_DHCP_IP_COMMAND_DESCRIPTION = {
505 'name' : 'dhcp-ip',
506 'mode' : 'config-tenant-def-vns',
507 'command-type' : 'config',
508 'short-help' : 'Configure dhcp ip address',
509 'doc' : 'vns|dhcp-ip',
510 'doc-example' : 'vns|dhcp-ip-example',
511 'args' : (
512 {
513 'field' : 'dhcp-ip',
514 'type' : 'ip-address',
515 'syntax-help' : 'Enter an IP Address',
516 }
517 ),
518}
519
520VNS_DEF_DHCP_MODE_COMMAND_DESCRIPTION = {
521 'name' : 'dhcp-mode',
522 'mode' : 'config-tenant-def-vns',
523 'command-type' : 'config',
524 'short-help' : 'Set dhcp mode',
525 'doc' : 'vns|dhcp-mode',
526 'doc-example' : 'vns|dhcp-mode-example',
527 'doc-include' : [ 'default' ],
528 'args' : (
529 {
530 'field' : 'dhcp-mode',
531 'type' : 'enum',
532 'values' : ('always-flood', 'flood-if-unknown', 'static'),
533 'doc' : 'vns|dhcp-value-+',
534 }
535 ),
536}
537
538VNS_INTERFACE_RULE_COMMAND_DESCRIPTION = {
539 'name' : 'interface-rule',
540 'mode' : 'config-tenant-def-vns*',
541 'command-type' : 'config-submode',
542 'obj-type' : 'vns-interface-rule',
543 'parent-field' : 'vns',
544 'submode-name' : 'config-tenant-def-vns-if-rule',
545 'short-help' : 'Enter interface-rule submode, configure vns details',
546 'doc' : 'vns|interface-rule',
547 'doc-example' : 'vns|interface-rule-example',
548 'args' : (
549 {
550 'field' : 'rule',
551 'type' : 'identifier',
552 'syntax-help' : 'Enter a vns interface rule name',
553 'completion' : 'complete-object-field',
554 'scoped' : True,
555 }
556 )
557}
558
559VNS_PRIORITY_COMMAND_DESCRIPTION = {
560 'name' : 'priority',
561 'mode' : 'config-tenant-def-vns',
562 'command-type' : 'config',
563 'short-help' : 'Set vns priority',
564 'doc' : 'vns|priority',
565 'doc-example' : 'vns|priority-example',
566 'args' : (
567 {
568 'field' : 'priority',
569 'base-type' : 'integer',
570 'range' : (0, 65535),
571 }
572 )
573}
574
575#
576# ----------------------------------------------------------------------
577# vns-def-if submode commands
578# (vns definition interface rules submode)
579#
580
581VNS_DEF_IF_ACTIVE_COMMAND_DESCRIPTION = {
582 'name' : 'active',
583 'mode' : 'config-tenant-def-vns-if-rule',
584 'command-type' : 'config',
585 'short-help' : 'Set rule to Active',
586 'doc' : 'vns|interface-rule-active',
587 'doc-example' : 'vns|interface-rule-active-example',
588 'doc-inlcude' : [ 'default' ],
589 'args' : (),
590 'action' : (
591 {
592 'proc' : 'write-fields',
593 'data' : { 'active' : True }
594 }
595 ),
596 'no-action' : (
597 {
598 'proc' : 'write-fields',
599 'data' : { 'active' : False }
600 }
601 )
602}
603
604VNS_DEF_IF_ALLOW_MULTIPLE_COMMAND_DESCRIPTION = {
605 'name' : 'allow-multiple',
606 'mode' : 'config-tenant-def-vns-if-rule',
607 'command-type' : 'config',
608 'short-help' : 'Enable multiple interface rule matches',
609 'doc' : 'vns|interface-rule-allow-multiple',
610 'doc-example' : 'vns|interface-rule-allow-multiple-example',
611 'doc-include' : [ 'default' ],
612 'args' : (),
613 'action' : (
614 {
615 'proc' : 'write-fields',
616 'data' : { 'allow-multiple' : True }
617 }
618 ),
619 'no-action' : (
620 {
621 'proc' : 'reset-fields',
622 'fields' : [ 'allow-multiple' ]
623 }
624 )
625}
626
627#
628# XXX vlan-tag-on-egress required in future releases when multiple vlans
629# tagging are supported in vns egress.
630#
631#VNS_DEF_IF_VLAN_TAG_ON_EGRESS_TMP_COMMAND_DESCRIPTION = {
632# 'name' : 'vlan-tag-on-egress',
633# 'short-help' : 'Enable vlan tagging on egress',
634# 'mode' : 'config-def-vns-if-rule',
635# 'command-type' : 'config',
636# 'args' : (),
637# 'action' : (
638# {
639# 'proc' : 'write-fields',
640# 'data' : { 'vlan-tag-on-egress' : True }
641# }
642# ),
643# 'no-action' : (
644# {
645# 'proc' : 'reset-fields',
646# 'fields' : [ 'vlan-tag-on-egress' ]
647# }
648# )
649# }
650
651VNS_DEF_IF_DESCRIPTION_COMMAND_DESCRIPTION = {
652 'name' : 'description',
653 'mode' : 'config-tenant-def-vns-if-rule',
654 'short-help' : 'Provide description for interface rule',
655 'doc' : 'vns|interface-rule-description',
656 'doc-example' : 'vns|interface-rule-description-example',
657 'command-type' : 'config',
658 'args' : (
659 {
660 'field' : 'description',
661 'type' : 'string',
662 }
663 ),
664}
665
666VNS_DEF_IF_PRIORITY_COMMAND_DESCRIPTION = {
667 'name' : 'priority',
668 'mode' : 'config-tenant-def-vns-if-rule',
669 'command-type' : 'config',
670 'short-help' : 'Describe priority for interface rule',
671 'doc' : 'vns|interface-rule-priority',
672 'doc-example' : 'vns|interface-rule-priority-example',
673 'args' : (
674 {
675 'field' : 'priority',
676 'value' : 'integer',
677 }
678 ),
679}
680
681
682VNS_DEF_IF_MATCH_MAC_COMMAND_DESCRIPTION = {
683 'name' : 'match',
684 'mode' : 'config-tenant-def-vns-if-rule',
685 'command-type' : 'config',
686 'short-help' : 'Associate mac (host) with interface rule',
687 'all-help' : 'Configure a match for this interface rule',
688 'doc' : 'vns|interface-rule-match-mac',
689 'doc-example' : 'vns|interface-rule-match-mac-example',
690 'doc-all' : 'address-space|match',
691 'data' : { 'mac' : None }, # for no command reset
692 'obj-type' : 'vns-interface-rule',
693 'args' : (
694 {
695 'token' : 'mac',
696 },
697 {
698 'field' : 'mac',
699 'type' : 'host',
700 'help-name' : 'host mac or alias',
701 'completion' : ['complete-object-field',
702 'complete-from-another',
703 ],
704 'scoped' : True,
705 'data-handler' : 'alias-to-value',
706 'other' : 'host',
707 'optional-for-no' : True,
708 'doc' : 'vns|interface-rule-match-mac-field',
709 }
710 ),
711}
712
713
714VNS_DEF_IF_MATCH_IP_SUBNET_COMMAND_DESCRIPTION = {
715 'name' : 'match',
716 'mode' : 'config-tenant-def-vns-if-rule',
717 'command-type' : 'config',
718 'short-help' : 'Associate ip-subnet (ip or cidr range) for interface rule',
719 'doc' : 'vns|interface-rule-match-ip-subnet',
720 'doc-example' : 'vns|interface-rule-match-ip-subnet-example',
721 'data' : { 'ip-subnet' : None }, # for no command reset
722 'args' : (
723 {
724 'token' : 'ip-subnet',
725 },
726 {
727 'field' : 'ip-subnet',
728 'type' : 'cidr-range',
729 'help-name' : 'ip address (10.10.10.10), or cidr (10.20.30.0/24)',
730 'optional-for-no' : True,
731 'doc' : 'vns|interface-rule-match-ip-subnet-field',
732 }
733 ),
734}
735
736
737VNS_DEF_IF_MATCH_SWITCH_COMMAND_DESCRIPTION = {
738 'name' : 'match',
739 'mode' : 'config-tenant-def-vns-if-rule',
740 'command-type' : 'config',
741 'obj-type' : 'vns-interface-rule',
742 'short-help' : 'Associate switch with interface rule',
743 'doc' : 'vns|interface-rule-match-switch',
744 'doc-example' : 'vns|interface-rule-match-switch-example',
745 'data' : { # for no command reset
746 'switch' : None,
747 'ports' : None,
748 },
749 'args' : (
750 {
751 'token' : 'switch',
752 },
753 {
754 # constructed as args to ensure that the ports isn't
755 # completed along with swtich values for 'no match switch'
756 'optional-for-no' : True,
757 'args' : (
758 {
759 'field' : 'switch',
760 'type' : 'string',
761 'parent-field' : None,
762 'completion' : [
763 'complete-object-field',
764 'complete-alias-choice',
765 ],
766 'help-name' : 'switch dpid or switch alias',
767 'data-handler' : 'alias-to-value',
768 'other' : 'switches|dpid',
769 },
770 {
771 'field' : 'ports',
772 'optional' : True,
773 'type' : 'string',
774 'help-name' : 'switch interface, or range, or list',
775 'completion' : 'complete-interface-list',
776 'data-handler' : 'warn-missing-interface',
777 'optional-for-no' : True,
778 },
779 ),
780 },
781 ),
782}
783
784
785VNS_DEF_IF_MATCH_TAGS_COMMAND_DESCRIPTION = {
786 'name' : 'match',
787 'mode' : 'config-tenant-def-vns-if-rule',
788 'command-type' : 'config',
789 'short-help' : 'Associate tags with interface rule',
790 'doc' : 'vns|interface-rule-match-tag',
791 'doc-example' : 'vns|interface-rule-match-tag-example',
792 'data' : { # for no command reset
793 'tags' : None,
794 },
795 'args' : (
796 {
797 'token' : 'tags',
798 },
799 {
800 'field' : 'tags',
801 'type' : 'string',
802 'optional-for-no' : True,
803 }
804 ),
805}
806
807# Remove match vlan command temporarily on gregor's requres
808# the running config can still generate these commands, but
809# they won't get read correctly
810VNS_DEF_IF_MATCH_VLANS_COMMAND_DESCRIPTION = {
811 'name' : 'match',
812 'mode' : 'config-tenant-def-vns-if-rule',
813 'command-type' : 'config',
814 'short-help' : 'Associate vlans with interface rule',
815 'doc' : 'vns|interface-rule-match-vlans',
816 'doc-example' : 'vns|interface-rule-match-vlans-example',
817 'data' : { # for no command reset
818 'vlans' : None,
819 },
820 'args' : (
821 {
822 'token' : 'vlans',
823 },
824 {
825 'field' : 'vlans',
826 'value' : 'string',
827 'help-name' : 'Vlan number (0-4096) or range, or list',
828 'optional-for-no' : True,
829 }
830 ),
831}
832
833#
834# ----------------------------------------------------------------------
835# vns submode commands
836#
837
838
839VNS_COMMAND_DESCRIPTION = {
840 'name' : 'vns',
841 'short-help' : 'Enter VNS submode, manage access lists',
842 'mode' : 'config*',
843 'feature' : 'vns',
844 'no-supported' : False,
845 'command-type' : 'config-submode',
846 'obj-type' : 'vns-definition',
847 'submode-name' : 'config-tenant-vns',
848 'syntax-help' : 'Enter a vns name',
849 'create' : False,
850 'doc' : 'vns|vns',
851 'doc-example' : 'vns|vns-example',
852 'args' : (
853 {
854 'field' : 'vnsname',
855 'type' : 'identifier',
856 'completion' : ['complete-tenantname-preprocess',
857 'complete-from-another'],
858 'other' : 'vns-definition|vnsname',
859 'scoped' : 'tenant',
860 'syntax-help' : 'Enter a vns name',
861 'doc' : 'vns|vns-id',
862 'doc-include' : [ 'type-doc' ],
863 'action' : (
864 {
865 'proc' : 'tenant-show-preprocess',
866 },
867 {
868 'proc' : 'push-mode-stack',
869 }
870 ),
871
872 }
873 )
874}
875
876VNS_INTERFACE_COMMAND_DESCRIPTION = {
877 'name' : 'interface',
878 'short-help' : 'Enter VNS-if submode',
879 'mode' : 'config-tenant-vns*',
880 'command-type' : 'config-submode',
881 'obj-type' : 'vns-interface-config',
882 'parent-field' : 'vns',
883 'current-mode-obj-id' : 'vns-definition',
884 'submode-name' : 'config-tenant-vns-if',
885 'syntax-help' : 'Enter an interface name',
886 'doc' : 'vns|vns-interface',
887 'doc-example' : 'vns|vns-interface-example',
888 'args' : (
889 {
890 'field' : 'interface',
891 'completion' : 'complete-object-field',
892 'doc' : 'vns|vns-interface-field',
893 }
894 )
895}
896
897VNS_ACCESS_GROUP_COMMAND_DESCRIPTION = {
898 'name' : 'access-group',
899 'short-help' : 'Associate interface with access-list',
900 'mode' : 'config-tenant-vns-if',
901 'command-type' : 'config',
902 'obj-type' : 'vns-interface-access-list',
903 'parent-field' : 'vns-interface',
904 # 'current-mode-obj-id' : 'vns-definition',
905 'submode-name' : 'config-tenant-vns-if',
906 'doc' : 'vns|vns-access-group',
907 'doc-example' : 'vns|vns-access-group-example',
908 'args' : (
909 {
910 'field' : 'vns-access-list',
911 'type' : 'string',
912 'completion' : 'complete-from-another',
913 'other' : 'vns-access-list|name',
914 'optional-for-no' : False,
915 },
916 {
917 'field' : 'in-out',
918 'type' : 'enum',
919 'values' : ('in', 'out'),
920 'syntax-help' : 'apply access-list in this direction',
921 'optional-for-no' : False,
922 'doc' : 'vns|vns-access-group-direction-+',
923 }
924 ),
925 'action' : (
926 {
927 'proc' : 'convert-vns-access-list',
928 },
929 {
930 'proc' : 'write-object',
931 },
932 ),
933 'no-action' : (
934 {
935 'proc' : 'convert-vns-access-list',
936 },
937 {
938 'proc' : 'delete-objects',
939 },
940 )
941}
942
943SHOW_VNS_ACCESS_GROUP_COMMAND_DESCRIPTION = {
944 'name' : 'show',
945 'mode' : 'config-tenant-vns-if*',
946 'action' : 'display-table',
947 'command-type' : 'display-table',
948 'scoped' : True, # displayed entries filtered by pushed obj id
949 'obj-type' : 'vns-interface-access-list',
950 'short-help' : 'show access-group details',
951 'args' : (
952 'access-group',
953 )
954}
955
956
957SHOW_VNS_ACCESS_LIST_COMMAND_DESCRIPTION = {
958 'name' : 'show',
959 'mode' : ['config-tenant-vns-*'],
960 'short-help' : 'Show VNS access lists',
961 'action' : 'display-table',
962 'command-type' : 'display-table',
963 'obj-type' : 'vns-access-list',
964 'scoped' : True, # displayed entries filtered by pushed obj id
965 'args' : (
966 'access-list',
967 )
968}
969
970SHOW_VNS_INTERFACES_COMMAND_DESCRIPTION = {
971 'name' : 'show',
972 'mode' : ['config-tenant-vns', 'config-tenant-vns-if'],
973 'short-help' : 'Show VNS associated interfaces',
974 'doc' : 'vns|vns-show-interface',
975 'obj-type' : 'vns-interface',
976 'args' : (
977 {
978 'token' : 'interfaces',
979 'scoped' : True,
980 'action' : ({'proc' : 'tenant-show-preprocess'},
981 'legacy-cli'),
982 }
983 )
984}
985
986SHOW_VNS_ACCESS_LIST_ENTRY_COMMAND_DESCRIPTION = {
987 'name' : 'show',
988 'mode' : 'config-tenant-vns*',
989 'short-help' : 'show VNS access list rules',
990 'action' : 'display-table',
991 'command-type' : 'display-table',
992 'obj-type' : 'vns-access-list-entry',
993 'detail' : 'acl-brief',
994 'args' : (
995 'access-list-entry',
996 ),
997}
998
999VNS_ACCESS_LIST_COMMAND_DESCRIPTION = {
1000 'name' : 'access-list',
1001 'mode' : 'config-tenant-vns*',
1002 'command-type' : 'config-submode',
1003 'obj-type' : 'vns-access-list',
1004 'parent-field' : 'vns',
1005 'submode-name' : 'config-tenant-vns-acl',
1006 'syntax-help' : 'Enter an access list name',
1007 'short-help' : 'Enter vns access-list submode',
1008 'doc' : 'vns|vns-access-list',
1009 'doc-example' : 'vns|vns-access-list-example',
1010 'args' : (
1011 {
1012 'field' : 'name',
1013 'completion' : 'complete-object-field',
1014 'doc' : 'vns|vns-access-list-name'
1015 }
1016 )
1017}
1018
1019
1020VNS_ACCESS_LIST_DESCRIPTION_COMMAND_DESCRIPTION = {
1021 'name' : 'description',
1022 'mode' : 'config-tenant-vns-acl',
1023 'short-help' : 'Provide a description for a VNS access list',
1024 'doc' : 'vns|vns-access-list-description',
1025 'doc-example' : 'vns|vns-access-list-description-example',
1026 'command-type' : 'config',
1027 'args' : (
1028 {
1029 'field' : 'description',
1030 'type' : 'string',
1031 }
1032 ),
1033}
1034
1035
1036VNS_ACCESS_LIST_PRIORITY_COMMAND_DESCRIPTION = {
1037 'name' : 'priority',
1038 'mode' : 'config-tenant-vns-acl',
1039 'short-help' : 'Set VNS priority',
1040 'doc' : 'vns|vns-access-list-priority',
1041 'doc-example' : 'vns|vns-access-list-priority-example',
1042 'doc-include' : [ 'default', 'range' ],
1043 'command-type' : 'config',
1044 'args' : (
1045 {
1046 'field' : 'priority',
1047 'base-type' : 'integer',
1048 'range' : (0, 65535),
1049 }
1050 )
1051}
1052
1053
1054#
1055# ----------------------------------------------------------------------
1056# vns access list command
1057#
1058
1059SRC_IP_MATCH = {
1060 'choices' : (
1061 (
1062 {
1063 'field' : 'src-ip',
1064 'type' : 'ip-address-not-mask',
1065 'doc' : 'vns|vns-access-list-ip-and-mask-ip',
1066 },
1067 {
1068 'field' : 'src-ip-mask',
1069 'type' : 'inverse-netmask',
1070 'data' : {
1071 'dst-ip' : '0.0.0.0',
1072 'dst-ip-mask' : '255.255.255.255',
1073 },
1074 'doc' : 'vns|vns-access-list-ip-and-mask-mask',
1075 },
1076 ),
1077 (
1078 {
1079 'field' : 'src-ip',
1080 'type' : 'ip-address-not-mask',
1081 'data' : {
1082 'src-ip-mask' : '0.0.0.0',
1083 'dst-ip' : '0.0.0.0',
1084 'dst-ip-mask' : '255.255.255.255',
1085 },
1086 'doc' : 'vns|vns-access-list-ip-only',
1087 },
1088 ),
1089 (
1090 {
1091 'field' : 'src-ip',
1092 'type' : 'cidr-range',
1093 'help-name' : 'src-cidr',
1094 'data-handler' : 'split-cidr-data-inverse',
1095 'dest-ip' : 'src-ip',
1096 'dest-netmask' : 'src-ip-mask',
1097 'data' : {
1098 'dst-ip' : '0.0.0.0',
1099 'dst-ip-mask' : '255.255.255.255',
1100 },
1101 'doc' : 'vns|vns-access-list-cidr-range',
1102 }
1103 ),
1104 (
1105 {
1106 'token' : 'any',
1107 'data' : {
1108 'src-ip' : '0.0.0.0',
1109 'src-ip-mask' : '255.255.255.255',
1110 'dst-ip' : '0.0.0.0',
1111 'dst-ip-mask' : '255.255.255.255',
1112 },
1113 'doc' : 'vns|vns-access-list-ip-any',
1114 }
1115 ),
1116 )
1117}
1118
1119
1120SRC_PORT_MATCH = (
1121 {
1122 'field' : 'src-tp-port-op',
1123 'type' : 'enum',
1124 'values' : ('eq', 'neq'),
1125 'doc' : 'vns|vns-access-list-port-op-+',
1126 },
1127 {
1128 'choices' : (
1129 {
1130 'field' : 'src-tp-port',
1131 'base-type' : 'hex-or-decimal-integer',
1132 'range' : (0,65535),
1133 'data-handler' : 'hex-to-integer',
1134 'doc' : 'vns|vns-access-list-port-hex',
1135 'doc-include' : [ 'range' ],
1136 },
1137 {
1138 'field' : 'src-tp-port',
1139 'type' : 'enum',
1140 'values' : fmtcnv.tcp_name_to_number_dict,
1141 'permute' : 'skip',
1142 'doc' : 'vns|vns-access-list-port-type',
1143 },
1144 ),
1145 },
1146)
1147
1148
1149DST_IP_MATCH = {
1150 'choices' : (
1151 (
1152 {
1153 'field' : 'dst-ip',
1154 'type' : 'ip-address-not-mask',
1155 'doc' : 'vns|vns-access-list-ip-and-mask-ip',
1156 },
1157 {
1158 'field' : 'dst-ip-mask',
1159 'type' : 'inverse-netmask',
1160 'doc' : 'vns|vns-access-list-ip-and-mask-mask',
1161 },
1162 ),
1163 (
1164 {
1165 'field' : 'dst-ip',
1166 'type' : 'ip-address-not-mask',
1167 'data' : {
1168 'dst-ip-mask' : '0.0.0.0',
1169 },
1170 'doc' : 'vns|vns-access-list-ip-only',
1171 },
1172 ),
1173 (
1174 {
1175 'field' : 'dst-ip',
1176 'type' : 'cidr-range',
1177 'help-name' : 'dst-cidr',
1178 'data-handler' : 'split-cidr-data-inverse',
1179 'dest-ip' : 'dst-ip',
1180 'dest-netmask' : 'dst-ip-mask',
1181 'doc' : 'vns|vns-access-list-cidr-range',
1182 },
1183 ),
1184 (
1185 {
1186 'token' : 'any',
1187 'data' : {
1188 'dst-ip' : '0.0.0.0',
1189 'dst-ip-mask' : '255.255.255.255',
1190 },
1191 'doc' : 'vns|vns-access-list-ip-any',
1192 }
1193 ),
1194 )
1195}
1196
1197
1198DST_PORT_MATCH = (
1199 {
1200 'field' : 'dst-tp-port-op',
1201 'type' : 'enum',
1202 'values' : ('eq', 'neq'),
1203 'doc' : 'vns|vns-access-list-port-op+',
1204 },
1205 {
1206 'choices' : (
1207 {
1208 'field' : 'dst-tp-port',
1209 'base-type' : 'hex-or-decimal-integer',
1210 'range' : (0,65535),
1211 'data-handler' : 'hex-to-integer',
1212 'doc' : 'vns|vns-access-list-port-hex',
1213 },
1214 {
1215 'field' : 'dst-tp-port',
1216 'type' : 'enum',
1217 'values' : fmtcnv.tcp_name_to_number_dict,
1218 'permute' : 'skip'
1219 },
1220 ),
1221 }
1222)
1223
1224
1225# Unfortunatly, the model defines the compound key using the
1226# rule field as a character field, not an integer.
1227# Since '00' is then the same rule as '0', two rows could be
1228# created describing the same integer rule.
1229# Here the character string is normalized.
1230# (This may be the result of having a requirement that all fields used to
1231# construct compound keys must be character fields)
1232#
1233# Additionally, for tcp and udp matches, the *tp_port_op needs
1234# to be set.
1235#
1236def vns_normalize_rule(data):
1237 data['rule'] = str(int(data['rule']))
1238
1239 if data.get('type', '') in ['tcp', 'udp']:
1240 if not 'src-tp-port-op' in data or data['src-tp-port-op'] == None:
1241 data['src-tp-port-op'] = 'any'
1242 if not 'dst-tp-port-op' in data or data['dst-tp-port-op'] == None:
1243 data['dst-tp-port-op'] = 'any'
1244
1245
1246command.add_action('vns-normalize-rule', vns_normalize_rule,
1247 {'kwargs' : { 'data' : '$data' }})
1248#
1249
1250VNS_ACCESS_LIST_ENTRY_COMMAND_DESCRIPTION = {
1251 'name' : { 'type' : 'pattern',
1252 'pattern' : r'\d',
1253 'field' : 'rule',
1254 'title' : '<acl rule number>',
1255 'completion' : 'complete-object-field',
1256 'obj-type' : 'vns-access-list-entry',
1257 },
1258 'mode' : 'config-tenant-vns-acl',
1259 'short-help' : 'Define ACL details for this access-list',
1260 'doc' : 'vns|vns-access-list-entry',
1261 'doc-example' : 'vns|vns-access-list-entry-example',
1262 'command-type' : 'config-object',
1263 'parent-field' : 'vns-access-list',
1264 'obj-type' : 'vns-access-list-entry',
1265 'data' : {
1266 'ether-type' : None,
1267 'src-ip' : None,
1268 'src-ip-mask' : None,
1269 'dst-ip' : None,
1270 'dst-ip-mask' : None,
1271 'src-tp-port' : None,
1272 'src-tp-port-op' : None,
1273 'dst-tp-port' : None,
1274 'dst-tp-port-op' : None,
1275 'src-mac' : None,
1276 'dst-mac' : None,
1277 'vlan' : None,
1278 'icmp-type' : None,
1279 },
1280 'args' : (
1281 {
1282 'field' : 'action',
1283 'type' : 'enum',
1284 'values' : ( 'permit', 'deny' ),
1285 'doc' : 'vns|vns-access-list-entry-action-+',
1286 },
1287 {
1288 'choices' : (
1289 (
1290 {
1291 'choices' : (
1292 {
1293 'field' : 'type',
1294 'type' : 'enum',
1295 'values' : ('ip','tcp','udp'),
1296 'doc' : 'vns|vns-access-list-entry-type-+',
1297 },
1298 {
1299 'field' : 'type',
1300 'base-type' : 'hex-or-decimal-integer',
1301 'range' : (0,255),
1302 'help-name' : 'ip protocol',
1303 'data-handler' : 'hex-to-integer',
1304 'doc' : 'vns|vns-access-entry-type-ip-protocol',
1305 'doc-include' : [ 'range' ],
1306 },
1307 )
1308 },
1309 # Complexity arises from the SRC_IP match part
1310 # being, required, while the port match
1311 # is optional, as is the DST_IP match, but the
1312 # DST_PORT_MATCH is only possible to describe when
1313 # the DST_IP part is included
1314 SRC_IP_MATCH,
1315 {
1316 'optional' : True,
1317 'optional-for-no' : True,
1318 'args' : SRC_PORT_MATCH,
1319 },
1320 {
1321 'optional' : True,
1322 'optional-for-no' : True,
1323 'args' : (
1324 DST_IP_MATCH,
1325 {
1326 'optional' : True,
1327 'optional-for-no' : True,
1328 'args' : DST_PORT_MATCH,
1329 },
1330 ),
1331 },
1332 ),
1333 (
1334 # Only allow the icmp type for icmp syntax
1335 # this further increases the syntax complexity
1336 {
1337 'field' : 'type',
1338 'type' : 'enum',
1339 'values' : 'icmp',
1340 'doc' : 'vns|vns-access-list-ip-+',
1341 },
1342 SRC_IP_MATCH,
1343 {
1344 'optional' : True,
1345 'optional-for-no' : True,
1346 'args' : SRC_PORT_MATCH
1347 },
1348 {
1349 'optional' : True,
1350 'optional-for-no' : True,
1351 'args' : (
1352 DST_IP_MATCH,
1353 {
1354 'optional' : True,
1355 'optional-for-no' : True,
1356 'args' : DST_PORT_MATCH,
1357 },
1358 ),
1359 },
1360 {
1361 'field' : 'icmp-type',
1362 'optional' : True,
1363 'optional-for-no' : True,
1364 'base-type' : 'hex-or-decimal-integer',
1365 'range' : (0,255),
1366 'data-handler' : 'hex-to-integer',
1367 },
1368 ),
1369 (
1370 {
1371 'field' : 'type',
1372 'type' : 'enum',
1373 'values' : 'mac',
1374 'doc' : 'vns|vns-access-list-mac',
1375 },
1376 {
1377 'choices' : (
1378 {
1379 'token' : 'any',
1380 },
1381 {
1382 'field' : 'src-mac',
1383 'type' : 'host',
1384 'completion' : [ 'complete-alias-choice',
1385 ],
1386 'other' : 'host|mac',
1387 'data-handler' : 'alias-to-value',
1388 },
1389 )
1390 },
1391 {
1392 'choices' : (
1393 {
1394 'token' : 'any',
1395 },
1396 {
1397 'field' : 'dst-mac',
1398 'type' : 'host',
1399 'completion' : [ 'complete-alias-choice',
1400 ],
1401 'other' : 'host|mac',
1402 'data-handler' : 'alias-to-value',
1403 },
1404 ),
1405 },
1406 {
1407 'optional' : True,
1408 'choices' : (
1409 {
1410 'field' : 'ether-type',
1411 'base-type' : 'hex-or-decimal-integer',
1412 'range' : (1536,65536),
1413 'data-handler' : 'hex-to-integer',
1414 'doc' : 'vns|vns-access-list-ether-type',
1415 },
1416 {
1417 'field' : 'ether-type',
1418 'type' : 'enum',
1419 'values' : fmtcnv.ether_type_to_number_dict,
1420 'permute' : 'skip'
1421 },
1422 )
1423 },
1424 {
1425 'field' : 'vlan',
1426 'tag' : 'vlan',
1427 'base-type' : 'hex-or-decimal-integer',
1428 'range' : (1,4096), # no zero? really?
1429 'data-handler' : 'hex-to-integer',
1430 'optional' : True,
1431 'optional-for-no' : True,
1432 },
1433 ),
1434 )
1435 }
1436 ),
1437 'action' : (
1438 {
1439 'proc' : 'vns-normalize-rule',
1440 'field' : 'rule',
1441 },
1442 {
1443 'proc' : 'write-object',
1444 },
1445 ),
1446}
1447
1448VNS_DEFINITION_FORMAT = {
1449 'vns-definition' : {
1450 'field-orderings' : {
1451 'default' : [ 'Idx', 'tenant','vnsname', 'active', 'priority', 'arp-mode',
1452 'dhcp-mode', 'dhcp-ip', 'broadcast',
1453 'address-space' ],
1454 'vns-config' : [ 'Idx', 'tenant','vnsname','active', 'priority', 'arp-mode',
1455 'dhcp-mode', 'dhcp-ip', 'broadcast',
1456 'address-space', ],
1457 'brief' : [ 'Idx', 'tenant', 'vnsname', 'address-space', ]
1458 },
1459 'fields' : {
1460 'vnsname' : { 'verbose-name' : 'VNS ID',
1461 },
1462 'active' : {
1463 },
1464 'address-space' : { 'verbose-name' : 'Address Space',
1465 },
1466 'priority' : {
1467 },
1468 'arp-mode' : { 'verbose-name' : 'ARP Config Mode',
1469 },
1470 'dhcp-mode' : { 'verbose-name' : 'DHCP Config Mode' ,
1471 },
1472 'dhcp-ip' : { 'verbose-name' : 'DHCP Ip' ,
1473 },
1474 'broadcast' : { 'verbose-name' : 'Broadcast Mode' ,
1475 },
1476 'address-space' : {
1477 'verbose-name' : 'Address Space',
1478 },
1479 'tenant' : {
1480 'verbose-name' : 'Tenant',
1481 },
1482
1483 }
1484 },
1485}
1486
1487VNS_INTERFACE_RULE_FORMAT = {
1488 'vns-interface-rule' : {
1489 'field-orderings': {
1490 'default' : [ 'Idx', 'tenant', 'vnsname', 'rule', 'description',
1491 'allow-multiple', 'active', 'priority',
1492 'mac', 'vlans', 'ip-subnet', 'switch', 'ports', 'tags'
1493 ],
1494 'vns-config' : [ 'Idx', 'rule', 'description', 'allow-multiple', 'active',
1495 'priority', 'mac', 'vlans', 'ip-subnet', 'switch', 'ports', 'tags'
1496 ],
1497 },
1498 'fields': {
1499 'rule' : { 'verbose-name' : 'VNS Rule ID',
1500 },
1501 'tenant' : {
1502 'verbose-name' : 'Tenant',
1503 },
1504 'vnsname' : { 'verbose-name' : 'VNS ID'
1505 },
1506 'mac' : {
1507 'formatter' : fmtcnv.print_host_and_alias
1508 },
1509 'tags' : {
1510 },
1511 'active' : {
1512 },
1513 'allow-multiple' : {
1514 },
1515 'description' : {
1516 },
1517 'ip-subnet' : {
1518 },
1519 'ports' : {
1520 },
1521 'priority' : {
1522 },
1523 'rule' : {
1524 },
1525 'switch' : {
1526 },
1527 'tags' : {
1528 },
1529 'vlans' : {
1530 },
1531 }
1532 },
1533}
1534
1535
1536VNS_DISPLAY_VNS_INTERFACE_FORMAT = {
1537 'display-vns-interface' : {
1538 'field-orderings' : {
1539 'default' : ['Idx', 'tenant', 'vnsname', 'address-space', 'id', 'rule', 'mac', 'vlan',
1540 'ips', 'attachment-points', 'last-seen'],
1541 'vns-config' : ['Idx', 'id', 'rule', 'mac', 'vlan',
1542 'ips', 'attachment-points', 'last-seen']
1543 },
1544 'fields': {
1545 'tenant' : {
1546 'verbose-name' : 'Tenant',
1547 },
1548 'vnsname' : {
1549 'verbose-name' : 'VNS ID',
1550 },
1551 'id' : {
1552 },
1553 'rule' : {
1554 },
1555 'address-space' : {
1556 'verbose-name' : 'Address Space',
1557 },
1558 'mac' : { 'verbose-name' : 'MAC Address',
1559 'formatter' : fmtcnv.print_host_and_alias,
1560 },
1561 'vlan' : { 'verbose-name' : 'VLAN',
1562 },
1563 'ips' : {
1564 'formatter' : fmtcnv.print_ip_addresses,
1565 'entry-formatter' : fmtcnv.print_all_ip_addresses,
1566 },
1567 'attachment-points' : { 'formatter' : fmtcnv.print_host_attachment_point,
1568 'entry-formatter' : fmtcnv.print_all_host_attachment_points,
1569 },
1570 'last-seen' : {
1571 'formatter' : fmtcnv.print_time_since_utc_timestr
1572 }
1573 }
1574 },
1575}
1576
1577
1578VNS_INTERFACE_DISPLAY_FORMAT = {
1579 'vns-interface-display' : {
1580 'field-orderings' : {
1581 'default' : ['Idx', 'tenant', 'vnsname', 'address-space', 'id', 'rule', 'mac', 'vlan',
1582 'ips', 'attachment-points', 'last-seen'],
1583 'vns-config' : ['Idx', 'id', 'address-space', 'rule', 'mac', 'vlan',
1584 'ips', 'attachment-points', 'last-seen']
1585 },
1586 'fields': {
1587 'id' : {
1588 },
1589 'tenant' : {
1590 'verbose-name' : 'Tenant',
1591 },
1592 'vnsname' : {
1593 'verbose-name' : 'VNS ID',
1594 },
1595 'rule' : {
1596 },
1597 'mac' : { 'verbose-name' : 'MAC Address',
1598 'formatter' : fmtcnv.print_host_and_alias,
1599 },
1600 'vlan' : { 'verbose-name' : 'VLAN',
1601 },
1602 'ips' : {
1603 'formatter' : fmtcnv.print_ip_addresses,
1604 'entry-formatter' : fmtcnv.print_all_ip_addresses,
1605 },
1606 'attachment-points' : { 'formatter' : fmtcnv.print_host_attachment_point,
1607 'entry-formatter' : fmtcnv.print_all_host_attachment_points,
1608 },
1609 'address-space' : {
1610 'verbose-name' : 'Address Space',
1611 },
1612 'last-seen' : {
1613 'formatter' : fmtcnv.print_time_since_utc
1614 }
1615 }
1616 },
1617}
1618
1619
1620VNS_INTERFACE_MACS_FORMAT = {
1621 'vns-interface-macs' : {
1622 'field-orderings' : {
1623 'default' : [ 'Idx', 'tenant', 'vns', 'address-space',
1624 'veth', 'mac', 'vlan', 'ips', 'tags', 'last-seen'],
1625 'scoped' : [ 'Idx', 'address-space',
1626 'veth', 'mac', 'vlan', 'ips', 'tags', 'last-seen'],
1627 },
1628 'fields': {
1629 'veth' : {
1630 'verbose-name' : 'Virtual I/F',
1631 },
1632 'tenant' : {
1633 'verbose-name' : 'Tenant',
1634 },
1635 'vnsname' : {
1636 'verbose-name': 'VNS ID'
1637 },
1638 'mac' : {
1639 'verbose-name' : 'MAC Address',
1640 'formatter' : fmtcnv.print_host_and_alias,
1641 },
1642 'vlan' : {
1643 'verbose-name' : 'VLAN',
1644 },
1645 'ips' : {
1646 'verbose-name' : 'IP Address',
1647 'formatter' : fmtcnv.print_ip_addresses,
1648 'entry-formatter' : fmtcnv.print_all_ip_addresses,
1649 },
1650 'tags' : {
1651 },
1652 'address-space' : {
1653 'verbose-name' : 'Address Space',
1654 },
1655 'last-seen' : {
1656 'verbose-name' : 'Last Seen',
1657 'formatter' : fmtcnv.print_time_since_utc
1658 }
1659 }
1660 },
1661}
1662
1663
1664VNS_INTERFACE_PHYS_FORMAT = {
1665 'vns-interface-phys' : {
1666 'field-orderings' : {
1667 'default' : ['Idx', 'id', 'address-space', 'switch', 'last-seen' ],
1668 },
1669
1670 'fields' : {
1671 'id' : { 'formatter' : fmtcnv.print_vns_physical_interface_id,
1672 'verbose-name' : 'Physical I/F',
1673 },
1674 'switch' : {
1675 'formatter' : fmtcnv.print_switch_and_alias
1676 },
1677 'address-space' : {
1678 'verbose-name' : 'Address Space',
1679 },
1680 'last-seen' : {
1681 'verbose-name' : 'Last Seen',
1682 'formatter' : fmtcnv.print_time_since_utc
1683 }
1684 }
1685 },
1686}
1687
1688
1689VNS_VNS_SWITCH_PORTS_FORMAT = {
1690 'vns-switch-ports' : {
1691 'field-orderings' : {
1692 'default' : [ 'Idx', 'tenant','vns', 'switch', 'port', 'reason' ],
1693 },
1694
1695 'fields' : {
1696 'tenant' : {
1697 'verbose-name' : 'Tenant',
1698 },
1699 'vnsname' : {
1700 'verbose-name' : 'VNS ID',
1701 },
1702 'switch' : {
1703 'formatter' : fmtcnv.replace_switch_with_alias
1704 },
1705 'port' : {
1706 'verbose-name' : 'OF Port #',
1707 'formatter' : fmtcnv.decode_openflow_port
1708 },
1709 'switch-port' : {
1710 'verbose-name' : 'Phy I/F'
1711 },
1712 'reason' : {
1713 'formatter' : fmtcnv.print_host_list_and_alias
1714 },
1715 }
1716 },
1717}
1718
1719
1720VNS_SWITCH_PORTS_VNS_PORTS_FORMAT = {
1721 'switch-ports-vns' : {
1722 'field-orderings' : {
1723 'default' : [ 'Idx', 'switch', 'port', 'tenant','vnsname', 'reason' ],
1724 },
1725
1726 'fields' : {
1727 'tenant' : {
1728 'verbose-name' : 'Tenant',
1729 },
1730 'vnsname' : { 'verbose-name' : 'VNS',
1731 'formatter' : fmtcnv.print_vns_count_dict
1732 },
1733 'switch' : {
1734 'formatter' : fmtcnv.replace_switch_with_alias
1735 },
1736 'port' : {
1737 'verbose-name' : 'OF Port #',
1738 'formatter' : fmtcnv.decode_openflow_port
1739 },
1740 'reason' : {
1741 'formatter' : fmtcnv.print_host_list_and_alias
1742 },
1743 }
1744 },
1745}
1746
1747
1748VNS_VNS_ACCESS_LIST_FORMAT = {
1749 'vns-access-list': {
1750 'show-this' : [
1751 ['vns-access-list', 'default'],
1752 ['vns-access-list-entry', 'acl-brief']
1753 ],
1754
1755 'field-orderings' : {
1756 'default' : [ 'tenant', 'vns', 'name', 'priority', 'description' ],
1757 'vns-config' : [ 'name', 'priority', 'description' ]
1758 },
1759 'fields' : {
1760 'name' : {
1761 },
1762 }
1763 },
1764}
1765
1766
1767VNS_ACCESS_LIST_ENTRY_FORMAT = {
1768 'vns-access-list-entry': {
1769 'field-orderings' : {
1770 'default' : [ 'Idx', 'vns', 'vns-access-list', 'rule', 'action', 'type',
1771 'src-ip', 'src-ip-mask',
1772 'dst-ip', 'dst-ip-mask',
1773 'src-tp-port-op', 'src-tp-port',
1774 'dst-tp-port-op', 'dst-tp-port',
1775 'icmp-type',
1776 'src-mac', 'dst-mac', 'ether-type',
1777 'vlan'
1778 ],
1779 'vns-config' : ['Idx',
1780 'vns-access-list', 'rule', 'action', 'type',
1781 'src-ip', 'src-ip-mask',
1782 'dst-ip', 'dst-ip-mask' ,
1783 'src-tp-port-op', 'src-tp-port',
1784 'dst-tp-port-op', 'dst-tp-port',
1785 'icmp-type',
1786 'src-mac', 'dst-mac', 'ether-type',
1787 'vlan'
1788 ],
1789 'acl-brief' : ['vns-access-list', 'rule', 'action', 'type', 'acl-text'
1790 ],
1791 'scoped-acl-brief' : [ 'rule', 'action', 'type', 'acl-text'
1792 ],
1793 },
1794 'fields' : {
1795 #
1796 # vns-acl-entry fields are a bit uncommon. the action and type
1797 # can only be configured via the create portion of the command,
1798 # while many other fields requre specific validation so that
1799 # alternate values can be replaced for some keywords
1800 #
1801 # the values of the 'validate' field is the name of the
1802 # def to call (in the SDNSh class)
1803 #
1804 'vns-access-list' : { 'verbose-name' : 'Acl'
1805 },
1806 'rule' : { 'verbose-name' : 'Seq',
1807 },
1808 'action' : { 'verbose-name' : 'Action',
1809 },
1810 'type' : { 'verbose-name' : 'Type',
1811 },
1812 'src-ip' : {
1813 'verbose-name' : 'Src-Ip'
1814 },
1815 'src-ip-mask' : {
1816 'verbose-name' : 'Src-Ip-Mask'
1817 },
1818 'dst-ip' : {
1819 'verbose-name' : 'Dst-Ip' },
1820 'dst-ip-mask' : {
1821 'verbose-name' : 'Dst-Ip-Mask' },
1822 'src-tp-port-op' : {
1823 'verbose-name' : 'Src-Port-Op' },
1824 'src-tp-port' : {
1825 'verbose-name' : 'Src-Port' },
1826 'dst-tp-port-op' : {
1827 'verbose-name' : 'Dst-Port-Op' },
1828 'dst-tp-port' : {
1829 'verbose-name' : 'Dst-Port' },
1830 'icmp-type' : {
1831 },
1832 'ether-type' : {
1833 },
1834 'vns' : {
1835 'verbose-name' : 'VNS ID',
1836 }
1837 }
1838 },
1839}
1840
1841
1842VNS_INTERFACE_ACCESS_LIST_FORMAT = {
1843 'vns-interface-access-list': {
1844 'field-orderings' : {
1845 'default' : [ 'Idx', 'vnsname', 'vns-interface', 'name', 'in-out' ],
1846 'vns-config': [ 'Idx', 'vns-interface', 'name', 'in-out' ]
1847 },
1848 'fields' : {
1849 'vnsname' : {
1850 'verbose-name' : 'VNS ID',
1851 },
1852 'vns-interface-name' : {
1853 'verbose-name' : 'VNS Interface ID',
1854 },
1855 'name' : {
1856 'verbose-name' : 'VNS Acl name',
1857 },
1858 }
1859 },
1860}
1861
1862
1863VNS_INTERFACE_FORMAT = {
1864 'vns-interface' : {
1865 'field-orderings' : {
1866 'default' : ['Idx', 'vns', 'address-space', 'interface', 'rule', 'last-seen', ],
1867 'vns-config' : ['Idx', 'address-space', 'interface', 'rule', 'last-seen', ]
1868 },
1869 'fields' : {
1870 'id' : {
1871 'verbose-name': 'ID',
1872 },
1873 'vns' : {
1874 'verbose-name': 'VNS ID'
1875 },
1876 'interface' : {
1877 'verbose-name': 'VNS Interface Name',
1878 },
1879 'rule' : {
1880 'verbose-name': 'VNS Rule ID',
1881 },
1882 'address-space' : {
1883 'verbose-name' : 'Address Space',
1884 },
1885 'last-seen' : {
1886 'verbose-name': 'Last Seen',
1887 'formatter' : fmtcnv.timestamp_to_local_timestr,
1888 },
1889 }
1890 },
1891}
1892"""