Looks for a MAC address under a heading in a command's output. The first line of words in the output is searched for the given heading. Words at the same word index as the heading in subsequent lines are then examined to see if they look like MAC addresses.
(command, args, heading)
| 535 | |
| 536 | |
| 537 | def _find_mac_under_heading(command, args, heading): |
| 538 | """Looks for a MAC address under a heading in a command's output. |
| 539 | |
| 540 | The first line of words in the output is searched for the given |
| 541 | heading. Words at the same word index as the heading in subsequent |
| 542 | lines are then examined to see if they look like MAC addresses. |
| 543 | """ |
| 544 | stdout = _get_command_stdout(command, args) |
| 545 | if stdout is None: |
| 546 | return None |
| 547 | |
| 548 | keywords = stdout.readline().rstrip().split() |
| 549 | try: |
| 550 | column_index = keywords.index(heading) |
| 551 | except ValueError: |
| 552 | return None |
| 553 | |
| 554 | first_local_mac = None |
| 555 | for line in stdout: |
| 556 | words = line.rstrip().split() |
| 557 | try: |
| 558 | word = words[column_index] |
| 559 | except IndexError: |
| 560 | continue |
| 561 | |
| 562 | mac = _parse_mac(word) |
| 563 | if mac is None: |
| 564 | continue |
| 565 | if _is_universal(mac): |
| 566 | return mac |
| 567 | if first_local_mac is None: |
| 568 | first_local_mac = mac |
| 569 | |
| 570 | return first_local_mac |
| 571 | |
| 572 | |
| 573 | # The following functions call external programs to 'get' a macaddr value to |
no test coverage detected
searching dependent graphs…