def _gather_mac_addr(self): from lib.container import Container from lib.inventory import Inventory yellow = '\033[93m' endc = '\033[0m' log = logger.getlogger() cont = Container(self.config_file_path) found_all = False while found_all is not True: cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append( os.path.join(gen.get_container_python_path(), 'clear_port_macs.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd, interactive=True) except UserException as exc: print('Fail:', str(exc), file=sys.stderr) sys.exit(1) _run_playbook("activate_client_interfaces.yml", self.config_file_path) cmd[-2] = os.path.join(gen.get_container_python_path(), 'set_port_macs.py') try: cont.run_command(cmd, interactive=True) except UserException as exc: print('Fail:', str(exc), file=sys.stderr) sys.exit(1) inv = Inventory(cfg_file=self.config_file_path) if inv.check_data_interfaces_macs(): found_all = True else: print() msg = 'Some data interface MAC addresses were not found!' log.warning(msg) print(f'{yellow}' + ('-' * (len(msg) + 10)) + f'{endc}') print("\nPress enter to retry") resp = input( "Enter C to continue POWER-Up or 'T' to terminate ") if resp == 'T': log.info( "'{}' entered. Terminating POWER-Up at user request". format(resp)) sys.exit(1) elif resp == 'C': log.info("'{}' entered. Continuing POWER-Up".format(resp)) found_all = True print('Success: Gathered Client MAC addresses')
def main(config_path=None): log = logger.getlogger() cfg = Config(config_path) inv = Inventory(config_path) macs = {} for sw_info in cfg.yield_sw_data_access_info(): switch = SwitchFactory.factory(sw_info[1], sw_info[2], sw_info[3], sw_info[4], mode='active') port_to_macs = switch.show_mac_address_table(format='std') log.debug(("Data switch port to MAC mapping - " "Switch: '{}', Class: '{}' - IP: '{}' - {}").format( sw_info[0], sw_info[1], sw_info[2], port_to_macs)) macs.update({sw_info[0]: port_to_macs}) inv.add_macs_data(macs) if not inv.check_data_interfaces_macs(): _print_data_macs(inv)