Skip to content

Commit

Permalink
Remove old netmiko usage
Browse files Browse the repository at this point in the history
  • Loading branch information
liorf committed Mar 19, 2017
1 parent 5e1345e commit 6abbb92
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 144 deletions.
44 changes: 0 additions & 44 deletions nsot_sync/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,39 +92,6 @@ def check_icmp(ip, logger):
return False


def get_hostname(device, hostname, logger):
"""
This function remove from the hostname any trailing or leading characters like <, > or #
:param logger: The logger.
:param device: The device details in the Netmiko format.
:param hostname: The hostname returned from the Netmiko.find_prompt()
:return: The actual hostname, if unknown return None.
"""
logger.debug('Getting the hostname of device: %s', device)
logger.debug('Full prompt is: %s', hostname)
if 'hp' in device['device_type']:
hostname = hostname.split('<')[1]
hostname = hostname.split('>')[0]
return hostname
elif 'cisco' in device['device_type']:
if '>' in hostname:
return hostname.split('>')[0]
else:
return hostname.split('#')[0]
elif 'eos' in device['device_type']:
if '>' in hostname:
return hostname.split('>')[0]
else:
return hostname.split('#')[0]
elif 'f5_ltm' in device['device_type']:
hostname = hostname.split('@')[1].split('(')[1].split(')')[0]
logger.debug('The final hostname is: %s', hostname)
return hostname
else:
logger.warning('device_type unknown - %s', device['device_type'])
return None


def find_device_in_ipam(ip, devices, logger):
"""
Find a device by IP address attribute in the list of devices.
Expand All @@ -139,14 +106,3 @@ def find_device_in_ipam(ip, devices, logger):
if 'address' in device['attributes']:
if device['attributes']['address'] == ip:
return device


def convert_netmiko_os_to_napalm_os(netmiko_os):
if netmiko_os == 'arista_eos':
return 'eos'
elif netmiko_os == 'cisco_ios':
return 'ios'
elif netmiko_os == 'cisco_nxos':
return 'nxos'
else:
return 'unknown'
69 changes: 0 additions & 69 deletions nsot_sync/creds_manager.py

This file was deleted.

32 changes: 1 addition & 31 deletions nsot_sync/drivers/device_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

import concurrent.futures
import ipaddress
# from netmiko import ConnectHandler
from netmiko.snmp_autodetect import SNMPDetect
# from netmiko.ssh_exception import NetMikoTimeoutException, NetMikoAuthenticationException
from pynsot.client import get_api_client
from pynsot.vendor.slumber.exceptions import HttpClientError
from requests.exceptions import ConnectionError

from base_driver import BaseDriver
from nsot_sync.common import check_icmp, find_device_in_ipam, convert_netmiko_os_to_napalm_os
# from nsot_sync.creds_manager import CredsManager
from nsot_sync.common import check_icmp, find_device_in_ipam
from nsot_sync.snmp_get_hostname import SNMPHostnameDetect


Expand All @@ -22,12 +19,6 @@
__email__ = '[email protected]'


# TODO Add creds manager as common module.
# TODO Move common function of the two scanners to common module.
# TODO Support SNMP v3.
# TODO remove SNMP and Vlan from cli options to dotfile.


class DeviceScannerDriver(BaseDriver):
REQUIRED_ATTRS = [
{
Expand Down Expand Up @@ -91,10 +82,7 @@ def __init__(self, max_threads, scan_vlan, snmp_community, snmp_version, *args,
self.scan_vlan = scan_vlan
self.snmp_community = snmp_community
self.snmp_version = snmp_version
# self.update_creds = update_creds
self.max_threads = max_threads
# creds_mng = CredsManager(update_creds=self.update_creds, name=__name__)
# self.user, self.password = creds_mng.load_creds
try:
self.logger.info('Getting networks for site: %s', self.site_id)
self.networks = self.c.sites(self.site_id).networks.get()
Expand Down Expand Up @@ -189,7 +177,6 @@ def scan(self, ip):
self.logger.info('%s - Could not get the os using SNMP', ip)
return
self.logger.debug('%s - Success getting the os, %s', ip, os)
# self.logger.debug('%s - device_details is: %s', ip, device_details)
try:
my_snmp = SNMPHostnameDetect(hostname=str(ip), community=self.snmp_community,
snmp_version=self.snmp_version)
Expand All @@ -213,7 +200,6 @@ def scan(self, ip):

device = find_device_in_ipam(ip, self.devices, self.logger)
# TODO - Add more attributes here
# napalm_os = convert_netmiko_os_to_napalm_os(netmiko_os)
if not device:
self.logger.info('%s - Not exist in IPAM', ip)
attributes = {'address': ip, 'last_reachable': str(st), 'os': os,
Expand All @@ -225,22 +211,6 @@ def scan(self, ip):
device['attributes']['os'] = os
device['attributes']['last_reachable'] = str(st)
device['attributes']['hostname'] = str(hostname)
# device['attributes']['napalm_os'] = str(napalm_os)
device['hostname'] = hostname
self.devices_to_update.append(device)
return
# try:
# # net_connect = ConnectHandler(**device_details)
# # hostname = get_hostname(device_details, net_connect.find_prompt() + "\n", self.logger)
#
# except NetMikoAuthenticationException as e:
# self.logger.info('%s - Login failed, wrong username or password\n%s', ip, e)
# except NetMikoTimeoutException as e:
# self.logger.info('%s - Login failed, TimeoutException\n%s', ip, e)
# except ValueError as e:
# self.logger.info('%s - Login failed, ValueError\n%s', ip, e)
# except KeyboardInterrupt:
# self.exit_app = True
# raise
# finally:
# return

0 comments on commit 6abbb92

Please sign in to comment.