def unarchive_trex(self): """ """ CommandTemplateExecutor( self._cli_service, trex_common.CHANGE_PATH).execute_command(path=TREX_ROOT_PATH) output = CommandTemplateExecutor( self._cli_service, trex_common.FILE_INFO).execute_command(file_path=TREX_PACK_NAME) if "gzip" in output.lower(): command = trex_common.UNTAR_GZ_PACKAGE._command.format( trex_package=TREX_PACK_NAME) elif "tar" in output.lower(): command = trex_common.UNTAR_PACKAGE._command.format( trex_package=TREX_PACK_NAME) # elif "Zip" in output: # pass else: raise Exception(self.__class__.__name__, "Can't determine TRex Package format") output = self._cli_service.send_command( command=command, action_map=trex_common.UNTAR_PACKAGE._action_map, error_map=trex_common.UNTAR_PACKAGE._error_map, remove_command_from_output=False) if re.search(r"error|fail", output, re.IGNORECASE | re.DOTALL): raise Exception(self.__class__.__name__, "Un-tar TRex package failed : {}".format(output)) trex_folder = "" for line in output.split("\n"): line = line.strip() if line and line != command: trex_folder = line break if not trex_folder: raise Exception(self.__class__.__name__, "Can't determine root TRex package folder") CommandTemplateExecutor(self._cli_service, trex_common.CREATE_SIM_LINK).execute_command( source_path=trex_folder, link_name=TREX_FOLDER)
def slot_table(self): """ Slot table :return: """ output = CommandTemplateExecutor( self._cli_service, command_template.BLADE_INFO).execute_command() blade_table = defaultdict(dict) for line in output.split('\n'): if line.strip() and ("model" in line.lower() or "serial" in line.lower()): if "model" in line.lower(): key, value = re.split(":\s+", line) match = re.search( r'Blade\s(?P<letter>[A-Z])\s(?P<name>\S+)', key) if match: blade_table[match.group('letter').strip()][match.group( 'name').strip()] = value.strip() return blade_table