def configure_snmp_v3(self, snmp_access, user, auth_type, auth_protocol, auth_password, priv_protocol,
                          priv_password):
        """ Configure SNMP v3 """

        CommandTemplateExecutor(self._cli_service,
                                enable_disable_snmp.CONFIGURE_V3_VIEW).execute_command(view_name=self.VIEW)
        CommandTemplateExecutor(self._cli_service,
                                enable_disable_snmp.CONFIGURE_V3_GROUP).execute_command(group_name=self.GROUP,
                                                                                        auth_type=auth_type,
                                                                                        snmp_access=snmp_access,
                                                                                        view_name=self.VIEW)

        CommandTemplateExecutor(self._cli_service,
                                enable_disable_snmp.CONFIGURE_V3_USER).execute_command(user_name=user)

        command = CommandTemplateExecutor(self._cli_service, enable_disable_snmp.CONFIGURE_V3_AUTH)
        command.update_action_map({r"Password:"******"Password:": lambda session, logger: session.send_line(priv_password, logger)})
        command.execute_command(user_name=user, priv_protocol=priv_protocol)
 def _get_l2_protocol_tunnel_cmd(self, action_map=None, error_map=None):
     return CommandTemplateExecutor(self._cli_service,
                                    vlan_command_template.L2_TUNNEL,
                                    action_map=action_map,
                                    error_map=error_map)
Esempio n. 3
0
 def _remove_association(self, association_name):
     if association_name:
         command_executor = CommandTemplateExecutor(
             self._cli_service, command_template.MAP_CLEAR)
         command_executor.execute_command(name=association_name)
         del self._associations_table[association_name]
 def save_server_port(self, port, action_map=None, error_map=None):
     return CommandTemplateExecutor(self._cli_service,
                                    aireos_save_templates.SAVE_CONFIGURATION_PORT,
                                    action_map=action_map,
                                    error_map=error_map,
                                    check_action_loop_detector=False).execute_command(port=port)
 def save_password(self, password, action_map=None, error_map=None):
     return CommandTemplateExecutor(self._cli_service,
                                    aireos_save_templates.SAVE_CONFIGURATION_PASSWORD,
                                    action_map=action_map,
                                    error_map=error_map,
                                    check_action_loop_detector=False).execute_command(password=password)
Esempio n. 6
0
    def set_vlan_to_interface(
        self,
        vlan_range,
        port_mode,
        port_name,
        qnq,
        c_tag,
        action_map=None,
        error_map=None,
    ):
        """Assign vlan to a certain interface.

        :param vlan_range: range of vlans to be assigned
        :param port_mode: switchport mode
        :param port_name: interface name
        :param qnq: qinq settings (dot1q tunnel)
        :param c_tag: selective qnq
        :param action_map: actions will be taken during executing commands,
            i.e. handles yes/no prompts
        :param error_map: errors will be raised during executing commands,
            i.e. handles Invalid Commands errors
        """
        CommandTemplateExecutor(
            self._cli_service,
            iface.CONFIGURE_INTERFACE).execute_command(port_name=port_name)

        CommandTemplateExecutor(
            self._cli_service,
            iface.NO_SHUTDOWN,
            action_map=action_map,
            error_map=error_map,
        ).execute_command()

        if qnq:
            port_mode = "dot1q-tunnel"

        CommandTemplateExecutor(
            self._cli_service,
            add_remove_vlan.SWITCHPORT_MODE,
            action_map=action_map,
            error_map=error_map,
        ).execute_command()
        response = CommandTemplateExecutor(
            self._cli_service,
            add_remove_vlan.SWITCHPORT_MODE,
            action_map=action_map,
            error_map=error_map,
        ).execute_command(port_mode=port_mode)
        if self.CHECK_VLAN_MODE_NOT_REJECTED.search(response):
            CommandTemplateExecutor(
                self._cli_service,
                add_remove_vlan.SWITCHPORT_REMOVE_TRUNK_AUTO,
                action_map=action_map,
                error_map=error_map,
            ).execute_command(port_mode_trunk="", vlan_range=vlan_range)
            CommandTemplateExecutor(
                self._cli_service,
                add_remove_vlan.SWITCHPORT_MODE,
                action_map=action_map,
                error_map=error_map,
            ).execute_command(port_mode=port_mode)
        if qnq:
            self._get_l2_protocol_tunnel_cmd(action_map,
                                             error_map).execute_command()

        if "trunk" not in port_mode:
            CommandTemplateExecutor(
                self._cli_service,
                add_remove_vlan.SWITCHPORT_ALLOW_VLAN,
                action_map=action_map,
                error_map=error_map,
            ).execute_command(port_mode_access="", vlan_range=vlan_range)

        else:
            CommandTemplateExecutor(
                self._cli_service,
                add_remove_vlan.SWITCHPORT_ALLOW_VLAN,
                action_map=action_map,
                error_map=error_map,
            ).execute_command(port_mode_trunk="", vlan_range=vlan_range)
Esempio n. 7
0
 def enable_snmp(self, snmp_community):
     """Enable snmp on the device."""
     return CommandTemplateExecutor(
         self._cli_service,
         ENABLE_SNMP).execute_command(snmp_community=snmp_community)
    def copy(self,
             source,
             destination,
             action_map=None,
             error_map=None,
             timeout=None,
             noconfirm=True):
        """ Copy file from device to tftp or vice versa, as well as copying inside devices filesystem.

        :param source: source file
        :param destination: destination file
        :param action_map: actions will be taken during executing commands, i.e. handles yes/no prompts
        :param error_map: errors will be raised during executing commands, i.e. handles Invalid Commands errors
        :param timeout: session timeout
        :raise Exception:
        """

        if noconfirm:
            output = CommandTemplateExecutor(self._cli_service,
                                             configuration.COPY,
                                             action_map=action_map,
                                             error_map=error_map,
                                             timeout=timeout).execute_command(
                                                 src=source,
                                                 dst=destination,
                                                 noconfirm="")

            if "Invalid input detected" in output:
                output = CommandTemplateExecutor(
                    self._cli_service,
                    configuration.COPY,
                    action_map=action_map,
                    error_map=error_map).execute_command(src=source,
                                                         dst=destination)

        else:
            output = CommandTemplateExecutor(
                self._cli_service,
                configuration.COPY,
                action_map=action_map,
                error_map=error_map).execute_command(src=source,
                                                     dst=destination)

        copy_ok_pattern = r"\d+ bytes copied|copied.*[\[\(].*[1-9][0-9]* bytes.*[\)\]]|[Cc]opy complete|[\(\[]OK[\]\)]"
        status_match = re.search(copy_ok_pattern, output, re.IGNORECASE)

        if not status_match:
            match_error = re.search(
                r"%.*|TFTP put operation failed.*|sysmgr.*not supported.*\n",
                output, re.IGNORECASE)
            message = "Copy Command failed. "
            if match_error:
                self._logger.error(message)
                message += re.sub(r"^%|\\n", "", match_error.group())
            else:
                error_match = re.search(r"error.*\n|fail.*\n", output,
                                        re.IGNORECASE)
                if error_match:
                    self._logger.error(message)
                    message += error_match.group()
            raise Exception("Copy", message)
 def save_data_type(self, data_type, action_map=None, error_map=None):
     return CommandTemplateExecutor(self._cli_service,
                                    aireos_save_templates.SAVE_CONFIGURATION_DATA_TYPE,
                                    action_map=action_map,
                                    error_map=error_map,
                                    check_action_loop_detector=False).execute_command(data_type=data_type)
 def save_config_name(self, filename, action_map=None, error_map=None):
     return CommandTemplateExecutor(self._cli_service,
                                    aireos_save_templates.SAVE_CONFIGURATION_FILENAME,
                                    action_map=action_map,
                                    error_map=error_map,
                                    check_action_loop_detector=False).execute_command(filename=filename)
 def set_state_id(self, state_id):
     out = CommandTemplateExecutor(
         self._cli_service,
         command_template.SET_STATE_ID).execute_command(state_id=state_id)
     return out
 def get_state_id(self):
     state_id = CommandTemplateExecutor(
         self._cli_service,
         command_template.GET_STATE_ID).execute_command()
     return re.split(r'\s', state_id.strip())[1]
    def show_version(self):
        """Show system version"""

        return CommandTemplateExecutor(
            self._cli_service, configuration.SHOW_VERSION).execute_command()
Esempio n. 14
0
 def remove_local_file(self, filepath):
     return CommandTemplateExecutor(
         cli_service=self._cli_service,
         command_template=command_templates.REMOVE).execute_command(
             filename=filepath)
Esempio n. 15
0
    def set_vlan_to_sub_interface(
        self,
        vlan_range,
        port_mode,
        port_name,
        qnq,
        c_tag,
        l2_transport=None,
        is_untagged=None,
        action_map=None,
        error_map=None,
    ):
        """Assign vlan to a certain interface.

        :param vlan_range: range of vlans to be assigned
        :param port_mode: switchport mode
        :param port_name: interface name
        :param qnq: qinq settings (dot1q tunnel)
        :param c_tag: selective qnq
        :param action_map: actions will be taken during executing commands,
            i.e. handles yes/no prompts
        :param error_map: errors will be raised during executing commands,
            i.e. handles Invalid Commands errors
        """
        untagged = None

        if is_untagged:
            untagged = ""

        CommandTemplateExecutor(
            self._cli_service,
            iface.NO_SHUTDOWN,
            action_map=action_map,
            error_map=error_map,
        ).execute_command()

        if qnq:
            CommandTemplateExecutor(
                self._cli_service,
                add_remove_vlan.VLAN_SUB_IFACE,
                action_map=action_map,
                error_map=error_map,
            ).execute_command(vlan_id=vlan_range, qnq="")
        else:
            try:
                CommandTemplateExecutor(
                    self._cli_service,
                    add_remove_vlan.VLAN_SUB_IFACE,
                    action_map=action_map,
                    error_map=error_map,
                ).execute_command(vlan_id=vlan_range, untagged=untagged)
            except SessionException:
                self._logger.warning(
                    "Unable to configure sub interface with untagged encapsulation."
                )
                CommandTemplateExecutor(
                    self._cli_service,
                    add_remove_vlan.VLAN_SUB_IFACE,
                    action_map=action_map,
                    error_map=error_map,
                ).execute_command(vlan_id=vlan_range)
    def enable_snmp_v3(
        self,
        snmp_user,
        snmp_password,
        auth_protocol,
        snmp_priv_key,
        priv_protocol,
        snmp_group,
        action_map=None,
        error_map=None,
    ):
        """Enable SNMP user on the device.

        :param snmp_user: snmp user
        :param snmp_password: snmp password
        :param snmp_priv_key: snmp priv key
        :param snmp_group: snmp group name
        :param action_map: actions will be taken during executing commands,
            i.e. handles yes/no prompts
        :param error_map: errors will be raised during executing commands,
            i.e. handles Invalid Commands errors
        """
        if snmp_group:
            try:
                result = CommandTemplateExecutor(
                    cli_service=self._cli_service,
                    command_template=enable_disable_snmp.
                    ENABLE_SNMP_V3_WITH_GROUP,
                    action_map=action_map,
                    error_map=error_map,
                ).execute_command(
                    snmp_user=snmp_user,
                    snmp_password=snmp_password,
                    auth_protocol=auth_protocol,
                    snmp_priv_key=snmp_priv_key,
                    priv_protocol=priv_protocol,
                    snmp_group=snmp_group,
                )
            except CommandExecutionException:
                result = CommandTemplateExecutor(
                    cli_service=self._cli_service,
                    command_template=enable_disable_snmp.
                    ENABLE_SNMP_V3_WITH_GROUP,
                    action_map=action_map,
                    error_map=error_map,
                ).execute_command(
                    snmp_user=snmp_user,
                    snmp_password=snmp_password,
                    auth_protocol=auth_protocol,
                    snmp_priv_key=snmp_priv_key,
                    priv_protocol=priv_protocol.replace("-", " "),
                    snmp_group=snmp_group,
                )
        else:
            result = CommandTemplateExecutor(
                cli_service=self._cli_service,
                command_template=enable_disable_snmp.ENABLE_SNMP_USER,
                action_map=action_map,
                error_map=error_map,
            ).execute_command(
                snmp_user=snmp_user,
                snmp_password=snmp_password,
                auth_protocol=auth_protocol,
                snmp_priv_key=snmp_priv_key,
                priv_protocol=priv_protocol,
            )
        return result
 def clean_vlan_sub_interface(self, port_name):
     CommandTemplateExecutor(
         self._cli_service,
         iface_command_template.REMOVE_INTERFACE).execute_command(
             port_name=port_name)
 def save_mode(self, mode, action_map=None, error_map=None):
     return CommandTemplateExecutor(self._cli_service,
                                    aireos_save_templates.SAVE_CONFIGURATION_MODE,
                                    action_map=action_map,
                                    error_map=error_map,
                                    check_action_loop_detector=False).execute_command(mode=mode)
Esempio n. 19
0
 def is_configured(self, snmp_community):
     """Check snmp community configured."""
     output = CommandTemplateExecutor(
         self._cli_service, SHOW_SNMP_COMMUNITY).execute_command()
     return snmp_community in output
 def save_server_ip(self, server_ip, action_map=None, error_map=None):
     return CommandTemplateExecutor(self._cli_service,
                                    aireos_save_templates.SAVE_CONFIGURATION_SERVER_IP,
                                    action_map=action_map,
                                    error_map=error_map,
                                    check_action_loop_detector=False).execute_command(server_ip=server_ip)
 def save_user(self, user, action_map=None, error_map=None):
     return CommandTemplateExecutor(self._cli_service,
                                    aireos_save_templates.SAVE_CONFIGURATION_USER,
                                    action_map=action_map,
                                    error_map=error_map,
                                    check_action_loop_detector=False).execute_command(user=user)
 def run_command(self, command, action_map=None, error_map=None):
     return CommandTemplateExecutor(
         self._cli_service,
         aireos_general_templates.RUN_COMMAND,
         action_map=action_map,
         error_map=error_map).execute_command(command=command)