1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
"""Dell PowerConnect Driver."""
from __future__ import unicode_literals
from netmiko.cisco_base_connection import CiscoSSHConnection
from paramiko import SSHClient
import time
from os import path
class SSHClient_noauth(SSHClient):
def _auth(self, username, *args):
self._transport.auth_none(username)
return
class DellPowerConnectSSH(CiscoSSHConnection):
"""Dell PowerConnect Driver.
To make it work, we have to override the SSHClient _auth method.
If we use login/password, the ssh server use the (none) auth mechanism.
"""
def _build_ssh_client(self):
"""Prepare for Paramiko SSH connection.
See base_connection.py file for any updates.
"""
# Create instance of SSHClient object
# If user does not provide SSH key, we use noauth
if not self.use_keys:
remote_conn_pre = SSHClient_noauth()
else:
remote_conn_pre = SSHClient()
# Load host_keys for better SSH security
if self.system_host_keys:
remote_conn_pre.load_system_host_keys()
if self.alt_host_keys and path.isfile(self.alt_key_file):
remote_conn_pre.load_host_keys(self.alt_key_file)
# Default is to automatically add untrusted hosts (make sure appropriate for your env)
remote_conn_pre.set_missing_host_key_policy(self.key_policy)
return remote_conn_pre
def special_login_handler(self, delay_factor=1):
"""
Powerconnect presents with the following on login
User Name:
Password: ****
"""
delay_factor = self.select_delay_factor(delay_factor)
i = 0
time.sleep(delay_factor * .5)
output = ""
while i <= 12:
output = self.read_channel()
if output:
if 'User Name:' in output:
self.write_channel(self.username + '\n')
elif 'Password:' in output:
self.write_channel(self.password + '\n')
break
time.sleep(delay_factor * 1)
else:
self.write_channel('\n')
time.sleep(delay_factor * 1.5)
i += 1
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.disable_paging(command="terminal datadump")
def set_base_prompt(self, pri_prompt_terminator='>', alt_prompt_terminator='#',
delay_factor=1):
"""Sets self.base_prompt: used as delimiter for stripping of trailing prompt in output."""
prompt = super(DellPowerConnectSSH, self).set_base_prompt(
pri_prompt_terminator=pri_prompt_terminator,
alt_prompt_terminator=alt_prompt_terminator,
delay_factor=delay_factor)
prompt = prompt.strip()
self.base_prompt = prompt
return self.base_prompt
def check_config_mode(self, check_string='(config)#'):
"""Checks if the device is in configuration mode"""
return super(DellPowerConnectSSH, self).check_config_mode(check_string=check_string)
def config_mode(self, config_command='config'):
"""Enter configuration mode."""
return super(DellPowerConnectSSH, self).config_mode(config_command=config_command)
|