Skip to content

Commit

Permalink
Merge pull request #301 from ktbyers/dev_1_1
Browse files Browse the repository at this point in the history
Merge dev_1_1 into master
  • Loading branch information
ktbyers authored Oct 25, 2016
2 parents 96a6fce + bd24410 commit 47c597a
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ dist
netmiko.egg-info
.cache
bin/.netmiko.cfg
.vscode/*
3 changes: 2 additions & 1 deletion netmiko/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
NetmikoTimeoutError = NetMikoTimeoutException
NetmikoAuthError = NetMikoAuthenticationException

__version__ = '1.0.2'
__version__ = '1.1.0'

__all__ = ('ConnectHandler', 'ssh_dispatcher', 'platforms', 'SCPConn', 'FileTransfer',
'NetMikoTimeoutException', 'NetMikoAuthenticationException',
'NetmikoTimeoutError', 'NetmikoAuthError')
3 changes: 3 additions & 0 deletions netmiko/a10/a10_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ def session_preparation(self):
self.set_base_prompt()
self.enable()
self.disable_paging(command="terminal length 0\n")

# Will not do anything without A10 specific command
self.set_terminal_width()
2 changes: 1 addition & 1 deletion netmiko/arista/arista_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def check_config_mode(self, check_string=')#', pattern=''):
Can also be (s2)
"""
debug = True
debug = False
if debug:
print("pattern: {}".format(pattern))
self.write_channel('\n')
Expand Down
3 changes: 3 additions & 0 deletions netmiko/aruba/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from netmiko.aruba.aruba_ssh import ArubaSSH

__all__ = ['ArubaSSH']
22 changes: 22 additions & 0 deletions netmiko/aruba/aruba_ssh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Aruba OS support"""
from netmiko.cisco_base_connection import CiscoSSHConnection


class ArubaSSH(CiscoSSHConnection):
"""Aruba OS support"""
def session_preparation(self):
"""Aruba OS requires enable mode to disable paging."""
self.set_base_prompt()
self.enable()
self.disable_paging(command="no paging")

def check_config_mode(self, check_string='(config) #', pattern=''):
"""
Checks if the device is in configuration mode or not.
Aruba uses "(<controller name>) (config) #" as config prompt
"""
if not pattern:
pattern = self.base_prompt[:16]
return super(ArubaSSH, self).check_config_mode(check_string=check_string,
pattern=pattern)
25 changes: 20 additions & 5 deletions netmiko/base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class BaseConnection(object):
"""
def __init__(self, ip='', host='', username='', password='', secret='', port=None,
device_type='', verbose=False, global_delay_factor=1, use_keys=False,
key_file=None, ssh_strict=False, system_host_keys=False, alt_host_keys=False,
alt_key_file='', ssh_config_file=None, timeout=8):
key_file=None, allow_agent=False, ssh_strict=False, system_host_keys=False,
alt_host_keys=False, alt_key_file='', ssh_config_file=None, timeout=8):

if ip:
self.host = ip
Expand Down Expand Up @@ -78,6 +78,7 @@ def __init__(self, ip='', host='', username='', password='', secret='', port=Non
# Options for SSH host_keys
self.use_keys = use_keys
self.key_file = key_file
self.allow_agent = allow_agent
self.system_host_keys = system_host_keys
self.alt_host_keys = alt_host_keys
self.alt_key_file = alt_key_file
Expand All @@ -88,6 +89,10 @@ def __init__(self, ip='', host='', username='', password='', secret='', port=Non
self.establish_connection()
self.session_preparation()

# Clear the read buffer
time.sleep(.3 * self.global_delay_factor)
self.clear_buffer()

def write_channel(self, out_data):
"""Generic handler that will write to both SSH and telnet channel."""
if self.protocol == 'ssh':
Expand Down Expand Up @@ -244,6 +249,16 @@ def telnet_login(self, pri_prompt_terminator='#', alt_prompt_terminator='>',
if debug:
print("checkpoint3")
return return_msg
if re.search(r"assword required, but none set", output):
if debug:
print("checkpoint4")
msg = "Telnet login failed - Password required, but none set: {0}".format(
self.host)
raise NetMikoAuthenticationException(msg)
if pri_prompt_terminator in output or alt_prompt_terminator in output:
if debug:
print("checkpoint5")
return return_msg
self.write_channel("\n")
time.sleep(.5 * delay_factor)
i += 1
Expand All @@ -258,7 +273,7 @@ def telnet_login(self, pri_prompt_terminator='#', alt_prompt_terminator='>',
return_msg += output
if pri_prompt_terminator in output or alt_prompt_terminator in output:
if debug:
print("checkpoint4")
print("checkpoint6")
return return_msg

msg = "Telnet login failed: {0}".format(self.host)
Expand Down Expand Up @@ -322,7 +337,7 @@ def _connect_params_dict(self):
'username': self.username,
'password': self.password,
'look_for_keys': self.use_keys,
'allow_agent': False,
'allow_agent': self.allow_agent,
'key_filename': self.key_file,
'timeout': self.timeout,
}
Expand Down Expand Up @@ -804,7 +819,7 @@ def send_config_set(self, config_commands=None, exit_config_mode=True, delay_fac
time.sleep(delay_factor * .5)

# Gather output
output = self._read_channel_timing(delay_factor=delay_factor, max_loops=max_loops)
output += self._read_channel_timing(delay_factor=delay_factor, max_loops=max_loops)
if exit_config_mode:
output += self.exit_config_mode()
output = self._sanitize_output(output)
Expand Down
10 changes: 9 additions & 1 deletion netmiko/cisco/cisco_asa_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ def send_command(self, *args, **kwargs):
If the ASA is in multi-context mode, then the base_prompt needs to be
updated after each context change.
"""
output = super(CiscoAsaSSH, self).send_command(*args, **kwargs)
if len(args) >= 1:
command_string = args[0]
else:
command_string = kwargs['command_string']

# If changeto in command, look for '#' to determine command is done
if "changeto" in command_string:
if len(args) <= 1:
expect_string = kwargs.get('expect_string', '#')
kwargs['expect_string'] = expect_string
output = super(CiscoAsaSSH, self).send_command(*args, **kwargs)

if "changeto" in command_string:
self.set_base_prompt()

return output

def send_command_expect(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion netmiko/paloalto/paloalto_panos_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def session_preparation(self):
Disable paging (the '--more--' prompts).
Set the base prompt for interaction ('>').
"""
self.set_base_prompt(delay_factor=3)
self.set_base_prompt(delay_factor=20)
self.disable_paging(command="set cli pager off\n")

def check_enable_mode(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion netmiko/scp_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def establish_scp_conn(self):
password=self.ssh_ctl_chan.password,
key_filename=self.ssh_ctl_chan.key_file,
look_for_keys=self.ssh_ctl_chan.use_keys,
allow_agent=False,
allow_agent=self.ssh_ctl_chan.allow_agent,
timeout=self.ssh_ctl_chan.timeout)
self.scp_client = scp.SCPClient(self.scp_conn.get_transport())

Expand Down
2 changes: 2 additions & 0 deletions netmiko/ssh_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from netmiko.dell import DellForce10SSH
from netmiko.paloalto import PaloAltoPanosSSH
from netmiko.quanta import QuantaMeshSSH
from netmiko.aruba import ArubaSSH
from netmiko.vyos import VyOSSSH

# The keys of this dictionary are the supported device_types
Expand Down Expand Up @@ -64,6 +65,7 @@
'dell_force10': DellForce10SSH,
'paloalto_panos': PaloAltoPanosSSH,
'quanta_mesh': QuantaMeshSSH,
'aruba_os': ArubaSSH,
}

# Also support keys that end in _ssh
Expand Down
2 changes: 1 addition & 1 deletion netmiko/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def find_cfg_file(file_name=None):
for test_file in check_files:
if os.path.isfile(test_file):
return test_file
raise IOError("{File not found in current dir or home dir.".format(base_file))
raise IOError("{}: file not found in current dir or home dir.".format(base_file))


def display_inventory(my_devices):
Expand Down
15 changes: 12 additions & 3 deletions netmiko/vyos/vyos_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def exit_config_mode(self, exit_config='exit', pattern='exit'):
"""Exit configuration mode"""
output = ""
if self.check_config_mode():
output = self.send_command(exit_config, strip_prompt=False, strip_command=False)
output = self.send_command_timing(exit_config, strip_prompt=False, strip_command=False)
if 'Cannot exit: configuration modified' in output:
# insert delay?
output += self.send_command('exit discard', strip_prompt=False, strip_command=False)
output += self.send_command_timing('exit discard', strip_prompt=False,
strip_command=False)
if self.check_config_mode():
raise ValueError("Failed to exit configuration mode")
return output
Expand Down Expand Up @@ -80,3 +80,12 @@ def set_base_prompt(self, pri_prompt_terminator='$', alt_prompt_terminator='#',
# Set prompt to user@hostname (remove two additional characters)
self.base_prompt = prompt[:-2].strip()
return self.base_prompt

def send_config_set(self, config_commands=None, exit_config_mode=False, delay_factor=1,
max_loops=150, strip_prompt=False, strip_command=False):
"""Remain in configuration mode."""
return super(VyOSSSH, self).send_config_set(config_commands=config_commands,
exit_config_mode=exit_config_mode,
delay_factor=delay_factor, max_loops=max_loops,
strip_prompt=strip_prompt,
strip_command=strip_command)
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def find_version(*file_paths):
'netmiko/dell',
'netmiko/avaya',
'netmiko/paloalto',
'netmiko/quanta',
'netmiko/vyos',
'netmiko/quanta'],
'netmiko/aruba'],
install_requires=['paramiko>=1.13.0', 'scp>=0.10.0', 'pyyaml'],
extras_require={
'test': ['pytest>=2.6.0', ]
Expand Down
10 changes: 10 additions & 0 deletions tests/etc/commands.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ brocade_nos:
- "logging raslog console WARNING" # base command
- "logging raslog console INFO"
config_verification: "show run | inc raslog"

aruba_os:
version: "show version"
basic: "show ip interface brief"
extended_output: "show version"
config:
- "location location1"
- "location location2"
config_verification: "show location"
...
13 changes: 12 additions & 1 deletion tests/etc/responses.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ paloalto_panos:
multiple_line_output: 'logdb-version: 7.0.9'
version_banner: 'sw-version: 7.0.1'
cmd_response_init: 'new_test'
cmd_response_final: 'another_test'---
cmd_response_final: 'another_test'

brocade_fastiron:
base_prompt: SSH@ICX7250-24P Router
Expand Down Expand Up @@ -57,3 +57,14 @@ brocade_nos:
multiple_line_output: "TenGigabitEthernet 34/0/48"
cmd_response_init: 'logging raslog console WARNING'
cmd_response_final: 'logging raslog console INFO'

aruba_os:
base_prompt: "(ARUBA-MASTER) "
router_prompt: "(ARUBA-MASTER) >"
enable_prompt: "(ARUBA-MASTER) #"
interface_ip: 10.1.200.242
version_banner: "Aruba Operating System Software."
multiple_line_output: "Supervisor Card"
cmd_response_init: "location1"
cmd_response_final: "location2"
...
8 changes: 8 additions & 0 deletions tests/etc/test_devices.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ brocade_nos:
ip: 10.254.4.117
username: admin
password: password

aruba_os:
device_type: aruba_os
ip: 10.1.200.242
username: admin
password: password
secret: secret
...
11 changes: 11 additions & 0 deletions tests/test_nxos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

RETURN_CODE=0

echo "Starting tests...good luck:" \
&& echo "Cisco NXOS" \
&& py.test -v test_netmiko_show.py --test_device nxos1 \
&& py.test -v test_netmiko_config.py --test_device nxos1 \
|| RETURN_CODE=1

exit $RETURN_CODE

0 comments on commit 47c597a

Please sign in to comment.