diff --git a/cloudshell/networking/huawei/autoload/snmp_entity_table.py b/cloudshell/networking/huawei/autoload/snmp_entity_table.py index 924b955..41c7821 100644 --- a/cloudshell/networking/huawei/autoload/snmp_entity_table.py +++ b/cloudshell/networking/huawei/autoload/snmp_entity_table.py @@ -120,6 +120,11 @@ def _get_entity_table(self): # 'entPhysicalVendorType': 'str'} entity_table_optional_port_attr = {'entPhysicalDescr': 'str', 'entPhysicalName': 'str'} + physical_desc = self._snmp.get_table('ENTITY-MIB', 'entPhysicalDescr') + physical_name = self._snmp.get_table('ENTITY-MIB', 'entPhysicalName') + physical_vendor = self._snmp.get_table('ENTITY-MIB', 'entPhysicalVendorType') + physical_class = self._snmp.get_table('ENTITY-MIB', 'entPhysicalClass') + contained_in = self._snmp.get_table('ENTITY-MIB', 'entPhysicalContainedIn') physical_indexes = self._snmp.get_table('ENTITY-MIB', 'entPhysicalParentRelPos') vendor_type_match_pattern = r"|".join(self.ENTITY_VENDOR_TYPE_TO_CLASS_MAP.keys()) for index in physical_indexes.keys(): @@ -129,20 +134,26 @@ def _get_entity_table(self): continue temp_entity_table = physical_indexes[index].copy() - temp_entity_table.update(self._snmp.get_properties('ENTITY-MIB', index, {"entPhysicalClass": "str"}) - [index]) + temp_entity_table.update(physical_class[index]) + # temp_entity_table.update(self._snmp.get_properties('ENTITY-MIB', index, {"entPhysicalClass": "str"}) + # [index]) + if re.search(r"cpu|fan|sensor", temp_entity_table['entPhysicalClass'].lower()): self._logger.debug("Loaded {}, skipping.".format(temp_entity_table['entPhysicalClass'])) continue - temp_entity_table.update(self._snmp.get_properties('ENTITY-MIB', index, {"entPhysicalContainedIn": "str"}) - [index]) + temp_entity_table.update(contained_in[index]) + # temp_entity_table.update(self._snmp.get_properties('ENTITY-MIB', index, {"entPhysicalContainedIn": "str"}) + # [index]) + if temp_entity_table['entPhysicalContainedIn'] == '': self.exclusion_list.append(index) continue - temp_entity_table.update(self._snmp.get_properties('ENTITY-MIB', index, {"entPhysicalVendorType": "str"}) - [index]) + temp_entity_table.update(physical_vendor[index]) + # temp_entity_table.update(self._snmp.get_properties('ENTITY-MIB', index, {"entPhysicalVendorType": "str"}) + # [index]) + ent_physical_class = temp_entity_table.get("entPhysicalClass") if not ent_physical_class or ent_physical_class == "''" or "other" in ent_physical_class: vendor_type = temp_entity_table['entPhysicalVendorType'] @@ -164,8 +175,10 @@ def _get_entity_table(self): else: temp_entity_table['entPhysicalClass'] = temp_entity_table['entPhysicalClass'].replace("'", "") - temp_entity_table.update(self._snmp.get_properties('ENTITY-MIB', index, entity_table_optional_port_attr) - [index]) + temp_entity_table.update(physical_desc[index]) + temp_entity_table.update(physical_name[index]) + # temp_entity_table.update(self._snmp.get_properties('ENTITY-MIB', index, entity_table_optional_port_attr) + # [index]) if re.search(r'stack|chassis|module|port|powerSupply|container|backplane', temp_entity_table['entPhysicalClass']): diff --git a/cloudshell/networking/huawei/command_actions/save_restore_actions.py b/cloudshell/networking/huawei/command_actions/save_restore_actions.py index b999d68..767a6fe 100644 --- a/cloudshell/networking/huawei/command_actions/save_restore_actions.py +++ b/cloudshell/networking/huawei/command_actions/save_restore_actions.py @@ -44,7 +44,7 @@ def copy_file(self, src_file, dst_file): def _device_response_verification(self, output): """ """ - match = re.search(r"\d+ bytes copied|copied.*[\[\(].*[0-9]* bytes.*[\)\]]|[Cc]opy complete", + match = re.search(r"\d+ bytes copied|copied.*[\[\(].*[0-9]* bytes.*[\)\]]|[Cc]opy complete|[Cc]omplete.", output, re.IGNORECASE) @@ -79,7 +79,7 @@ def setup_startup_config(self, dst_file): """ Specifies the system configuration file for next startup """ output = CommandTemplateExecutor(self._cli_service, - configuration.SAVE_RUNNING).execute_command(dst_file=dst_file) + configuration.SAVE_STARTUP).execute_command(dst_file=dst_file) match = re.search(r"Succeeded in setting the configuration for booting system", output, diff --git a/cloudshell/networking/huawei/command_actions/system_actions.py b/cloudshell/networking/huawei/command_actions/system_actions.py index 0b344ba..e5817fd 100644 --- a/cloudshell/networking/huawei/command_actions/system_actions.py +++ b/cloudshell/networking/huawei/command_actions/system_actions.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- import re - +from collections import OrderedDict from cloudshell.cli.command_template.command_template_executor import CommandTemplateExecutor from cloudshell.networking.huawei.command_templates import system @@ -71,7 +71,9 @@ def reboot(self, action_map=None, error_map=None): try: CommandTemplateExecutor(cli_service=self._cli_service, command_template=system.REBOOT, - action_map=action_map, + action_map=OrderedDict({ + r"\[Y/N\]": lambda session, logger: session.send_line("Y", logger), + "\(Y/N\)": lambda session, logger: session.send_line("Y", logger)}), error_map=error_map, expected_string="System is rebooting, please wait").execute_command() except Exception as e: diff --git a/cloudshell/networking/huawei/command_templates/configuration.py b/cloudshell/networking/huawei/command_templates/configuration.py index 86f7b76..964f012 100644 --- a/cloudshell/networking/huawei/command_templates/configuration.py +++ b/cloudshell/networking/huawei/command_templates/configuration.py @@ -29,7 +29,7 @@ r"[Oo]verwrit+e": lambda session, logger: session.send_line("y", logger), "\(Y/N\)": lambda session, logger: session.send_line("Y", logger)})) -SAVE_STARTUP = CommandTemplate("startup saved-configuration {dst}", +SAVE_STARTUP = CommandTemplate("startup saved-configuration {dst_file}", action_map=OrderedDict({ r"\[confirm\]": lambda session, logger: session.send_line("", logger), r"\[Y/N\]": lambda session, logger: session.send_line("y", logger), diff --git a/cloudshell/networking/huawei/flows/huawei_file_system_flow.py b/cloudshell/networking/huawei/flows/huawei_file_system_flow.py index 348b46b..833480f 100644 --- a/cloudshell/networking/huawei/flows/huawei_file_system_flow.py +++ b/cloudshell/networking/huawei/flows/huawei_file_system_flow.py @@ -20,4 +20,4 @@ def execute_flow(self): src_file = save_action.get_startup_config_filename(startup_config=startup_config) - return src_file.split(":")[0] + return src_file.split(":")[0].lstrip(' ') diff --git a/cloudshell/networking/huawei/flows/huawei_restore_flow.py b/cloudshell/networking/huawei/flows/huawei_restore_flow.py index 837a65f..ad7bd4b 100644 --- a/cloudshell/networking/huawei/flows/huawei_restore_flow.py +++ b/cloudshell/networking/huawei/flows/huawei_restore_flow.py @@ -5,6 +5,7 @@ from cloudshell.devices.networking_utils import UrlParser from cloudshell.networking.huawei.command_actions.system_actions import SystemActions from cloudshell.networking.huawei.command_actions.save_restore_actions import SaveRestoreActions +import re class HuaweiRestoreFlow(RestoreConfigurationFlow): @@ -23,6 +24,10 @@ def execute_flow(self, path, configuration_type, restore_method, vrf_management_ :param vrf_management_name: Virtual Routing and Forwarding Name """ + path = re.sub('{}:'.format(self.file_system), '', path) + if 'cfg' not in path: + path = path + '.cfg' + if not configuration_type: configuration_type = "running-config" elif "-config" not in configuration_type: diff --git a/cloudshell/networking/huawei/flows/huawei_save_flow.py b/cloudshell/networking/huawei/flows/huawei_save_flow.py index e8f996f..61f8361 100644 --- a/cloudshell/networking/huawei/flows/huawei_save_flow.py +++ b/cloudshell/networking/huawei/flows/huawei_save_flow.py @@ -6,6 +6,7 @@ from cloudshell.devices.flows.action_flows import SaveConfigurationFlow from cloudshell.networking.huawei.command_actions.system_actions import SystemActions from cloudshell.networking.huawei.command_actions.save_restore_actions import SaveRestoreActions +import re class HuaweiSaveFlow(SaveConfigurationFlow): @@ -22,6 +23,10 @@ def execute_flow(self, folder_path, configuration_type, vrf_management_name=None :return: saved configuration file name """ + folder_path = re.sub('{}:'.format(self.file_system), '', folder_path) + if 'cfg' not in folder_path: + folder_path = folder_path + '.cfg' + if not configuration_type: configuration_type = "running-config" elif "-config" not in configuration_type: @@ -39,7 +44,7 @@ def execute_flow(self, folder_path, configuration_type, vrf_management_name=None if configuration_type == "running-config": # src_file = "{file_system}:/qualirunconfig.cfg".format(file_system=self.file_system) - src_file = "quali_run_config.cfg" + src_file = folder_path save_action.save_runninig_config(dst_file=src_file) else: startup_config = system_action.display_startup_config() @@ -53,6 +58,8 @@ def execute_flow(self, folder_path, configuration_type, vrf_management_name=None save_action.put_file(server_address=url.get(UrlParser.HOSTNAME), src_file=src_file, dst_file=url.get(UrlParser.FILENAME)) + elif src_file == folder_path: + pass else: raise Exception("Unsupported backup protocol {scheme}. " "Supported types are ftp, tftp of local({file_system})".format(scheme=scheme,