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 | import command |
| 17 | import json |
| 18 | import fmtcnv |
| 19 | |
| 20 | """ |
| 21 | SWITCH_SUBMODE_COMMAND_DESCRIPTION = { |
| 22 | 'name' : 'switch', |
| 23 | 'short-help' : 'Enter switch submode, configure switch details', |
| 24 | 'mode' : 'config*', |
| 25 | 'obj-type' : 'switch-config', |
| 26 | 'command-type' : 'config-submode', |
| 27 | 'parent-field' : None, |
| 28 | 'submode-name' : 'config-switch', |
| 29 | 'doc' : 'switch|switch', |
| 30 | 'doc-example' : 'switch|switch-example', |
| 31 | 'args' : ( |
| 32 | { |
| 33 | 'field' : 'dpid', |
| 34 | 'type' : 'dpid', |
| 35 | 'other' : 'switches|dpid', |
| 36 | 'completion' : [ |
| 37 | 'complete-alias-choice', |
| 38 | 'complete-from-another', |
| 39 | ], |
| 40 | 'data-handler' : 'alias-to-value', |
| 41 | 'syntax-help' : 'Configure a new switch with dpid', |
| 42 | } |
| 43 | ) |
| 44 | } |
| 45 | """ |
| 46 | # |
| 47 | # ------------------------------------------------------------------------------ |
| 48 | # show switch |
| 49 | # |
| 50 | |
| 51 | show_switch_pipeline = ( |
| 52 | { |
| 53 | 'proc' : 'query-table', |
| 54 | 'obj-type' : 'switches', # synthetic, supported by rest_to_model |
| 55 | 'key' : 'dpid', |
| 56 | }, |
| 57 | { |
| 58 | 'proc' : 'join-table', |
| 59 | 'obj-type' : 'switch-alias', |
| 60 | 'key' : 'switch', |
| 61 | 'join-field' : '@', |
| 62 | 'add-field' : 'switch-alias|id', |
| 63 | }, |
| 64 | { |
| 65 | 'proc' : 'join-rest', |
| 66 | 'url' : 'tunnel-manager/all', |
| 67 | 'rest-type' : 'dict-of-dict-of-switch', |
| 68 | 'key' : 'switch', |
| 69 | 'join-field' : '@', |
| 70 | }, |
| 71 | { |
| 72 | 'proc' : 'display', |
| 73 | 'format' : 'switch', |
| 74 | }, |
| 75 | ) |
| 76 | |
| 77 | SWITCH_SHOW_COMMAND_DESCRIPTION = { |
| 78 | 'name' : 'show', |
| 79 | 'mode' : 'login', |
| 80 | 'command-type' : 'display-table', |
| 81 | 'all-help' : 'Show switch information', |
| 82 | 'short-help' : 'Show switch summary', |
| 83 | 'obj-type' : 'switches', |
| 84 | 'doc' : 'switch|show', |
| 85 | 'doc-example' : 'switch|show-example', |
| 86 | 'args' : ( |
| 87 | { |
| 88 | 'token' : 'switch', |
| 89 | 'action' : show_switch_pipeline, |
| 90 | 'doc' : 'switch|show', |
| 91 | }, |
| 92 | ) |
| 93 | } |
| 94 | |
| 95 | SWITCH_SHOW_WITH_DPID_COMMAND_DESCRIPTION = { |
| 96 | 'name' : 'show', |
| 97 | 'mode' : 'login', |
| 98 | 'short-help' : 'Show switch details via query', |
| 99 | 'no-supported' : False, |
| 100 | 'parent-field' : None, |
| 101 | 'obj-type' : 'switches', |
| 102 | 'args' : ( |
| 103 | { |
| 104 | 'token' : 'switch', |
| 105 | 'obj-type' : 'switches', |
| 106 | 'command-type' : 'display-table', |
| 107 | # 'command-type' : 'display-rest', |
| 108 | 'action' : show_switch_pipeline, |
| 109 | }, |
| 110 | { |
| 111 | 'choices' : ( |
| 112 | { |
| 113 | 'field' : 'dpid', |
| 114 | 'completion' : 'complete-alias-choice', |
| 115 | 'type' : 'dpid', |
| 116 | 'help-name' : 'switch dpid or alias', |
| 117 | 'data-handler' : 'alias-to-value', |
| 118 | }, |
| 119 | { |
| 120 | 'token' : 'all', |
| 121 | }, |
| 122 | ), |
| 123 | }, |
| 124 | { |
| 125 | 'optional' : True, |
| 126 | 'choices' : ( |
| 127 | ( |
| 128 | { |
| 129 | 'token' : 'by', |
| 130 | 'doc' : 'switch|show-switch-order', |
| 131 | }, |
| 132 | { |
| 133 | 'choices' : ( |
| 134 | { |
| 135 | 'token' : 'ip-address', |
| 136 | 'sort' : 'ip-address', |
| 137 | 'action' : 'display-table', |
| 138 | 'short-help' : 'Sort by ip-address', |
| 139 | }, |
| 140 | { |
| 141 | 'token' : 'connect-time', |
| 142 | 'sort' : '-connected-since', |
| 143 | 'action' : 'display-table', |
| 144 | 'short-help' : 'Sort by connect time', |
| 145 | }, |
| 146 | ) |
| 147 | } |
| 148 | ), |
| 149 | ) |
| 150 | }, |
| 151 | { |
| 152 | 'field' : 'detail', |
| 153 | 'type' : 'enum', |
| 154 | 'values' : ('details','brief'), |
| 155 | 'optional' : True, |
| 156 | 'doc' : 'switch|show-switch-format-+', |
| 157 | }, |
| 158 | ) |
| 159 | } |
| 160 | SWITCH_SHOW_REALTIME_STATS_COMMAND_DESCRIPTION = { |
| 161 | 'name' : 'show', |
| 162 | 'mode' : 'login', |
| 163 | 'short-help' : 'Show switch stats via direct query to switch', |
| 164 | 'no-supported' : False, |
| 165 | 'short-help' : 'Show realtime stats for switch', |
| 166 | 'parent-field' : None, |
| 167 | 'obj-type' : 'switches', |
| 168 | 'args' : ( |
| 169 | { |
| 170 | 'token' : 'switch', |
| 171 | 'obj-type' : 'switches', |
| 172 | 'command-type' : 'display-table', |
| 173 | # 'command-type' : 'display-rest', |
| 174 | }, |
| 175 | { |
| 176 | 'choices' : ( |
| 177 | { |
| 178 | 'field' : 'dpid', |
| 179 | 'completion' : 'complete-alias-choice', |
| 180 | 'type' : 'dpid', |
| 181 | 'help-name' : 'switch dpid or alias', |
| 182 | 'data-handler' : 'alias-to-value', |
| 183 | 'data' : { 'detail' : 'scoped' }, |
| 184 | }, |
| 185 | { |
| 186 | 'token' : 'all', |
| 187 | 'doc' : 'reserved|all', |
| 188 | }, |
| 189 | ), |
| 190 | }, |
| 191 | { |
| 192 | 'choices' : ( |
| 193 | ( |
| 194 | { |
| 195 | 'field' : 'realtimestats', |
| 196 | 'type' : 'enum', |
| 197 | 'values' : ('aggregate', |
| 198 | 'port', |
| 199 | 'desc', |
| 200 | 'queue', |
| 201 | 'group' |
| 202 | ), |
| 203 | 'action' : 'display-rest', |
| 204 | 'sort' : ['groupid',], |
| 205 | 'url' : [ |
| 206 | 'realtimestats/%(realtimestats)s/%(dpid)s/', |
| 207 | 'realtimestats/%(realtimestats)s/all/', |
| 208 | ], |
| 209 | 'rest-type' : 'dict-of-list-of-switch', |
| 210 | 'format' : 'realtime_%(realtimestats)s', |
| 211 | 'short-help' : 'Show requested item by querying switch', |
| 212 | 'doc' : 'switch|realtime-+', |
| 213 | }, |
| 214 | ), |
| 215 | ( |
| 216 | { |
| 217 | 'field' : 'realtimestats', |
| 218 | 'type' : 'enum', |
| 219 | 'values' : 'features', |
| 220 | 'action' : 'display-rest', |
| 221 | 'url' : [ |
| 222 | 'realtimestats/%(realtimestats)s/%(dpid)s/', |
| 223 | 'realtimestats/%(realtimestats)s/all/', |
| 224 | ], |
| 225 | 'rest-type' : 'dict-of-dict-of-switch|ports', |
| 226 | 'format' : 'realtime_%(realtimestats)s', |
| 227 | 'doc' : 'switch|realtime_features', |
| 228 | }, |
| 229 | { |
| 230 | 'field' : 'detail', |
| 231 | 'optional' : True, |
| 232 | 'type' : 'enum', |
| 233 | 'values' : ('details','brief'), |
| 234 | 'doc' : 'format|+', |
| 235 | }, |
| 236 | ), |
| 237 | ( |
| 238 | { |
| 239 | 'field' : 'realtimestats', |
| 240 | 'type' : 'enum', |
| 241 | 'values' : 'table', |
| 242 | }, |
| 243 | { |
| 244 | 'field' : 'tabletype', |
| 245 | 'type' : 'enum', |
| 246 | 'values' : ('ip', |
| 247 | 'acl', |
| 248 | 'mpls' |
| 249 | ), |
| 250 | 'sort' : ['mplsLabel','priority',], |
| 251 | 'action' : 'display-rest', |
| 252 | 'url' : 'realtimestats/%(realtimestats)s/%(tabletype)s/flow/%(dpid)s/', |
| 253 | 'rest-type' : 'dict-of-list-of-switch', |
| 254 | 'format' : 'realtime_%(realtimestats)s_%(tabletype)s_flow', |
| 255 | 'doc' : 'format|+', |
| 256 | }, |
| 257 | ), |
| 258 | ( |
| 259 | { |
| 260 | 'field' : 'realtimestats', |
| 261 | 'type' : 'enum', |
| 262 | 'values' : 'group', |
| 263 | }, |
| 264 | { |
| 265 | 'field' : 'groupId', |
| 266 | #'data' : { |
| 267 | # 'dpid' : '$dpid', |
| 268 | # }, |
| 269 | #'type' : 'groupId', |
| 270 | 'completion' : 'group-id-completion', |
| 271 | #'sort' : ['mplsLabel','priority',], |
| 272 | 'action' : 'display-rest', |
| 273 | 'url' : 'realtimestats/%(realtimestats)s/%(groupId)s/%(dpid)s/', |
| 274 | 'rest-type' : 'dict-of-list-of-switch', |
| 275 | 'format' : 'realtime_group', |
| 276 | 'doc' : 'format|+', |
| 277 | }, |
| 278 | ), |
| 279 | ) |
| 280 | } |
| 281 | ) |
| 282 | } |
| 283 | |
| 284 | SWITCH_SHOW_STATS_COMMAND_DESCRIPTION = { |
| 285 | 'name' : 'show', |
| 286 | 'mode' : 'login', |
| 287 | 'short-help' : 'Show switch stats', |
| 288 | 'short-help' : 'show stats for selected switch', |
| 289 | 'no-supported' : False, |
| 290 | 'parent-field' : None, |
| 291 | 'obj-type' : 'switches', |
| 292 | 'args' : ( |
| 293 | { |
| 294 | 'token' : 'switch', |
| 295 | # 'command-type' : 'display-rest', |
| 296 | }, |
| 297 | { |
| 298 | 'field' : 'dpid', |
| 299 | 'completion' : 'complete-alias-choice', |
| 300 | 'type' : 'dpid', |
| 301 | 'help-name' : 'switch dpid or alias', |
| 302 | 'data-handler' : 'alias-to-value', |
| 303 | }, |
| 304 | { |
| 305 | 'token' : 'stats', |
| 306 | 'action' : 'legacy-cli', |
| 307 | 'obj-type' : 'switch-stats', |
| 308 | }, |
| 309 | ) |
| 310 | } |
| 311 | |
| 312 | SWITCH_SHOW_STATS_OBJECT_DETAILS_COMMAND_DESCRIPTION = { |
| 313 | 'name' : 'show', |
| 314 | 'mode' : 'login', |
| 315 | 'short-help' : 'Show statistics for a given switch', |
| 316 | 'no-supported' : False, |
| 317 | 'parent-field' : None, |
| 318 | 'obj-type' : 'switches', |
| 319 | 'args' : ( |
| 320 | { |
| 321 | 'token' : 'switch', |
| 322 | # 'command-type' : 'display-rest', |
| 323 | }, |
| 324 | { |
| 325 | 'field' : 'dpid', |
| 326 | 'completion' : 'complete-alias-choice', |
| 327 | 'type' : 'dpid', |
| 328 | 'help-name' : 'switch dpid or alias', |
| 329 | 'data-handler' : 'alias-to-value', |
| 330 | }, |
| 331 | { |
| 332 | 'token' : 'stats', |
| 333 | 'action' : 'legacy-cli', |
| 334 | 'obj-type' : 'switch-stats', |
| 335 | }, |
| 336 | { |
| 337 | 'field' : 'stats-type', |
| 338 | 'type' : 'enum', |
| 339 | 'values' : ( |
| 340 | 'OFActiveFlow', |
| 341 | 'OFFlowMod', |
| 342 | 'OFPacketIn', |
| 343 | ), |
| 344 | }, |
| 345 | { |
| 346 | 'field' : 'start-time', |
| 347 | 'tag' : 'start-time', |
| 348 | 'type' : 'date', |
| 349 | 'data-handler' : 'date-to-integer', |
| 350 | 'short-help' : 'Start time for displaying the stats', |
| 351 | 'optional' : True, |
| 352 | }, |
| 353 | { |
| 354 | 'field' : 'end-time', |
| 355 | 'tag' : 'end-time', |
| 356 | 'type' : 'date', |
| 357 | 'data-handler' : 'date-to-integer', |
| 358 | 'short-help' : 'End time for displaying the stats', |
| 359 | 'optional' : True, |
| 360 | }, |
| 361 | { |
| 362 | 'field' : 'duration', |
| 363 | 'tag' : 'duration', |
| 364 | 'type' : 'duration', |
| 365 | 'short-help' : 'Duration from the start or end for displaying the stats', |
| 366 | 'optional' : True, |
| 367 | }, |
| 368 | { |
| 369 | 'field' : 'sample-interval', |
| 370 | 'tag' : 'sample-interval', |
| 371 | 'type' : 'integer', |
| 372 | 'short-help' : 'Spacing between sampling windows', |
| 373 | 'optional' : True, |
| 374 | }, |
| 375 | { |
| 376 | 'field' : 'sample-count', |
| 377 | 'tag' : 'sample-count', |
| 378 | 'type' : 'integer', |
| 379 | 'short-help' : 'Number of samples in each window', |
| 380 | 'optional' : True, |
| 381 | }, |
| 382 | { |
| 383 | 'field' : 'sample-window', |
| 384 | 'tag' : 'sample-window', |
| 385 | 'type' : 'integer', |
| 386 | 'short-help' : 'Window length for sampling', |
| 387 | 'optional' : True, |
| 388 | }, |
| 389 | { |
| 390 | 'field' : 'data-format', |
| 391 | 'tag' : 'data-format', |
| 392 | 'type' : 'enum', |
| 393 | 'values' : ('value', 'rate',), |
| 394 | 'short-help' : 'Whether to display as a raw value or rate', |
| 395 | 'optional' : True, |
| 396 | }, |
| 397 | { |
| 398 | 'field' : 'display', |
| 399 | 'tag' : 'display', |
| 400 | 'type' : 'enum', |
| 401 | 'values' : ('latest-value', 'graph', 'table'), |
| 402 | 'short-help' : 'Display the latest value, a graph, or a table', |
| 403 | 'optional' : True, |
| 404 | }, |
| 405 | ), |
| 406 | } |
| 407 | |
| 408 | |
| 409 | show_switch_interfaces_pipeline = ( |
| 410 | { |
| 411 | 'proc' : 'query-table', |
| 412 | 'obj-type' : 'interfaces', |
| 413 | 'key' : 'id', |
| 414 | }, |
| 415 | { |
| 416 | 'proc' : 'query-table-append', |
| 417 | 'obj-type' : 'switch-interface-config', |
| 418 | 'key' : 'id', |
| 419 | }, |
| 420 | { |
| 421 | 'proc' : 'join-rest', |
| 422 | 'url' : [ |
| 423 | # this is using 'switch' from previous results, |
| 424 | # not from the data items |
| 425 | 'realtimestats/port/%(switch)s/', |
| 426 | ], |
| 427 | 'rest-type' : 'dict-of-list-of-switch|portNumber', |
| 428 | 'key' : 'switch|portNumber', |
| 429 | 'join-field' : 'switch|portNumber' |
| 430 | }, |
| 431 | { |
| 432 | 'proc' : 'display', |
| 433 | 'sort' : ['switch', 'portName'], |
| 434 | 'format' : 'switch-interfaces', |
| 435 | }, |
| 436 | ) |
| 437 | |
| 438 | SWITCH_SHOW_SWITCH_DPID_INTERFACES_COMMAND_DESCRIPTION = { |
| 439 | 'name' : 'show', |
| 440 | 'mode' : 'login', |
| 441 | 'no-supported' : False, |
| 442 | 'short-help' : 'Show interfaces for selected switch', |
| 443 | 'parent-field' : None, |
| 444 | 'obj-type' : 'switches', |
| 445 | 'args' : ( |
| 446 | { |
| 447 | 'token' : 'switch', |
| 448 | 'command-type' : 'display-table', |
| 449 | }, |
| 450 | { |
| 451 | 'choices' : ( |
| 452 | { |
| 453 | 'field' : 'dpid', |
| 454 | 'completion' : 'complete-alias-choice', |
| 455 | 'type' : 'dpid', |
| 456 | 'help-name' : 'switch dpid or alias', |
| 457 | 'data-handler' : 'alias-to-value', |
| 458 | }, |
| 459 | { |
| 460 | 'field' : 'dpid', |
| 461 | 'type' : 'enum', |
| 462 | 'values' : 'all', |
| 463 | 'short-help' : 'Show interfaces for all switches', |
| 464 | }, |
| 465 | ), |
| 466 | }, |
| 467 | { |
| 468 | 'choices' : ( |
| 469 | ( |
| 470 | { |
| 471 | 'token' : 'interfaces', |
| 472 | 'action' : 'legacy-cli', |
| 473 | 'obj-type' : 'switch-interfaces', |
| 474 | 'action' : show_switch_interfaces_pipeline, |
| 475 | 'short-help' : 'Show interfaces for switches', |
| 476 | 'doc' : 'switch|show-interfaces', |
| 477 | }, |
| 478 | { |
| 479 | 'token' : 'stats', |
| 480 | 'action' : 'display-rest', |
| 481 | 'url' : 'realtimestats/port/%(dpid)s/', |
| 482 | 'rest-type' : 'dict-of-list-of-switch', |
| 483 | 'format' : 'realtime_port', |
| 484 | 'rest-type' : 'dict-of-list-of-switch', |
| 485 | 'optional' : True, |
| 486 | 'short-help' : 'Show interfaces stats for switches', |
| 487 | }, |
| 488 | { |
| 489 | 'token' : 'alias', |
| 490 | 'action' : 'display-table', |
| 491 | 'obj-type' : 'switch-interface-alias', |
| 492 | 'optional' : True, |
| 493 | 'short-help' : 'Show interface aliases for switches', |
| 494 | 'scoped' : True, |
| 495 | 'doc' : 'switch|show-interfaces-alias', |
| 496 | } |
| 497 | ), |
| 498 | #{ |
| 499 | # 'field' : 'vns', |
| 500 | # 'type' : 'enum', |
| 501 | # 'values' : 'vns', |
| 502 | # 'action' : 'legacy-cli', |
| 503 | # 'obj-type' : 'switch-ports-vns' |
| 504 | #}, |
| 505 | { |
| 506 | 'field' : 'alias', |
| 507 | 'type' : 'enum', |
| 508 | 'values' : 'alias', |
| 509 | 'obj-type' : 'switch-alias', |
| 510 | 'action' : 'display-table', |
| 511 | 'doc' : 'switch|show-switch-alias', |
| 512 | }, |
| 513 | ) |
| 514 | }, |
| 515 | { |
| 516 | 'optional' : True, |
| 517 | 'field' : 'detail', |
| 518 | 'type' : 'enum', |
| 519 | 'values' : ('details', 'brief',), |
| 520 | 'short-help' : 'Show switch output format level', |
| 521 | } |
| 522 | ) |
| 523 | } |
| 524 | """ |
| 525 | SWITCH_SUBMODE_SHOW_INTERFACE_COMMAND_DESCRIPTION = { |
| 526 | 'name' : 'show', |
| 527 | 'mode' : 'config-switch*', |
| 528 | 'command-type' : 'display-table', |
| 529 | 'obj-type' : 'switch-interfaces', |
| 530 | 'short-help' : 'Show interfaces for switch associated with current submode', |
| 531 | 'args' : ( |
| 532 | { |
| 533 | 'token' : 'interfaces', |
| 534 | 'action' : 'legacy-cli', |
| 535 | 'scoped' : True, |
| 536 | 'action' : show_switch_interfaces_pipeline, |
| 537 | }, |
| 538 | ) |
| 539 | } |
| 540 | |
| 541 | |
| 542 | SWITCH_SHOW_TCPDUMP_COMMAND_DESCRIPTION = { |
| 543 | 'name' : 'show', |
| 544 | 'mode' : 'login', |
| 545 | 'short-help' : 'Show switch tcpdump via controller', |
| 546 | 'no-supported' : False, |
| 547 | 'parent-field' : None, |
| 548 | 'current-mode-obj-id' : None, |
| 549 | 'obj-type' : 'switches', |
| 550 | 'args' : ( |
| 551 | { |
| 552 | 'token' : 'switch', |
| 553 | 'obj-type' : 'switches', |
| 554 | }, |
| 555 | { |
| 556 | 'field' : 'dpid', |
| 557 | 'optional' : False, |
| 558 | 'completion' : 'complete-alias-choice', |
| 559 | 'type' : 'dpid', |
| 560 | 'help-name' : 'switch dpid or alias', |
| 561 | 'data-handler' : 'alias-to-value', |
| 562 | }, |
| 563 | { |
| 564 | 'field' : 'tcpdump', |
| 565 | 'optional' : False, |
| 566 | 'type' : 'enum', |
| 567 | 'values' : 'trace', |
| 568 | 'obj-type' : 'switch-tcpdump', |
| 569 | 'action' : 'legacy-cli', |
| 570 | }, |
| 571 | { |
| 572 | 'field' : 'oneline', |
| 573 | 'type' : 'enum', |
| 574 | 'values' : 'oneline', |
| 575 | 'optional' : True, |
| 576 | }, |
| 577 | { |
| 578 | 'field' : 'single_session', |
| 579 | 'type' : 'enum', |
| 580 | 'values' : 'single-session', |
| 581 | 'optional' : True, |
| 582 | }, |
| 583 | { |
| 584 | 'field' : 'echo_reply', |
| 585 | 'type' : 'enum', |
| 586 | 'values' : 'echo-reply', |
| 587 | 'optional' : True, |
| 588 | 'permute' : 'skip', |
| 589 | }, |
| 590 | { |
| 591 | 'field' : 'echo_request', |
| 592 | 'type' : 'enum', |
| 593 | 'values' : 'echo-request', |
| 594 | 'optional' : True, |
| 595 | 'permute' : 'skip', |
| 596 | }, |
| 597 | { |
| 598 | 'field' : 'features_rep', |
| 599 | 'type' : 'enum', |
| 600 | 'values' : 'features-rep', |
| 601 | 'optional' : True, |
| 602 | 'permute' : 'skip', |
| 603 | }, |
| 604 | { |
| 605 | 'field' : 'flow_mod', |
| 606 | 'type' : 'enum', |
| 607 | 'values' : 'flow-mod', |
| 608 | 'optional' : True, |
| 609 | 'permute' : 'skip', |
| 610 | }, |
| 611 | { |
| 612 | 'field' : 'flow_removed', |
| 613 | 'type' : 'enum', |
| 614 | 'values' : 'flow-removed', |
| 615 | 'optional' : True, |
| 616 | 'permute' : 'skip', |
| 617 | }, |
| 618 | { |
| 619 | 'field' : 'get_config_rep', |
| 620 | 'type' : 'enum', |
| 621 | 'values' : 'get-config-rep', |
| 622 | 'optional' : True, |
| 623 | 'permute' : 'skip', |
| 624 | }, |
| 625 | { |
| 626 | 'field' : 'hello', |
| 627 | 'type' : 'enum', |
| 628 | 'values' : 'hello', |
| 629 | 'optional' : True, |
| 630 | 'permute' : 'skip', |
| 631 | }, |
| 632 | { |
| 633 | 'field' : 'packet_in', |
| 634 | 'type' : 'enum', |
| 635 | 'values' : 'packet-in', |
| 636 | 'optional' : True, |
| 637 | 'permute' : 'skip', |
| 638 | }, |
| 639 | { |
| 640 | 'field' : 'packet_out', |
| 641 | 'type' : 'enum', |
| 642 | 'values' : 'packet-out', |
| 643 | 'optional' : True, |
| 644 | 'permute' : 'skip', |
| 645 | }, |
| 646 | { |
| 647 | 'field' : 'port_status', |
| 648 | 'type' : 'enum', |
| 649 | 'values' : 'port-status', |
| 650 | 'optional' : True, |
| 651 | 'permute' : 'skip', |
| 652 | }, |
| 653 | { |
| 654 | 'field' : 'set_config', |
| 655 | 'type' : 'enum', |
| 656 | 'values' : 'set-config', |
| 657 | 'optional' : True, |
| 658 | 'permute' : 'skip', |
| 659 | }, |
| 660 | { |
| 661 | 'field' : 'stats_reply', |
| 662 | 'type' : 'enum', |
| 663 | 'values' : 'stats-reply', |
| 664 | 'optional' : True, |
| 665 | 'permute' : 'skip', |
| 666 | }, |
| 667 | { |
| 668 | 'field' : 'stats_request', |
| 669 | 'type' : 'enum', |
| 670 | 'values' : 'stats-request', |
| 671 | 'optional' : True, |
| 672 | 'permute' : 'skip', |
| 673 | }, |
| 674 | { |
| 675 | 'field' : 'detail', |
| 676 | 'type' : 'enum', |
| 677 | 'values' : 'detail', |
| 678 | 'optional' : True, |
| 679 | }, |
| 680 | ) |
| 681 | } |
| 682 | |
| 683 | # |
| 684 | # ------------------------------------------------------------------------------ |
| 685 | # SWITCH_TUNNEL_SHOW_COMMAND_DESCRIPTION |
| 686 | # |
| 687 | |
| 688 | show_tunnel_pipeline = ( |
| 689 | { |
| 690 | 'proc' : 'query-rest', |
| 691 | 'url' : [ |
| 692 | 'tunnel-manager/%(dpid)s', |
| 693 | 'tunnel-manager/all', |
| 694 | ], |
| 695 | 'rest-type' : 'dict-of-dict-of-dpid', |
| 696 | }, |
| 697 | { |
| 698 | 'proc' : 'join-table', |
| 699 | 'obj-type' : 'interfaces', |
| 700 | 'key' : 'switch|portName', |
| 701 | 'join-field' : 'hexDpid|tunnelEndPointIntfName', |
| 702 | 'add-field' : 'portNumber|portNumber', |
| 703 | }, |
| 704 | { |
| 705 | 'proc' : 'join-rest', |
| 706 | 'url' : 'realtimestats/port/%(dpid)s/', |
| 707 | 'rest-type' : 'dict-of-list-of-switch|portNumber', |
| 708 | 'key' : 'switch|portNumber', |
| 709 | 'join-field' : 'hexDpid|portNumber', |
| 710 | }, |
| 711 | { |
| 712 | 'proc' : 'display', |
| 713 | 'format' : 'tunnel-pipeline', |
| 714 | } |
| 715 | ) |
| 716 | """ |
| 717 | import fmtcnv |
| 718 | """ |
| 719 | TUNNEL_PIPELINE_FORMAT = { |
| 720 | 'tunnel-pipeline' : { |
| 721 | 'field-orderings' : { |
| 722 | 'default' : [ 'Idx', |
| 723 | 'dpid', |
| 724 | 'tunnelCapable', |
| 725 | 'tunnelEnabled', |
| 726 | 'tunnelEndPointIntfName', |
| 727 | 'tunnelIPAddr', |
| 728 | 'tunnelState', |
| 729 | 'receivePackets', |
| 730 | 'receiveBytes', |
| 731 | 'transmitPackets', |
| 732 | 'transmitBytes', |
| 733 | ] |
| 734 | }, |
| 735 | |
| 736 | 'fields' : { |
| 737 | 'dpid' : { |
| 738 | 'verbose-name' : 'Switch DPID', |
| 739 | 'primary_key': True, |
| 740 | 'formatter' : fmtcnv.replace_switch_with_alias, |
| 741 | }, |
| 742 | 'tunnelCapable' : { |
| 743 | 'verbose-name' : 'Capable', |
| 744 | }, |
| 745 | 'tunnelEnabled' : { |
| 746 | 'verbose-name' : 'Enabled', |
| 747 | }, |
| 748 | 'tunnelEndPointIntfName' : { |
| 749 | 'verbose-name' : 'IF Name', |
| 750 | }, |
| 751 | 'tunnelIPAddr' : { |
| 752 | 'verbose-name' : 'IP Address', |
| 753 | }, |
| 754 | 'tunnelState' : { |
| 755 | 'verbose-name' : 'State', |
| 756 | }, |
| 757 | 'receivePackets' : { |
| 758 | 'verbose-name' : 'Rx Pkts', |
| 759 | }, |
| 760 | 'receiveBytes' : { |
| 761 | 'verbose-name' : 'Rx Bytes', |
| 762 | }, |
| 763 | 'transmitPackets' : { |
| 764 | 'verbose-name' : 'Tx Pkts', |
| 765 | }, |
| 766 | 'transmitBytes' : { |
| 767 | 'verbose-name' : 'Tx Bytes', |
| 768 | }, |
| 769 | }, |
| 770 | }, |
| 771 | } |
| 772 | |
| 773 | |
| 774 | |
| 775 | SWITCH_TUNNEL_SHOW_COMMAND_DESCRIPTION = { |
| 776 | 'name' : 'show', |
| 777 | 'mode' : 'login', |
| 778 | 'feature' : 'vns', |
| 779 | 'short-help' : 'Show tunnels for all switches', |
| 780 | 'command-type' : 'display-rest', |
| 781 | 'url' : 'tunnel-manager/all', |
| 782 | 'obj-type' : 'switch', |
| 783 | 'action' : show_tunnel_pipeline, |
| 784 | 'args' : ( |
| 785 | 'tunnel', |
| 786 | ), |
| 787 | } |
| 788 | |
| 789 | |
| 790 | SWITCH_TUNNEL_SHOW_WITH_DPID_COMMAND_DESCRIPTION = { |
| 791 | 'name' : 'show', |
| 792 | 'mode' : 'login', |
| 793 | 'feature' : 'vns', |
| 794 | 'short-help' : 'Show tunnels for selected switches', |
| 795 | 'command-type' : 'display-rest', |
| 796 | 'obj-type' : 'switch', |
| 797 | 'url' : 'tunnel-manager/%(dpid)s', |
| 798 | 'format' : 'tunnel-details', |
| 799 | 'action' : show_tunnel_pipeline, |
| 800 | 'args' : ( |
| 801 | 'tunnel', |
| 802 | { |
| 803 | 'choices' : ( |
| 804 | { |
| 805 | 'field' : 'dpid', |
| 806 | 'type' : 'enum', |
| 807 | 'values' : 'all', |
| 808 | }, |
| 809 | { |
| 810 | 'field' : 'dpid', |
| 811 | 'completion' : 'complete-object-field', |
| 812 | 'type' : 'dpid', |
| 813 | }, |
| 814 | ), |
| 815 | }, |
| 816 | ), |
| 817 | } |
| 818 | # |
| 819 | # ------------------------------------------------------------------------------ |
| 820 | # SWITCH_CORE_SWITCH_TERMINATION_COMMAND_DESCRIPTION |
| 821 | # |
| 822 | |
| 823 | SWITCH_CORE_SWITCH_COMMAND_DESCRIPTION = { |
| 824 | 'name' : 'core-switch', |
| 825 | 'short-help' : 'Enable core-switch property for this switch', |
| 826 | 'mode' : 'config-switch', |
| 827 | 'parent-field' : 'dpid', |
| 828 | 'obj-type' : 'switch-config', |
| 829 | 'doc' : 'switch|core-switch', |
| 830 | 'doc-example' : 'switch|core-switch-example', |
| 831 | 'args' : (), |
| 832 | 'action': ( |
| 833 | { |
| 834 | 'proc' : 'update-config', |
| 835 | 'data' : {'core-switch' : True} |
| 836 | }, |
| 837 | ), |
| 838 | 'no-action': ( |
| 839 | { |
| 840 | 'proc' : 'update-config', |
| 841 | 'data' : {'core-switch' : False}, |
| 842 | } |
| 843 | ) |
| 844 | } |
| 845 | # |
| 846 | # ------------------------------------------------------------------------------ |
| 847 | # SWITCH_TUNNEL_TERMINATION_COMMAND_DESCRIPTION |
| 848 | # |
| 849 | |
| 850 | SWITCH_TUNNEL_TERMINATION_COMMAND_DESCRIPTION = { |
| 851 | 'name' : 'tunnel', |
| 852 | 'short-help' : 'Enable/Disable tunnel creation for this switch', |
| 853 | 'mode' : 'config-switch', |
| 854 | 'command-type' : 'update-config', |
| 855 | 'parent-field' : 'dpid', |
| 856 | 'obj-type' : 'switch-config', |
| 857 | 'doc' : 'switch|tunnel', |
| 858 | 'doc-example' : 'switch|tunnel-example', |
| 859 | 'data' : { 'tunnel-termination' : 'default' }, # for no command |
| 860 | 'args' : ( |
| 861 | 'termination', |
| 862 | { |
| 863 | 'field' : 'tunnel-termination', |
| 864 | 'type' : 'enum', |
| 865 | 'values' : ( "enabled", "disabled" ), |
| 866 | 'optional-for-no' : True, |
| 867 | } |
| 868 | ) |
| 869 | } |
| 870 | # |
| 871 | # ------------------------------------------------------------------------------ |
| 872 | # SWITCH_ALIAS_COMMAND_DESCRIPTION |
| 873 | # |
| 874 | |
| 875 | SWITCH_SWITCH_ALIAS_COMMAND_DESCRIPTION = { |
| 876 | 'name' : 'switch-alias', |
| 877 | 'mode' : 'config-switch', |
| 878 | 'short-help' : 'Attach alias to switch', |
| 879 | 'doc' : 'switch|alias', |
| 880 | 'doc-example' : 'switch|alias-example', |
| 881 | 'command-type' : 'manage-alias', |
| 882 | 'obj-type' : 'switch-alias', |
| 883 | 'scoped' : True, |
| 884 | 'args' : ( |
| 885 | { |
| 886 | 'field' : 'id', |
| 887 | 'optional-for-no' : False, |
| 888 | 'completion' : 'complete-object-field', |
| 889 | } |
| 890 | ) |
| 891 | } |
| 892 | |
| 893 | # |
| 894 | # ------------------------------------------------------------------------------ |
| 895 | # SWITCH_INTERFACE_COMMAND_DESCRIPTION |
| 896 | # enter config-switch-if submode |
| 897 | # |
| 898 | |
| 899 | SWITCH_INTERFACE_COMMAND_DESCRIPTION = { |
| 900 | 'name' : 'interface', |
| 901 | 'mode' : 'config-switch*', |
| 902 | 'short-help' : 'Enter switch-if submode, configure switch interface', |
| 903 | 'command-type' : 'config-submode', |
| 904 | 'obj-type' : 'switch-interface-config', |
| 905 | 'parent-field' : 'switch', |
| 906 | 'current-mode-obj-id' : 'switch', |
| 907 | 'submode-name' : 'config-switch-if', |
| 908 | 'syntax-help' : 'Enter an interface name', |
| 909 | 'doc' : 'switch|interface', |
| 910 | 'doc-example' : 'switch|interface-example', |
| 911 | 'args' : ( |
| 912 | { |
| 913 | 'field' : 'name', |
| 914 | 'completion' : [ 'complete-object-field', |
| 915 | 'complete-from-another', |
| 916 | ], |
| 917 | 'other' : 'interfaces|portName', |
| 918 | 'scoped' : 'dpid', |
| 919 | 'data-handler' : 'warn-missing-interface', |
| 920 | } |
| 921 | ) |
| 922 | } |
| 923 | |
| 924 | # |
| 925 | # ------------------------------------------------------------------------------ |
| 926 | # SWITCHPORT_COMMAND_DESCRIPTION |
| 927 | # 'switchport mode external' |
| 928 | # 'no switchport mode external' |
| 929 | # |
| 930 | |
| 931 | SWITCHPORT_COMMAND_DESCRIPTION = { |
| 932 | 'name' : 'switchport', |
| 933 | 'short-help' : 'Configure interface as connected to an external network', |
| 934 | 'mode' : 'config-switch-if', |
| 935 | 'command-type' : 'config', |
| 936 | 'obj-type' : 'switch-interface-config', |
| 937 | 'fields' : ('broadcast', 'mode',), |
| 938 | 'action' : 'write-fields', |
| 939 | 'no-action' : 'reset-fields', |
| 940 | 'doc' : 'switch|switchport', |
| 941 | 'doc-example' : 'switch|switchport-example', |
| 942 | 'args' : ( |
| 943 | 'mode', |
| 944 | { |
| 945 | 'field' : 'mode', |
| 946 | 'type' : 'enum', |
| 947 | 'values' : 'external', |
| 948 | 'help-name' : 'interface connects to external network', |
| 949 | 'short-help' : 'interface connects to external network', |
| 950 | 'syntax-help' : 'external' |
| 951 | }, |
| 952 | ) |
| 953 | } |
| 954 | |
| 955 | # |
| 956 | # ------------------------------------------------------------------------------ |
| 957 | # |
| 958 | |
| 959 | |
| 960 | SWITCH_INTERFACE_INTERFACE_ALIAS_COMMAND_DESCRIPTION = { |
| 961 | 'name' : 'interface-alias', |
| 962 | 'mode' : 'config-switch-if', |
| 963 | 'short-help' : 'Attach alias to switch interface', |
| 964 | 'command-type' : 'manage-alias', |
| 965 | 'obj-type' : 'switch-interface-alias', |
| 966 | 'scoped' : True, |
| 967 | 'doc' : 'switch|interface-alias', |
| 968 | 'doc-example' : 'switch|interface-alias-example', |
| 969 | 'args' : ( |
| 970 | { |
| 971 | 'field' : 'id', |
| 972 | 'optional-for-no' : False, |
| 973 | 'completion' : 'complete-object-field', |
| 974 | 'short-help' : 'Alias string', |
| 975 | } |
| 976 | ) |
| 977 | } |
| 978 | """ |
| 979 | # |
| 980 | # FORMATS |
| 981 | # |
| 982 | |
| 983 | |
| 984 | SWITCH_FORMAT = { |
| 985 | 'switch' : { |
| 986 | 'field-orderings' : { |
| 987 | 'default' : [ 'Idx', '@', 'switch-alias', 'connected-since', |
| 988 | 'ip-address', 'type', 'controller'], |
| 989 | 'details' : [ 'Idx','@', 'switch-alias', 'connected-since', |
| 990 | 'ip-address', 'type', 'controller'], |
| 991 | 'brief' : [ 'Idx', '@', 'switch-alias', 'controller'], |
| 992 | }, |
| 993 | 'fields' : { |
| 994 | '@' : { |
| 995 | 'verbose-name' : 'Switch DPID', |
| 996 | }, |
| 997 | 'active' : { |
| 998 | }, |
| 999 | 'core-switch' : { |
| 1000 | 'verbose-name' : 'Core Switch', |
| 1001 | 'validate' : 'validate_switch_core_switch', |
| 1002 | }, |
| 1003 | 'connected-since' : { |
| 1004 | 'verbose-name' : 'Connected Since', |
| 1005 | #'formatter' : fmtcnv.timestamp_to_local_timestr, |
| 1006 | }, |
| 1007 | 'capabilities' : { |
| 1008 | 'formatter' : fmtcnv.decode_switch_capabilities, |
| 1009 | }, |
| 1010 | 'actions' : { |
| 1011 | 'formatter' : fmtcnv.decode_switch_actions, |
| 1012 | }, |
| 1013 | 'ip-address' : { |
| 1014 | 'verbose-name' : 'Connected At', |
| 1015 | }, |
| 1016 | 'socket-address' : { |
| 1017 | }, |
| 1018 | 'buffers' : { |
| 1019 | }, |
| 1020 | 'controller' : { |
| 1021 | 'verbose-name' : 'Controller', |
| 1022 | }, |
| 1023 | 'tables' : { |
| 1024 | }, |
| 1025 | 'switch-alias' : { |
| 1026 | |
| 1027 | 'verbose-name' : 'Alias' |
| 1028 | }, |
| 1029 | 'tunnelCapable' : { |
| 1030 | 'verbose-name' : 'Tun Capable', |
| 1031 | }, |
| 1032 | 'tunnelEnabled' : { |
| 1033 | 'verbose-name' : '-Enabled', |
| 1034 | }, |
| 1035 | 'tunnelState' : { |
| 1036 | 'verbose-name' : '-State', |
| 1037 | }, |
| 1038 | 'dp-desc' : { |
| 1039 | }, |
| 1040 | 'hw-desc' : { |
| 1041 | }, |
| 1042 | 'sw-desc' : { |
| 1043 | }, |
| 1044 | 'serial-num' : { |
| 1045 | }, |
| 1046 | 'type' : { |
| 1047 | }, |
| 1048 | } |
| 1049 | }, |
| 1050 | } |
| 1051 | """ |
| 1052 | SWITCH_CONFIG_FORMAT = { |
| 1053 | 'switch-config' : { |
| 1054 | 'field-orderings' : { |
| 1055 | 'default' : [ |
| 1056 | 'Idx', |
| 1057 | 'dpid', |
| 1058 | 'tunnel-termination', |
| 1059 | 'core-switch', |
| 1060 | ], |
| 1061 | }, |
| 1062 | }, |
| 1063 | } |
| 1064 | |
| 1065 | |
| 1066 | SWITCH_ALIAS_FORMAT = { |
| 1067 | 'switch-alias' : { |
| 1068 | 'field-orderings' : { |
| 1069 | 'default' : [ 'Idx', 'id', 'switch' ], |
| 1070 | 'brief' : [ 'Idx', 'id', 'switch' ], |
| 1071 | }, |
| 1072 | }, |
| 1073 | } |
| 1074 | |
| 1075 | |
| 1076 | SWITCH_INTERFACE_CONFIG_FORMAT = { |
| 1077 | 'switch-interface-config' : { |
| 1078 | 'field-orderings' : { |
| 1079 | 'default' : [ 'Idx', 'if-name', 'mode' ] |
| 1080 | }, |
| 1081 | 'fields' : { |
| 1082 | 'broadcast' : { |
| 1083 | }, |
| 1084 | 'name' : { |
| 1085 | }, |
| 1086 | 'mode' : { |
| 1087 | 'verbose-name' : 'Switchport Mode', |
| 1088 | }, |
| 1089 | }, |
| 1090 | }, |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | SWITCH_INTERFACE_ALIAS_FORMAT = { |
| 1095 | 'switch-interface-alias' : { |
| 1096 | 'field-orderings' : { |
| 1097 | 'default' : [ 'Idx', 'id', 'switch', 'name' ] |
| 1098 | }, |
| 1099 | 'fields' : { |
| 1100 | 'id' : { 'verbose-name' : 'Alias', |
| 1101 | } |
| 1102 | } |
| 1103 | }, |
| 1104 | } |
| 1105 | |
| 1106 | SWITCH_INTERFACES_FORMAT = { |
| 1107 | 'switch-interfaces' : { |
| 1108 | 'field-orderings' : { |
| 1109 | 'default' : [ 'Idx', 'switch', 'portName', 'state', 'config', |
| 1110 | 'receiveBytes', 'receivePackets', 'receiveErrors', |
| 1111 | 'transmitBytes', 'transmitPackets', 'transmitErrors', |
| 1112 | 'mode', 'broadcast', |
| 1113 | ], |
| 1114 | 'details' : [ 'Idx', 'switch', 'portName', 'hardwareAddress', |
| 1115 | 'config', 'stp-state', 'state', 'currentFeatures', |
| 1116 | 'advertisedFeatures', 'supportedFeatures', |
| 1117 | 'peer-features', 'mode', 'broadcast', |
| 1118 | ], |
| 1119 | 'brief' : [ 'Idx', 'switch', 'portName', 'state', 'config' ], |
| 1120 | }, |
| 1121 | |
| 1122 | 'fields' : { |
| 1123 | 'id' : { |
| 1124 | }, |
| 1125 | 'switch' : { 'formatter' : fmtcnv.replace_switch_with_alias |
| 1126 | }, |
| 1127 | 'portName' : { 'verbose-name' : 'IF', |
| 1128 | }, |
| 1129 | 'hardwareAddress' : { 'verbose-name' : 'MAC Address' |
| 1130 | }, |
| 1131 | 'config' : { |
| 1132 | 'formatter' : fmtcnv.decode_port_config |
| 1133 | }, |
| 1134 | 'state' : { 'verbose-name' : 'Link', |
| 1135 | 'formatter' : fmtcnv.decode_port_up_down, |
| 1136 | }, |
| 1137 | 'stp-state' : { |
| 1138 | 'formatter' : lambda i, data : |
| 1139 | fmtcnv.decode_port_stp_state(data['state'], |
| 1140 | data), |
| 1141 | }, |
| 1142 | 'currentFeatures' : { 'verbose-name' : 'Curr Features', |
| 1143 | 'formatter' : fmtcnv.decode_port_features |
| 1144 | }, |
| 1145 | 'advertisedFeatures' : { 'verbose-name' : 'Adv Features', |
| 1146 | 'formatter' : fmtcnv.decode_port_features |
| 1147 | }, |
| 1148 | 'supportedFeatures' : { 'verbose-name' : 'Supp Features', |
| 1149 | 'formatter' : fmtcnv.decode_port_features |
| 1150 | }, |
| 1151 | 'peer-features' : { 'verbose-name' : 'Peer Features', |
| 1152 | 'formatter' : fmtcnv.decode_port_features |
| 1153 | }, |
| 1154 | 'receiveBytes' : { 'verbose-name' : 'Rcv Bytes', |
| 1155 | 'formatter' : fmtcnv.decode_port_counter}, |
| 1156 | 'receivePackets' : { 'verbose-name' : 'Rcv Pkts', |
| 1157 | 'formatter' : fmtcnv.decode_port_counter}, |
| 1158 | 'receiveErrors' : { 'verbose-name' : 'Rcv Errs', |
| 1159 | 'formatter' : fmtcnv.decode_port_counter}, |
| 1160 | 'transmitBytes' : { 'verbose-name' : 'Xmit Bytes', |
| 1161 | 'formatter' : fmtcnv.decode_port_counter}, |
| 1162 | 'transmitPackets' : { 'verbose-name' : 'Xmit Pkts', |
| 1163 | 'formatter' : fmtcnv.decode_port_counter}, |
| 1164 | 'transmitErrors' : { 'verbose-name' : 'Xmit Errs', |
| 1165 | 'formatter' : fmtcnv.decode_port_counter}, |
| 1166 | }, |
| 1167 | }, |
| 1168 | } |
| 1169 | |
| 1170 | TUNNEL_DETAILS_FORMAT = { |
| 1171 | 'tunnel-details' : { |
| 1172 | 'field-orderings' : { |
| 1173 | 'default' : [ 'Idx', 'dpid', 'localTunnelIPAddr', |
| 1174 | 'tunnelPorts', |
| 1175 | ] |
| 1176 | }, |
| 1177 | |
| 1178 | 'fields' : { |
| 1179 | 'dpid' : { |
| 1180 | 'verbose-name' : 'Switch DPID', |
| 1181 | 'primary_key': True, |
| 1182 | 'formatter' : fmtcnv.replace_switch_with_alias, |
| 1183 | }, |
| 1184 | 'localTunnelIPAddr' : { |
| 1185 | 'verbose-name' : 'Local tunnel IP', |
| 1186 | }, |
| 1187 | 'tunnelPorts' : { |
| 1188 | 'verbose-name' : 'Remote tunnel IP', |
| 1189 | }, |
| 1190 | }, |
| 1191 | }, |
| 1192 | } |
| 1193 | """ |
| 1194 | |
| 1195 | def group_id_completion(prefix, data, completions): |
| 1196 | dpid = data.get('dpid') |
| 1197 | #print dpid |
| 1198 | query_url = "http://127.0.0.1:8000/rest/v1/realtimestats/group/%s/" %(dpid) |
| 1199 | result = command.sdnsh.store.rest_simple_request(query_url) |
| 1200 | entries = json.loads(result) |
| 1201 | entries = entries[dpid] |
| 1202 | #print "result", entries |
| 1203 | for entry in entries: |
| 1204 | #print entry['groupId'] |
| 1205 | if str(entry['groupId']).startswith(prefix): |
| 1206 | completions[str(entry['groupId'])+' '] = entry['groupId'] |
| 1207 | return |
| 1208 | |
| 1209 | command.add_completion('group-id-completion', group_id_completion, |
| 1210 | {'kwargs': { 'prefix' : '$text', |
| 1211 | 'data' : '$data', |
| 1212 | 'completions' : '$completions', |
| 1213 | }}) |