How to use the netmiko.cisco_base_connection.CiscoBaseConnection function in netmiko

To help you get started, we’ve selected a few netmiko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ktbyers / netmiko / netmiko / cisco_base_connection.py View on Github external
def config_mode(self, config_command="config term", pattern=""):
        """
        Enter into configuration mode on remote device.

        Cisco IOS devices abbreviate the prompt at 20 chars in config mode
        """
        if not pattern:
            pattern = re.escape(self.base_prompt[:16])
        return super(CiscoBaseConnection, self).config_mode(
            config_command=config_command, pattern=pattern
        )
github ktbyers / netmiko / netmiko / cisco / cisco_ios.py View on Github external
from __future__ import unicode_literals

import time
import re
import os
import hashlib
import io

from netmiko.cisco_base_connection import CiscoBaseConnection, CiscoFileTransfer


class CiscoIosBase(CiscoBaseConnection):
    """Common Methods for IOS (both SSH and telnet)."""
    def session_preparation(self):
        """Prepare the session after the connection has been established."""
        self._test_channel_read(pattern=r'[>#]')
        self.set_base_prompt()
        self.disable_paging()
        self.set_terminal_width(command='terminal width 511')
        # Clear the read buffer
        time.sleep(.3 * self.global_delay_factor)
        self.clear_buffer()

    def save_config(self, cmd='write mem', confirm=False):
        """Saves Config Using Copy Run Start"""
        return super(CiscoIosBase, self).save_config(cmd=cmd, confirm=confirm)
github ktbyers / netmiko / netmiko / cisco_base_connection.py View on Github external
"""Saves Config."""
        self.enable()
        if confirm:
            output = self.send_command_timing(command_string=cmd)
            if confirm_response:
                output += self.send_command_timing(confirm_response)
            else:
                # Send enter by default
                output += self.send_command_timing(self.RETURN)
        else:
            # Some devices are slow so match on trailing-prompt if you can
            output = self.send_command(command_string=cmd)
        return output


class CiscoSSHConnection(CiscoBaseConnection):
    pass


class CiscoFileTransfer(BaseFileTransfer):
    pass
github ktbyers / netmiko / netmiko / ipinfusion / ipinfusion_ocnos.py View on Github external
import time
from telnetlib import IAC, DO, DONT, WILL, WONT, SB, SE, TTYPE
from netmiko.cisco_base_connection import CiscoBaseConnection


class IpInfusionOcNOSBase(CiscoBaseConnection):
    """Common Methods for IP Infusion OcNOS support."""

    def __init__(self, *args, **kwargs):
        if kwargs.get("default_enter") is None:
            kwargs["default_enter"] = "\r"
        return super(IpInfusionOcNOSBase, self).__init__(**kwargs)

    def session_preparation(self):
        self._test_channel_read()
        self.set_base_prompt()
        self.disable_paging(command="terminal length 0")

        # Clear the read buffer
        time.sleep(0.3 * self.global_delay_factor)
        self.clear_buffer()
github ktbyers / netmiko / netmiko / brocade / brocade_netiron_telnet.py View on Github external
from __future__ import unicode_literals
from netmiko.cisco_base_connection import CiscoBaseConnection


class BrocadeNetironTelnet(CiscoBaseConnection):
    """Brocade NetIron aka CER support."""
    def telnet_login(self, pri_prompt_terminator='#', alt_prompt_terminator='>',
                     username_pattern=r"Username:", pwd_pattern=r"assword:",
                     delay_factor=1, max_loops=60):
        """Telnet login. Can be username/password or just password."""
        super(BrocadeNetironTelnet, self).telnet_login(
              pri_prompt_terminator=pri_prompt_terminator,
              alt_prompt_terminator=alt_prompt_terminator,
              username_pattern=username_pattern,
              pwd_pattern=pwd_pattern,
              delay_factor=delay_factor,
              max_loops=max_loops)

    def _test_channel_read(self, count=40, pattern="", newline_format="\r"):
        super(BrocadeNetironTelnet, self)._test_channel_read(count=count,
                                                             pattern=pattern,
github ktbyers / netmiko / netmiko / huawei / huawei.py View on Github external
from __future__ import print_function
from __future__ import unicode_literals
import time
import re
from netmiko.cisco_base_connection import CiscoBaseConnection
from netmiko.ssh_exception import NetMikoAuthenticationException
from netmiko import log


class HuaweiBase(CiscoBaseConnection):
    def session_preparation(self):
        """Prepare the session after the connection has been established."""
        self._test_channel_read()
        self.set_base_prompt()
        self.disable_paging(command="screen-length 0 temporary")
        # Clear the read buffer
        time.sleep(0.3 * self.global_delay_factor)
        self.clear_buffer()

    def config_mode(self, config_command="system-view"):
        """Enter configuration mode."""
        return super(HuaweiBase, self).config_mode(config_command=config_command)

    def exit_config_mode(self, exit_config="return", pattern=r">"):
        """Exit configuration mode."""
        return super(HuaweiBase, self).exit_config_mode(
github ktbyers / netmiko / netmiko / brocade / brocade_fastiron_telnet.py View on Github external
from __future__ import unicode_literals
import re
from netmiko.cisco_base_connection import CiscoBaseConnection


class BrocadeFastironTelnet(CiscoBaseConnection):
    """Brocade FastIron aka ICX support."""
    def session_preparation(self):
        """FastIron requires to be enable mode to disable paging."""
        self._test_channel_read()
        self.set_base_prompt()
        self.enable()
        self.disable_paging(command="skip-page-display")

    @staticmethod
    def normalize_linefeeds(a_string):
        """Convert '\r\n\r\n', '\r\r\n','\r\n', '\n\r' to '\n."""
        newline = re.compile(r'(\r\n\r\n|\r\r\n|\r\n|\n\r|\r)')
        return newline.sub('\n', a_string)

    def telnet_login(self, pri_prompt_terminator='#', alt_prompt_terminator='>',
                     username_pattern=r"Username:", pwd_pattern=r"assword:",
github ktbyers / netmiko / netmiko / oneaccess / oneaccess_oneos.py View on Github external
"""Netmiko driver for OneAccess ONEOS"""

from __future__ import print_function
from __future__ import unicode_literals

from netmiko.cisco_base_connection import CiscoBaseConnection
import time


class OneaccessOneOSBase(CiscoBaseConnection):
    def __init__(self, *args, **kwargs):
        """Init connection - similar as Cisco"""
        default_enter = kwargs.get("default_enter")
        kwargs["default_enter"] = "\r\n" if default_enter is None else default_enter
        super(OneaccessOneOSBase, self).__init__(*args, **kwargs)

    def session_preparation(self):
        """Prepare connection - disable paging"""
        self._test_channel_read()
        self.set_base_prompt()
        self.disable_paging(command="term len 0")
        self.set_terminal_width(command="stty columns 255")
        # Clear the read buffer
        time.sleep(0.3 * self.global_delay_factor)
        self.clear_buffer()
github ktbyers / netmiko / netmiko / dell / dell_powerconnect_telnet.py View on Github external
"""Dell Telnet Driver."""
from __future__ import unicode_literals

import time
from netmiko.cisco_base_connection import CiscoBaseConnection
from netmiko import log


class DellPowerConnectTelnet(CiscoBaseConnection):
    def disable_paging(self, command="terminal length 0", delay_factor=1):
        """Must be in enable mode to disable paging."""

        self.enable()
        delay_factor = self.select_delay_factor(delay_factor)
        time.sleep(delay_factor * .1)
        self.clear_buffer()
        command = self.normalize_cmd(command)
        log.debug("In disable_paging")
        log.debug("Command: {0}".format(command))
        self.write_channel(command)
        output = self.read_until_prompt()
        if self.ansi_escape_codes:
            output = self.strip_ansi_escape_codes(output)
        log.debug("{0}".format(output))
        log.debug("Exiting disable_paging")
github ktbyers / netmiko / netmiko / dell / dell_powerconnect.py View on Github external
"""Dell PowerConnect Driver."""
from __future__ import unicode_literals
from paramiko import SSHClient
import time
from os import path
from netmiko.cisco_base_connection import CiscoBaseConnection


class SSHClient_noauth(SSHClient):
    def _auth(self, username, *args):
        self._transport.auth_none(username)
        return


class DellPowerConnectBase(CiscoBaseConnection):
    """Dell PowerConnect Driver."""

    def session_preparation(self):
        """Prepare the session after the connection has been established."""
        self.ansi_escape_codes = True
        self._test_channel_read()
        self.set_base_prompt()
        self.enable()
        self.disable_paging(command="terminal datadump")
        # Clear the read buffer
        time.sleep(0.3 * self.global_delay_factor)
        self.clear_buffer()

    def set_base_prompt(
        self, pri_prompt_terminator=">", alt_prompt_terminator="#", delay_factor=1
    ):