Srikanth Vavilapalli | 1725e49 | 2014-12-01 17:50:52 -0800 | [diff] [blame] | 1 | # |
| 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 | |
| 17 | # |
| 18 | # |
| 19 | |
| 20 | import command |
| 21 | import fmtcnv |
| 22 | import error |
| 23 | |
| 24 | def virtualrouter_origin_external(data): |
| 25 | """ |
| 26 | Return origin-name when the virtualrouter wasn't created by the cli, |
| 27 | return None otherwise. |
| 28 | """ |
| 29 | pk = command.mi.pk('virtualrouter') |
| 30 | if not pk in data: |
| 31 | return None; |
| 32 | |
| 33 | virtualrouter = command.sdnsh.get_table_from_store('virtualrouter', |
| 34 | pk, |
| 35 | data[pk]) |
| 36 | if len(virtualrouter) == 0: |
| 37 | return None |
| 38 | |
| 39 | local = ['cli', 'rest'] |
| 40 | if 'origin' in virtualrouter[0] and not virtualrouter[0]['origin'] in local: |
| 41 | return virtualrouter[0]['origin'] |
| 42 | return None |
| 43 | |
| 44 | def virtualrouter_warn_external_config(data): |
| 45 | """ |
| 46 | From the named virtualrouter, look up the entry, if it exists in the |
| 47 | database, validate the 'origin' is either null, or 'cli', |
| 48 | otherwise provide a warning about this particular virtualrouter |
| 49 | (along with the originator name) |
| 50 | """ |
| 51 | external_origin = virtualrouter_origin_external(data) |
| 52 | if external_origin: |
| 53 | command.sdnsh.warning('router %s may not be intended for cli update, ' |
| 54 | 'origin/creator "%s" ' % (data['id'], external_origin)) |
| 55 | def verify_router_intf_ip(data): |
| 56 | if data['ip-address']=='0.0.0.0': |
| 57 | raise error.ArgumentValidationError("0.0.0.0 is not a valid router interface ip address") |
| 58 | if data['subnet-mask']=='255.255.255.255': |
| 59 | raise error.ArgumentValidationError("0.0.0.0 is not a valid router interface ip subnet mask") |
| 60 | |
| 61 | def verify_router_gw_ip(data): |
| 62 | if data['ip-address']=='0.0.0.0': |
| 63 | raise error.ArgumentValidationError("0.0.0.0 is not a valid router interface ip address") |
| 64 | |
| 65 | def virtualrouter_preprocess(data): |
| 66 | current_mode=command.sdnsh.current_mode() |
| 67 | if current_mode.startswith('config-tenant'): |
| 68 | for x in command.sdnsh.mode_stack: |
| 69 | if x['mode_name'] == 'config-tenant': |
| 70 | tenant = x['obj'] |
| 71 | if current_mode.startswith('config-tenant-router'): |
| 72 | for x in command.sdnsh.mode_stack: |
| 73 | if x['mode_name'] == 'config-tenant-router': |
| 74 | data['virtual-router'] = x['obj'] |
| 75 | if 'outgoing-intf' in data: |
| 76 | current_obj=command.sdnsh.get_current_mode_obj() |
| 77 | if current_mode.startswith('config-tenant-router-intf') or current_mode.startswith('config-tenant-router-gw'): |
| 78 | for x in command.sdnsh.mode_stack: |
| 79 | if x['mode_name'] == 'config-tenant-router': |
| 80 | current_obj = x['obj'] |
| 81 | data['outgoing-intf']=current_obj+'|'+data['outgoing-intf'] |
| 82 | if 'gateway-pool' in data: |
| 83 | current_obj=command.sdnsh.get_current_mode_obj() |
| 84 | if current_mode.startswith('config-tenant-router-intf') or current_mode.startswith('config-tenant-router-gw'): |
| 85 | for x in command.sdnsh.mode_stack: |
| 86 | if x['mode_name'] == 'config-tenant-router': |
| 87 | current_obj = x['obj'] |
| 88 | data['gateway-pool']=current_obj+'|'+data['gateway-pool'] |
| 89 | if 'src-vns' in data: |
| 90 | if not'src-tenant' in data: |
| 91 | data['src-tenant']=tenant |
| 92 | data['src-vns']= data['src-tenant'] + '|' + data ['src-vns'] |
| 93 | if 'dst-vns' in data: |
| 94 | if not 'dst-tenant' in data: |
| 95 | data['dst-tenant']=tenant |
| 96 | data['dst-vns']= data['dst-tenant'] + '|' + data ['dst-vns'] |
| 97 | if 'vns-connected' in data: |
| 98 | data['vns-connected']=tenant+'|'+data['vns-connected'] |
| 99 | if 'router-connected-tenant' in data: |
| 100 | if tenant !='system' and data['router-connected-tenant']!='system': |
| 101 | command.sdnsh.warning('Tenant router interface can only connected to system tenant router\n') |
| 102 | data['router-connected']= data['router-connected-tenant'] +'|'+ data['router-connected'] |
| 103 | del data['router-connected-tenant'] |
| 104 | |
| 105 | command.add_action('virtualrouter-warn-external-config', virtualrouter_warn_external_config, |
| 106 | {'kwargs': {'data' : '$data',}}) |
| 107 | command.add_action('virtualrouter-preprocess', virtualrouter_preprocess, |
| 108 | {'kwargs': {'data' : '$data',}}) |
| 109 | command.add_action('verify-router-intf-ip', verify_router_intf_ip, |
| 110 | {'kwargs': {'data' : '$data',}}) |
| 111 | command.add_action('verify-router-gw-ip', verify_router_gw_ip, |
| 112 | {'kwargs': {'data' : '$data',}}) |
| 113 | |
| 114 | |
| 115 | def complete_virtualrouter_preprocess(data): |
| 116 | obj_id = command.sdnsh.get_current_mode_obj() |
| 117 | if '|' in obj_id: |
| 118 | parts=obj_id.split('|') |
| 119 | data['tenant']=parts[0] |
| 120 | data['virtual-router']=parts[0]+'|' + parts[1] |
| 121 | else: |
| 122 | data['tenant']=obj_id |
| 123 | if 'vrname' in data: |
| 124 | data['virtual-router']=obj_id+'|'+data['vrname'] |
| 125 | if 'router-connected-tenant' in data: |
| 126 | data['tenant'] = data['router-connected-tenant'] |
| 127 | if 'src-tenant' in data: |
| 128 | data['tenant']=data['src-tenant'] |
| 129 | if 'dst-tenant' in data: |
| 130 | data['tenant']=data['dst-tenant'] |
| 131 | |
| 132 | def complete_virtualrouter_postprocess(data,completions): |
| 133 | obj_id = command.sdnsh.get_current_mode_obj() |
| 134 | parts=obj_id.split('|') |
| 135 | tenant=parts[0] |
| 136 | if tenant !='system': #non-system virtual router can only connected to system virtual router |
| 137 | completions.clear() |
| 138 | completions['system ']='Tenant Selection' |
| 139 | else: # system virtual router can't connect to itself |
| 140 | if 'system ' in completions: |
| 141 | del completions['system '] |
| 142 | |
| 143 | command.add_completion('complete-virtualrouter-postprocess', complete_virtualrouter_postprocess, |
| 144 | {'kwargs': {'data': '$data', |
| 145 | 'completions' : '$completions',}}) |
| 146 | command.add_completion('complete-virtualrouter-preprocess', complete_virtualrouter_preprocess, |
| 147 | {'kwargs': {'data': '$data', |
| 148 | }}) |
| 149 | |
| 150 | def virtualrouter_confirm_external_delete(data): |
| 151 | """ |
| 152 | From the named virtualrouter, look up the entry, if it exists in the |
| 153 | database, validate the 'origin' is either null, or 'cli', |
| 154 | otherwise provide a warning about this particular virtualrouter |
| 155 | (along with the originator name) |
| 156 | """ |
| 157 | external_origin = virtualrouter_origin_external(data) |
| 158 | if external_origin: |
| 159 | confirm = command.action_registry['confirm'][0] # XXX accessor? |
| 160 | confirm('virtual router %s may not be intended for cli delete, ' |
| 161 | 'origin/creator "%s"\nEnter y or yes to continue delete: ' |
| 162 | % (data['id'], external_origin)) |
| 163 | |
| 164 | command.add_action('virtualrouter-confirm-external-delete', virtualrouter_confirm_external_delete, |
| 165 | {'kwargs': {'data' : '$data',}}) |
| 166 | |
| 167 | """ |
| 168 | # |
| 169 | # ---------------------------------------------------------------------- |
| 170 | # router submode commands |
| 171 | # |
| 172 | VROUTER_COMMAND_DESCRIPTION = { |
| 173 | 'name' : 'router', |
| 174 | 'help' : 'Enter virtual router definition submode', |
| 175 | 'mode' : 'config-tenant*', |
| 176 | 'command-type' : 'config-submode', |
| 177 | 'obj-type' : 'virtualrouter', |
| 178 | 'submode-name' : 'config-tenant-router', |
| 179 | 'feature' : 'vns', |
| 180 | 'short-help' : 'Enter virtual router definition submode', |
| 181 | 'doc' : 'vns|tenant-vrouter', |
| 182 | 'doc-example' : 'vns|tenant-vrouter-example', |
| 183 | 'args' : ( |
| 184 | { |
| 185 | 'field' : 'vrname', |
| 186 | 'type' : 'identifier', |
| 187 | 'completion' : 'complete-object-field', |
| 188 | 'scoped' : True, |
| 189 | 'syntax-help' : 'Enter a router name', |
| 190 | 'action' : ( |
| 191 | { |
| 192 | 'proc' : 'virtualrouter-warn-external-config', |
| 193 | }, |
| 194 | { 'proc' : 'tenant-show-preprocess' |
| 195 | }, |
| 196 | { |
| 197 | 'proc' : 'push-mode-stack', |
| 198 | }, |
| 199 | ), |
| 200 | 'no-action' : ( |
| 201 | { |
| 202 | 'proc' : 'virtualrouter-confirm-external-delete', |
| 203 | }, |
| 204 | { 'proc' : 'tenant-show-preprocess' |
| 205 | }, |
| 206 | { |
| 207 | 'proc' : 'delete-objects', |
| 208 | }, |
| 209 | ) |
| 210 | } |
| 211 | ), |
| 212 | } |
| 213 | |
| 214 | virtualrouter_show_action = ( |
| 215 | { 'proc' : 'tenant-show-preprocess'}, |
| 216 | { |
| 217 | 'proc' : 'query-table', |
| 218 | }, |
| 219 | { |
| 220 | 'proc' : 'display', |
| 221 | 'format' : 'virtualrouter', |
| 222 | }, |
| 223 | ) |
| 224 | |
| 225 | VIRTUALROUTER_SHOW_COMMAND_DESCRIPTION = { |
| 226 | 'name' : 'show', |
| 227 | 'obj-type' : 'virtualrouter', |
| 228 | 'mode' : 'config-tenant*', |
| 229 | 'command-type' : 'display-table', |
| 230 | 'action' : virtualrouter_show_action, |
| 231 | 'short-help' : 'Show specific virtual router, identified by name', |
| 232 | 'doc' : 'vns|show-tenant-id-router', |
| 233 | 'doc-example' : 'vns|show-tenant-id-router-example', |
| 234 | 'args' : ( |
| 235 | 'router', |
| 236 | ) |
| 237 | } |
| 238 | |
| 239 | VIRTUALROUTER_SHOW_ID_COMMAND_DESCRIPTION = { |
| 240 | 'name' : 'show', |
| 241 | 'obj-type' : 'virtualrouter', |
| 242 | 'mode' : 'config-tenant*', |
| 243 | 'command-type' : 'display-table', |
| 244 | 'action' : virtualrouter_show_action, |
| 245 | 'short-help' : 'Show specific virtual router, identified by name', |
| 246 | 'doc' : 'vns|show-tenant-vrouter-id', |
| 247 | 'doc-example' : 'vns|show-tenant-vrouter-id-example', |
| 248 | 'args' : ( |
| 249 | 'router', |
| 250 | { |
| 251 | 'field' : 'vrname', |
| 252 | 'type' : 'identifier', |
| 253 | 'completion' : 'complete-object-field', |
| 254 | 'help-name' : "virtualrouter-id", |
| 255 | 'scoped' : True, |
| 256 | }, |
| 257 | { |
| 258 | 'optional' : True, |
| 259 | 'choices' : ( |
| 260 | { |
| 261 | 'token' : 'ip-address-pool', |
| 262 | 'obj-type' : 'interface-address-pool', |
| 263 | 'doc' : 'vns|show-tenant-id-router-ippool', |
| 264 | 'action' : ( |
| 265 | { 'proc' : 'tenant-show-preprocess'}, |
| 266 | { 'proc' : 'query-table'}, |
| 267 | { 'proc' : 'display', |
| 268 | 'format' : 'interface-address-pool'}, |
| 269 | ), |
| 270 | }, |
| 271 | { |
| 272 | 'field' : 'route', |
| 273 | 'type' : 'enum', |
| 274 | 'values' : 'route', |
| 275 | 'obj-type' : 'virtualrouter-routingrule', |
| 276 | 'doc' : 'vns|show-tenant-id-router-route', |
| 277 | 'action' : ( |
| 278 | { 'proc' : 'tenant-show-preprocess'}, |
| 279 | { 'proc' : 'query-table',}, |
| 280 | { |
| 281 | 'proc' : 'display', |
| 282 | 'format' : 'virtualrouter-routingrule'}, |
| 283 | ), |
| 284 | }, |
| 285 | ( |
| 286 | { |
| 287 | 'field' : 'interfaces', |
| 288 | 'type' : 'enum', |
| 289 | 'values' : 'interfaces', |
| 290 | 'obj-type' : 'virtualrouter-interface', |
| 291 | 'doc' : 'vns|show-tenant-id-router-interfaces', |
| 292 | 'action' : ( |
| 293 | { 'proc' : 'tenant-show-preprocess'}, |
| 294 | { 'proc' : 'query-table'}, |
| 295 | { 'proc' : 'display', |
| 296 | 'format' : 'virtualrouter-interface'}, |
| 297 | ), |
| 298 | }, |
| 299 | { |
| 300 | 'optional' : True, |
| 301 | 'args' : ( |
| 302 | { |
| 303 | 'field' : 'vriname', |
| 304 | 'obj-type' : 'virtualrouter-interface', |
| 305 | 'completion' : ['complete-virtualrouter-preprocess', |
| 306 | 'complete-from-another'], |
| 307 | 'other' : 'virtualrouter-interface|vriname', |
| 308 | 'scoped' : 'virtual-router', |
| 309 | 'explicit' : True, |
| 310 | 'action' : ( |
| 311 | { 'proc' : 'tenant-show-preprocess'}, |
| 312 | { 'proc' : 'query-table'}, |
| 313 | { 'proc' : 'display', |
| 314 | 'format' : 'virtualrouter-interface'}, |
| 315 | ), |
| 316 | }, |
| 317 | {'optional' : True, |
| 318 | 'token' : 'ip-address-pool', |
| 319 | 'obj-type' : 'interface-address-pool', |
| 320 | 'action' : ( |
| 321 | { 'proc' : 'tenant-show-preprocess'}, |
| 322 | { 'proc' : 'query-table'}, |
| 323 | { 'proc' : 'display', |
| 324 | 'format' : 'interface-address-pool'}, |
| 325 | ), |
| 326 | }, |
| 327 | ), |
| 328 | }, |
| 329 | ), |
| 330 | ( |
| 331 | { |
| 332 | 'field' : 'gateway-pools', |
| 333 | 'type' : 'enum', |
| 334 | 'values' : 'gateway-pools', |
| 335 | 'obj-type' : 'virtualrouter-gwpool', |
| 336 | 'doc' : 'vns|show-tenant-id-router-gwpools', |
| 337 | 'action' : ( |
| 338 | { 'proc' : 'tenant-show-preprocess'}, |
| 339 | { 'proc' : 'query-table'}, |
| 340 | { 'proc' : 'display', |
| 341 | 'format' : 'virtualrouter-gwpool'}, |
| 342 | ), |
| 343 | }, |
| 344 | { |
| 345 | 'optional' : True, |
| 346 | 'args' : ( |
| 347 | { |
| 348 | 'field' : 'vrgwname', |
| 349 | 'obj-type' : 'virtualrouter-gwpool', |
| 350 | 'completion' : ['complete-virtualrouter-preprocess', |
| 351 | 'complete-from-another'], |
| 352 | 'other' : 'virtualrouter-gwpool|vrgwname', |
| 353 | 'scoped' : 'virtual-router', |
| 354 | 'explicit' : True, |
| 355 | 'action' : ( |
| 356 | { 'proc' : 'tenant-show-preprocess'}, |
| 357 | { 'proc' : 'query-table'}, |
| 358 | { 'proc' : 'display', |
| 359 | 'format' : 'virtualrouter-gwpool'}, |
| 360 | ), |
| 361 | }, |
| 362 | {'optional' : True, |
| 363 | 'token' : 'gw-address-pool', |
| 364 | 'obj-type' : 'gateway-address-pool', |
| 365 | 'action' : ( |
| 366 | { 'proc' : 'tenant-show-preprocess'}, |
| 367 | { 'proc' : 'query-table'}, |
| 368 | { 'proc' : 'display', |
| 369 | 'format' : 'gateway-address-pool'}, |
| 370 | ), |
| 371 | }, |
| 372 | ), |
| 373 | }, |
| 374 | ), |
| 375 | ), |
| 376 | }, |
| 377 | ) |
| 378 | } |
| 379 | |
| 380 | VIRTUALROUTER_DEF_DESCRIPTION_COMMAND_DESCRIPTION = { |
| 381 | 'name' : 'description', |
| 382 | 'mode' : 'config-tenant-router', |
| 383 | 'command-type' : 'config', |
| 384 | 'short-help' : 'Provide description for a virtual router instance', |
| 385 | 'doc' : 'vns|tenant-router-description', |
| 386 | 'doc-example' : 'vns|tenant-router-description-example', |
| 387 | 'args' : ( |
| 388 | { |
| 389 | 'field' : 'description', |
| 390 | 'type' : 'string', |
| 391 | } |
| 392 | ), |
| 393 | } |
| 394 | |
| 395 | |
| 396 | VIRTUALROUTER_DEF_ORIGIN_COMMAND_DESCRIPTION = { |
| 397 | 'name' : 'origin', |
| 398 | 'mode' : 'config-tenant-router', |
| 399 | 'command-type' : 'config', |
| 400 | 'short-help' : 'Describe virtual router origin', |
| 401 | 'doc' : 'virtualrouter|origin', |
| 402 | 'doc-example' : 'virtualrouter|origin-example', |
| 403 | 'args' : ( |
| 404 | { |
| 405 | 'field' : 'origin', |
| 406 | 'type' : 'string', |
| 407 | 'action' : ( |
| 408 | { |
| 409 | 'proc' : 'virtualrouter-warn-external-config', |
| 410 | }, |
| 411 | { |
| 412 | 'proc' : 'write-fields', |
| 413 | }, |
| 414 | ), |
| 415 | }, |
| 416 | ), |
| 417 | } |
| 418 | |
| 419 | VIRTUALROUTER_INTF_DEF_ORIGIN_COMMAND_DESCRIPTION = { |
| 420 | 'name' : 'origin', |
| 421 | 'mode' : 'config-tenant-router-intf', |
| 422 | 'command-type' : 'config', |
| 423 | 'short-help' : 'Describe virtual router interface origin', |
| 424 | 'doc' : 'virtualrouter|origin', |
| 425 | 'doc-example' : 'virtualrouter|origin-example', |
| 426 | 'args' : ( |
| 427 | { |
| 428 | 'field' : 'origin', |
| 429 | 'type' : 'string', |
| 430 | 'action' : ( |
| 431 | { |
| 432 | 'proc' : 'virtualrouter-warn-external-config', |
| 433 | }, |
| 434 | { |
| 435 | 'proc' : 'write-fields', |
| 436 | }, |
| 437 | ), |
| 438 | }, |
| 439 | ), |
| 440 | } |
| 441 | |
| 442 | # |
| 443 | # ---------------------------------------------------------------------- |
| 444 | # router interface submode commands |
| 445 | # |
| 446 | VROUTER_INTERFACE_COMMAND_DESCRIPTION = { |
| 447 | 'name' : 'interface', |
| 448 | 'help' : 'Enter virtual router interface definition submode', |
| 449 | 'mode' : 'config-tenant-router*', |
| 450 | 'command-type' : 'config-submode', |
| 451 | 'obj-type' : 'virtualrouter-interface', |
| 452 | 'submode-name' : 'config-tenant-router-intf', |
| 453 | 'short-help' : 'Enter virtual router interface definition submode', |
| 454 | 'doc' : 'vns|tenant-router-interface', |
| 455 | 'doc-example' : 'vns|tenant-router-interface-example', |
| 456 | 'args' : ( |
| 457 | { |
| 458 | 'field' : 'vriname', |
| 459 | 'type' : 'identifier', |
| 460 | 'scoped' : 'virtual-router', |
| 461 | 'explicit' : True, |
| 462 | 'completion' : [ 'complete-virtualrouter-preprocess', |
| 463 | 'complete-object-field', |
| 464 | ], |
| 465 | 'other' : 'virtualrouter-interface|vriname', |
| 466 | 'syntax-help' : 'Enter a router interface name', |
| 467 | 'action' : ( |
| 468 | { |
| 469 | 'proc' : 'virtualrouter-preprocess', |
| 470 | }, |
| 471 | { |
| 472 | 'proc' : 'push-mode-stack', |
| 473 | }, |
| 474 | ), |
| 475 | 'no-action' : ( |
| 476 | { |
| 477 | 'proc' : 'virtualrouter-preprocess', |
| 478 | }, |
| 479 | { |
| 480 | 'proc' : 'delete-objects', |
| 481 | }, |
| 482 | ) |
| 483 | }, |
| 484 | { |
| 485 | 'optional' : True, |
| 486 | 'optional-for-no' : True, |
| 487 | 'choices' : ( |
| 488 | ( |
| 489 | { |
| 490 | 'token' : 'vns', |
| 491 | 'doc' : 'vns|interface-vns-connected', |
| 492 | }, |
| 493 | { |
| 494 | 'field' :'vns-connected', |
| 495 | 'type' : 'identifier', |
| 496 | 'completion' : ['complete-virtualrouter-preprocess', |
| 497 | 'complete-from-another'], |
| 498 | 'other' : 'vns-definition|vnsname', |
| 499 | 'syntax-help' : 'Enter a VNS to connect', |
| 500 | 'scoped' : 'tenant', |
| 501 | |
| 502 | 'explicit' : True, |
| 503 | } |
| 504 | ), |
| 505 | ( |
| 506 | { |
| 507 | 'token' : 'tenant', |
| 508 | 'doc' : 'vns|interface-router-connected', |
| 509 | }, |
| 510 | { 'field' :'router-connected-tenant', |
| 511 | 'type' : 'identifier', |
| 512 | 'completion' : ['complete-from-another', |
| 513 | 'complete-virtualrouter-postprocess'], |
| 514 | 'other' : 'tenant|name', |
| 515 | 'syntax-help' : 'Enter a Tenant Router to connect', |
| 516 | }, |
| 517 | { |
| 518 | 'field' :'router-connected', |
| 519 | 'type' : 'identifier', |
| 520 | 'scoped' : 'tenant', |
| 521 | 'explicit' : True, |
| 522 | 'completion' : ['complete-virtualrouter-preprocess', |
| 523 | 'complete-from-another'], |
| 524 | 'other' : 'virtualrouter|vrname', |
| 525 | 'syntax-help' : 'Enter a Tenant Router to connect', |
| 526 | }, |
| 527 | ) |
| 528 | ), |
| 529 | }, |
| 530 | |
| 531 | ), |
| 532 | } |
| 533 | |
| 534 | VRI_DEF_ACTIVE_COMMAND_DESCRIPTION = { |
| 535 | 'name' : 'active', |
| 536 | 'mode' : 'config-tenant-router-intf', |
| 537 | 'short-help' : 'Set Virtual Router Interface active', |
| 538 | 'doc' : 'vns|tenant-router-active', |
| 539 | 'doc-example' : 'vns|tenant-router-active-example', |
| 540 | 'doc-include' : [ 'default' ], |
| 541 | 'obj-type' : 'virtualrouter-interface', |
| 542 | 'args' : (), |
| 543 | 'action' : ( |
| 544 | { |
| 545 | 'proc' : 'write-fields', |
| 546 | 'data' : { 'active' : True }, |
| 547 | 'syntax-help' : 'mark the interface as active', |
| 548 | } |
| 549 | ), |
| 550 | 'no-action' : ( |
| 551 | { |
| 552 | 'proc' : 'write-fields', |
| 553 | 'data' : { 'active' : False }, |
| 554 | 'syntax-help' : 'mark the interface as inactive', |
| 555 | } |
| 556 | ) |
| 557 | } |
| 558 | |
| 559 | VRI_DEF_IP_COMMAND_DESCRIPTION = { |
| 560 | 'name' : 'ip', |
| 561 | 'mode' : 'config-tenant-router-intf', |
| 562 | 'short-help' : 'Set Virtual Router Interface IP address', |
| 563 | 'doc' : 'vns|tenant-router-interfaceip', |
| 564 | 'doc-example' : 'vns|tenant-router-interfaceip-example', |
| 565 | 'doc-include' : [ 'default' ], |
| 566 | 'parent-field' : 'virtual-router-interface', |
| 567 | 'command-type' : 'config-object', |
| 568 | 'obj-type' : 'interface-address-pool', |
| 569 | 'data' : { |
| 570 | 'ip-address' : None, |
| 571 | 'subnet-mask' : None, |
| 572 | }, |
| 573 | 'args' : ( |
| 574 | { 'choices': ( |
| 575 | ( |
| 576 | { |
| 577 | 'field' : 'ip-address', |
| 578 | 'type' : 'ip-address-not-mask', |
| 579 | 'doc' : 'vns|vns-access-list-ip-and-mask-ip', |
| 580 | }, |
| 581 | { |
| 582 | 'field' : 'subnet-mask', |
| 583 | 'type' : 'netmask', |
| 584 | 'data-handler' : 'convert-inverse-netmask', |
| 585 | 'doc' : 'vns|vns-access-list-ip-and-mask-mask', |
| 586 | }, |
| 587 | ), |
| 588 | ( |
| 589 | { |
| 590 | 'field' : 'ip-address', |
| 591 | 'type' : 'cidr-range', |
| 592 | 'help-name' : 'src-cidr', |
| 593 | 'data-handler' : 'split-cidr-data-inverse', |
| 594 | 'dest-ip' : 'ip-address', |
| 595 | 'dest-netmask' : 'subnet-mask', |
| 596 | 'doc' : 'vns|vns-access-list-cidr-range', |
| 597 | } |
| 598 | ), |
| 599 | ) |
| 600 | } |
| 601 | ), |
| 602 | 'action' : ( { |
| 603 | 'proc' : 'verify-router-intf-ip' |
| 604 | }, |
| 605 | { |
| 606 | 'proc' : 'write-object', |
| 607 | }, |
| 608 | ), |
| 609 | 'no-action' : ( |
| 610 | { |
| 611 | 'proc' : 'delete-objects', |
| 612 | }, |
| 613 | ), |
| 614 | } |
| 615 | |
| 616 | # |
| 617 | # ---------------------------------------------------------------------- |
| 618 | # gateway pool submode commands |
| 619 | # |
| 620 | VROUTER_GWPOOL_COMMAND_DESCRIPTION = { |
| 621 | 'name' : 'gateway-pool', |
| 622 | 'help' : 'Enter virtual router gateway pool submode', |
| 623 | 'mode' : 'config-tenant-router*', |
| 624 | 'command-type' : 'config-submode', |
| 625 | 'obj-type' : 'virtualrouter-gwpool', |
| 626 | 'submode-name' : 'config-tenant-router-gw', |
| 627 | 'short-help' : 'Enter virtual router gateway pool definition submode', |
| 628 | 'doc' : 'vns|tenant-router-gwpool', |
| 629 | 'doc-example' : 'vns|tenant-router-gwpool-example', |
| 630 | 'args' : ( |
| 631 | { |
| 632 | 'field' : 'vrgwname', |
| 633 | 'type' : 'identifier', |
| 634 | 'scoped' : 'virtual-router', |
| 635 | 'explicit' : True, |
| 636 | 'completion' : [ 'complete-virtualrouter-preprocess', |
| 637 | 'complete-object-field', |
| 638 | ], |
| 639 | 'other' : 'virtualrouter-gwpool|vrgwname', |
| 640 | 'syntax-help' : 'Enter a router gateway pool name', |
| 641 | 'action' : ( |
| 642 | { |
| 643 | 'proc' : 'virtualrouter-preprocess', |
| 644 | }, |
| 645 | { |
| 646 | 'proc' : 'push-mode-stack', |
| 647 | }, |
| 648 | ), |
| 649 | 'no-action' : ( |
| 650 | { |
| 651 | 'proc' : 'virtualrouter-preprocess', |
| 652 | }, |
| 653 | { |
| 654 | 'proc' : 'delete-objects', |
| 655 | }, |
| 656 | ) |
| 657 | }, |
| 658 | ), |
| 659 | } |
| 660 | |
| 661 | VRGW_DEF_IP_COMMAND_DESCRIPTION = { |
| 662 | 'name' : 'ip', |
| 663 | 'mode' : 'config-tenant-router-gw', |
| 664 | 'short-help' : 'Add IP address to the gateway pool', |
| 665 | 'doc' : 'vns|tenant-router-gwip', |
| 666 | 'doc-example' : 'vns|tenant-router-gwip-example', |
| 667 | 'doc-include' : [ 'default' ], |
| 668 | 'parent-field' : 'virtual-router-gwpool', |
| 669 | 'command-type' : 'config-object', |
| 670 | 'obj-type' : 'gateway-address-pool', |
| 671 | 'data' : { |
| 672 | 'ip-address' : None, |
| 673 | }, |
| 674 | 'args' : ( |
| 675 | { |
| 676 | 'field' : 'ip-address', |
| 677 | 'type' : 'ip-address-not-mask', |
| 678 | 'doc' : 'vns|vns-access-list-ip-and-mask-ip', |
| 679 | 'action' : ( |
| 680 | { |
| 681 | 'proc' : 'verify-router-gw-ip' |
| 682 | }, |
| 683 | { |
| 684 | 'proc' : 'write-object', |
| 685 | }, |
| 686 | ), |
| 687 | 'no-action' : ( |
| 688 | { |
| 689 | 'proc' : 'delete-objects', |
| 690 | }, |
| 691 | ), |
| 692 | }, |
| 693 | ), |
| 694 | } |
| 695 | |
| 696 | |
| 697 | STATIC_ARP_COMMAND_DESCRIPTION = { |
| 698 | 'name' : 'arp', |
| 699 | 'mode' : 'config*', |
| 700 | 'short-help' : 'Set Static ARP', |
| 701 | 'doc' : 'static-arp', |
| 702 | 'doc-example' : 'static-arp-example', |
| 703 | 'doc-include' : [ 'default' ], |
| 704 | 'command-type' : 'config', |
| 705 | 'obj-type' : 'static-arp', |
| 706 | 'data' : { |
| 707 | 'ip' : None, |
| 708 | 'mac' : None, |
| 709 | }, |
| 710 | 'args' : ( |
| 711 | |
| 712 | { |
| 713 | 'field' : 'ip', |
| 714 | 'type' : 'ip-address-not-mask', |
| 715 | }, |
| 716 | { |
| 717 | 'field' : 'mac', |
| 718 | 'type' : 'mac-address', |
| 719 | }, |
| 720 | |
| 721 | ), |
| 722 | 'action' : ( |
| 723 | { |
| 724 | 'proc' : 'write-object', |
| 725 | }, |
| 726 | ), |
| 727 | 'no-action' : ( |
| 728 | { |
| 729 | 'proc' : 'delete-objects', |
| 730 | }, |
| 731 | ), |
| 732 | } |
| 733 | tenant_show_action = ( |
| 734 | { |
| 735 | 'proc' : 'query-table', |
| 736 | }, |
| 737 | { |
| 738 | 'proc' : 'display', |
| 739 | 'format' : 'staticarp', |
| 740 | }, |
| 741 | ) |
| 742 | |
| 743 | STATIC_ARP_SHOW_COMMAND_DESCRIPTION = { |
| 744 | 'name' : 'show', |
| 745 | 'mode' : 'login', |
| 746 | 'all-help' : 'Show static ARP details', |
| 747 | 'short-help' : 'Show all configured static ARPs', |
| 748 | 'command-type' : 'display-table', |
| 749 | 'obj-type' : 'static-arp', |
| 750 | 'doc' : 'show-arp', |
| 751 | 'doc-example' : 'show-arp-example', |
| 752 | 'action' : tenant_show_action, |
| 753 | 'args' : ( |
| 754 | 'arp', |
| 755 | ) |
| 756 | } |
| 757 | # |
| 758 | # FORMATS |
| 759 | ARP_FORMAT = { |
| 760 | 'staticarp' : { |
| 761 | 'field-orderings' : { |
| 762 | 'default' : [ 'Idx', 'ip', 'mac'], |
| 763 | }, |
| 764 | 'fields' : { |
| 765 | 'ip' : { |
| 766 | }, |
| 767 | 'mac' : { |
| 768 | }, |
| 769 | } |
| 770 | }, |
| 771 | } |
| 772 | SRC_IP_MATCH = { |
| 773 | 'choices' : ( |
| 774 | ( |
| 775 | { |
| 776 | 'field' : 'src-ip', |
| 777 | 'type' : 'ip-address-not-mask', |
| 778 | 'doc' : 'vns|vns-access-list-ip-and-mask-ip', |
| 779 | }, |
| 780 | { |
| 781 | 'field' : 'src-ip-mask', |
| 782 | 'type' : 'netmask', |
| 783 | 'doc' : 'vns|vns-access-list-ip-and-mask-mask', |
| 784 | 'data-handler' : 'convert-inverse-netmask', |
| 785 | }, |
| 786 | ), |
| 787 | ( |
| 788 | { |
| 789 | 'field' : 'src-ip', |
| 790 | 'type' : 'ip-address-not-mask', |
| 791 | 'data' : { |
| 792 | 'src-ip-mask' : '0.0.0.0', |
| 793 | }, |
| 794 | 'doc' : 'vns|vns-access-list-ip-only', |
| 795 | }, |
| 796 | ), |
| 797 | ( |
| 798 | { |
| 799 | 'field' : 'src-ip', |
| 800 | 'type' : 'cidr-range', |
| 801 | 'help-name' : 'src-cidr', |
| 802 | 'data-handler' : 'split-cidr-data-inverse', |
| 803 | 'dest-ip' : 'src-ip', |
| 804 | 'dest-netmask' : 'src-ip-mask', |
| 805 | 'doc' : 'vns|vns-access-list-cidr-range', |
| 806 | } |
| 807 | ), |
| 808 | ( |
| 809 | { |
| 810 | 'token' : 'any', |
| 811 | 'data' : { |
| 812 | 'src-ip' : '0.0.0.0', |
| 813 | 'src-ip-mask' : '255.255.255.255', |
| 814 | }, |
| 815 | 'doc' : 'vns|vns-access-list-ip-any', |
| 816 | } |
| 817 | ), |
| 818 | ) |
| 819 | } |
| 820 | |
| 821 | DST_IP_MATCH = { |
| 822 | 'choices' : ( |
| 823 | ( |
| 824 | { |
| 825 | 'field' : 'dst-ip', |
| 826 | 'type' : 'ip-address-not-mask', |
| 827 | 'doc' : 'vns|vns-access-list-ip-and-mask-ip', |
| 828 | }, |
| 829 | { |
| 830 | 'field' : 'dst-ip-mask', |
| 831 | 'type' : 'netmask', |
| 832 | 'doc' : 'vns|vns-access-list-ip-and-mask-mask', |
| 833 | 'data-handler' : 'convert-inverse-netmask', |
| 834 | }, |
| 835 | ), |
| 836 | ( |
| 837 | { |
| 838 | 'field' : 'dst-ip', |
| 839 | 'type' : 'ip-address-not-mask', |
| 840 | 'data' : { |
| 841 | 'dst-ip-mask' : '0.0.0.0', |
| 842 | }, |
| 843 | 'doc' : 'vns|vns-access-list-ip-only', |
| 844 | }, |
| 845 | ), |
| 846 | ( |
| 847 | { |
| 848 | 'field' : 'dst-ip', |
| 849 | 'type' : 'cidr-range', |
| 850 | 'help-name' : 'dst-cidr', |
| 851 | 'data-handler' : 'split-cidr-data-inverse', |
| 852 | 'dest-ip' : 'dst-ip', |
| 853 | 'dest-netmask' : 'dst-ip-mask', |
| 854 | 'doc' : 'vns|vns-access-list-cidr-range', |
| 855 | }, |
| 856 | ), |
| 857 | ( |
| 858 | { |
| 859 | 'token' : 'any', |
| 860 | 'data' : { |
| 861 | 'dst-ip' : '0.0.0.0', |
| 862 | 'dst-ip-mask' : '255.255.255.255', |
| 863 | }, |
| 864 | 'doc' : 'vns|vns-access-list-ip-any', |
| 865 | } |
| 866 | ), |
| 867 | ) |
| 868 | } |
| 869 | |
| 870 | ROUTING_RULE_COMMAND_DESCRIPTION = { |
| 871 | 'name' : 'route', |
| 872 | 'mode' : 'config-tenant-router*', |
| 873 | 'short-help' : 'Set Routing Rule', |
| 874 | 'doc' : 'vns|tenant-router-route', |
| 875 | 'doc-example' : 'vns|tenant-router-route-example', |
| 876 | 'doc-include' : [ 'default' ], |
| 877 | 'command-type' : 'config-object', |
| 878 | 'obj-type' : 'virtualrouter-routingrule', |
| 879 | 'args' : ( |
| 880 | {'token' : 'from' |
| 881 | }, |
| 882 | { |
| 883 | 'choices': ( |
| 884 | ({'token' : 'tenant'}, |
| 885 | {'field' : 'src-tenant', |
| 886 | 'type' : 'identifier', |
| 887 | 'completion' : 'complete-from-another', |
| 888 | 'other' : 'tenant|name', |
| 889 | 'help-name' : 'source tenant' |
| 890 | }, |
| 891 | { |
| 892 | 'optional' : True, |
| 893 | 'optional-for-no' : True, |
| 894 | 'args' : ( |
| 895 | {'token' : 'vns', |
| 896 | }, |
| 897 | {'field' : 'src-vns', |
| 898 | 'type' : 'identifier', |
| 899 | 'completion' : ['complete-virtualrouter-preprocess', |
| 900 | 'complete-from-another'], |
| 901 | 'other' : 'vns-definition|vnsname', |
| 902 | 'help-name' : 'source VNS', |
| 903 | }, |
| 904 | ), |
| 905 | }, |
| 906 | ), |
| 907 | ({'token' : 'vns', |
| 908 | }, |
| 909 | {'field' : 'src-vns', |
| 910 | 'type' : 'identifier', |
| 911 | 'completion' : 'complete-from-another', |
| 912 | 'other' : 'vns-definition|vnsname', |
| 913 | 'help-name' : 'source VNS', |
| 914 | }, |
| 915 | ), |
| 916 | ( SRC_IP_MATCH, |
| 917 | ) |
| 918 | ) |
| 919 | }, |
| 920 | {'token' : 'to', |
| 921 | }, |
| 922 | { |
| 923 | 'choices': ( |
| 924 | ({'token' : 'tenant'}, |
| 925 | {'field' : 'dst-tenant', |
| 926 | 'type' : 'identifier', |
| 927 | 'completion' : 'complete-from-another', |
| 928 | 'other' : 'tenant|name', |
| 929 | 'help-name' : 'destination tenant' |
| 930 | }, |
| 931 | { |
| 932 | 'optional' : True, |
| 933 | 'optional-for-no' : True, |
| 934 | 'args' : ( |
| 935 | {'token' : 'vns', |
| 936 | }, |
| 937 | {'field' : 'dst-vns', |
| 938 | 'type' : 'identifier', |
| 939 | 'completion' : ['complete-virtualrouter-preprocess', |
| 940 | 'complete-from-another'], |
| 941 | 'other' : 'vns-definition|vnsname', |
| 942 | 'help-name' : 'destination VNS', |
| 943 | }, |
| 944 | ), |
| 945 | }, |
| 946 | ), |
| 947 | ({'token' : 'vns', |
| 948 | }, |
| 949 | {'field' : 'dst-vns', |
| 950 | 'type' : 'identifier', |
| 951 | 'completion' : 'complete-from-another', |
| 952 | 'other' : 'vns-definition|vnsname', |
| 953 | 'help-name' : 'destination VNS', |
| 954 | }, |
| 955 | ), |
| 956 | ( DST_IP_MATCH, |
| 957 | ) |
| 958 | ) |
| 959 | }, |
| 960 | { |
| 961 | 'optional' : True, |
| 962 | 'optional-for-no' : True, |
| 963 | 'choices' : ( |
| 964 | ( |
| 965 | { |
| 966 | 'field' : 'nh-ip', |
| 967 | 'type' : 'ip-address-not-mask', |
| 968 | 'help-name': 'next hop ip address', |
| 969 | 'doc' : 'vns|vns-access-list-ip-only', |
| 970 | }, |
| 971 | ), |
| 972 | ( |
| 973 | {'token' : 'gw-pool', |
| 974 | }, |
| 975 | { |
| 976 | 'field' : 'gateway-pool', |
| 977 | 'type' : 'identifier', |
| 978 | 'scoped' : 'virtual-router', |
| 979 | 'explicit' : True, |
| 980 | 'completion' : ['complete-virtualrouter-preprocess', |
| 981 | 'complete-from-another'], |
| 982 | 'other' : 'virtualrouter-gwpool|vrgwname', |
| 983 | 'help-name' : 'gateway pool name', |
| 984 | 'doc' : 'vns|gateway-pool', |
| 985 | }, |
| 986 | ), |
| 987 | ), |
| 988 | }, |
| 989 | { |
| 990 | 'field' : 'outgoing-intf', |
| 991 | 'type' : 'identifier', |
| 992 | 'scoped' : 'virtual-router', |
| 993 | 'explicit' : True, |
| 994 | 'completion' : ['complete-virtualrouter-preprocess', |
| 995 | 'complete-from-another'], |
| 996 | 'other' : 'virtualrouter-interface|vriname', |
| 997 | 'optional' : True, |
| 998 | 'optional-for-no' : True, |
| 999 | 'help-name' : 'outgoing interface', |
| 1000 | 'doc' : 'vns|outgoing-interface', |
| 1001 | }, |
| 1002 | {'field' : 'action', |
| 1003 | 'type' : 'enum', |
| 1004 | 'values' : ('deny', 'permit'), |
| 1005 | } |
| 1006 | ), |
| 1007 | 'action' : ( |
| 1008 | { |
| 1009 | 'proc' : 'virtualrouter-preprocess' |
| 1010 | }, |
| 1011 | { |
| 1012 | 'proc' : 'write-object', |
| 1013 | }, |
| 1014 | ), |
| 1015 | 'no-action' : ( |
| 1016 | { |
| 1017 | 'proc' : 'virtualrouter-preprocess' |
| 1018 | }, |
| 1019 | { |
| 1020 | 'proc' : 'delete-objects', |
| 1021 | }, |
| 1022 | ), |
| 1023 | } |
| 1024 | |
| 1025 | # FORMATS |
| 1026 | VIRTUALROUTER_FORMAT = { |
| 1027 | 'virtualrouter' : { |
| 1028 | 'field-orderings' : { |
| 1029 | 'default' : [ 'Idx', 'tenant', 'vrname', 'description'], |
| 1030 | 'details' : [ 'Idx', 'tenant', 'vrname', 'description'], |
| 1031 | 'brief' : [ 'Idx', 'tenant', 'vrname'], |
| 1032 | }, |
| 1033 | 'fields' : { |
| 1034 | 'tenant' : { 'verbose-name' : 'Tenant ID', |
| 1035 | }, |
| 1036 | 'vrname' : { |
| 1037 | }, |
| 1038 | 'description' : { |
| 1039 | }, |
| 1040 | } |
| 1041 | }, |
| 1042 | } |
| 1043 | VIRTUALROUTER_INTERFACE_FORMAT = { |
| 1044 | 'virtualrouter-interface' : { |
| 1045 | 'field-orderings' : { |
| 1046 | 'default' : [ 'Idx', 'virtual-router', 'vriname', 'active', 'vns-connected','router-connected'], |
| 1047 | 'details' : [ 'Idx', 'virtual-router', 'vriname', 'active', 'vns-connected','router-connected'], |
| 1048 | 'brief' : [ 'Idx', 'virtual-router', 'vriname', 'active'], |
| 1049 | }, |
| 1050 | 'fields' : { |
| 1051 | 'virtual-router' : {}, |
| 1052 | 'vriname' : {}, |
| 1053 | 'active' : {}, |
| 1054 | 'vns-connected' : {}, |
| 1055 | 'router-connected' : {}, |
| 1056 | } |
| 1057 | }, |
| 1058 | } |
| 1059 | VIRTUALROUTER_GWPOOL_FORMAT = { |
| 1060 | 'virtualrouter-gwpool' : { |
| 1061 | 'field-orderings' : { |
| 1062 | 'default' : [ 'Idx', 'virtual-router', 'vrgwname'], |
| 1063 | 'details' : [ 'Idx', 'virtual-router', 'vrgwname'], |
| 1064 | 'brief' : [ 'Idx', 'virtual-router', 'vrgwname'], |
| 1065 | }, |
| 1066 | 'fields' : { |
| 1067 | 'virtual-router' : {}, |
| 1068 | 'vrgwname' : {}, |
| 1069 | } |
| 1070 | }, |
| 1071 | } |
| 1072 | GATEWAY_ADDRESS_POOL_FORMAT = { |
| 1073 | 'gateway-address-pool' : { |
| 1074 | 'field-orderings' : { |
| 1075 | 'default' : [ 'Idx', 'virtual-router-gwpool', 'ip-address'], |
| 1076 | }, |
| 1077 | 'fields' : { |
| 1078 | 'virtual-router-gwpool' : {'verbose-name' : 'Virtual Router Gateway Pool',}, |
| 1079 | 'ip-address' : {'verbose-name' : 'IP Address',}, |
| 1080 | } |
| 1081 | }, |
| 1082 | } |
| 1083 | VIRTUALROUTER_ROUTINGRULE_FORMAT = { |
| 1084 | 'virtualrouter-routingrule' : { |
| 1085 | 'field-orderings' : { |
| 1086 | 'default' : [ 'Idx', 'virtual-router','action','src-tenant','src-vns','src-ip','src-ip-mask','dst-tenant','dst-vns','dst-ip','dst-ip-mask','nh-ip','gateway-pool','outgoing-intf'], |
| 1087 | }, |
| 1088 | 'fields' : { |
| 1089 | 'virtual-router' : {}, |
| 1090 | 'src-tenant' : {}, |
| 1091 | 'src-vns' : {}, |
| 1092 | 'src-ip' : {}, |
| 1093 | 'src-ip-mask' : {'formatter' : fmtcnv.convert_inverse_netmask_handler,}, |
| 1094 | 'dst-tenant' : {}, |
| 1095 | 'dst-vns' : {}, |
| 1096 | 'dst-ip' : {}, |
| 1097 | 'dst-ip-mask' : {'formatter' : fmtcnv.convert_inverse_netmask_handler,}, |
| 1098 | 'nh-ip' : {}, |
| 1099 | 'gateway-pool' : {}, |
| 1100 | 'outgoing-intf' : {}, |
| 1101 | 'action' : {}, |
| 1102 | } |
| 1103 | }, |
| 1104 | } |
| 1105 | INTERFACE_ADDRESS_POOL_FORMAT = { |
| 1106 | 'interface-address-pool' : { |
| 1107 | 'field-orderings' : { |
| 1108 | 'default' : [ 'Idx', 'virtual-router-interface', 'ip-address', 'subnet-mask'], |
| 1109 | }, |
| 1110 | 'fields' : { |
| 1111 | 'virtual-router-interface' : {'verbose-name' : 'Virtual Router Interface',}, |
| 1112 | 'ip-address' : {'verbose-name' : 'IP Address',}, |
| 1113 | 'subnet-mask' : {'formatter' : fmtcnv.convert_inverse_netmask_handler,}, |
| 1114 | } |
| 1115 | }, |
| 1116 | } |
| 1117 | """ |