mirror of
https://github.com/napalm-automation-community/napalm-vyos.git
synced 2026-03-24 12:35:37 +00:00
netmiko and config files
This commit is contained in:
@@ -14,3 +14,11 @@
|
|||||||
|
|
||||||
"""napalm_vyos package."""
|
"""napalm_vyos package."""
|
||||||
from vyos import VyOSDriver
|
from vyos import VyOSDriver
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
|
try:
|
||||||
|
__version__ = pkg_resources.get_distribution('napalm-vyos').version
|
||||||
|
except pkg_resources.DistributionNotFound:
|
||||||
|
__version__ = "Not installed"
|
||||||
|
|
||||||
|
__all__ = ('VyOSDriver',)
|
||||||
|
|||||||
@@ -25,11 +25,10 @@ import os
|
|||||||
|
|
||||||
import vyattaconfparser
|
import vyattaconfparser
|
||||||
|
|
||||||
|
from netmiko import __version__ as netmiko_version
|
||||||
from netmiko import ConnectHandler
|
from netmiko import ConnectHandler
|
||||||
from netmiko import SCPConn
|
from netmiko import SCPConn
|
||||||
|
|
||||||
|
|
||||||
# NAPALM base
|
# NAPALM base
|
||||||
from napalm_base.base import NetworkDriver
|
from napalm_base.base import NetworkDriver
|
||||||
from napalm_base.exceptions import ConnectionException, SessionLockedException, \
|
from napalm_base.exceptions import ConnectionException, SessionLockedException, \
|
||||||
@@ -59,31 +58,48 @@ class VyOSDriver(NetworkDriver):
|
|||||||
self._old_config = None
|
self._old_config = None
|
||||||
self._ssh_usekeys = False
|
self._ssh_usekeys = False
|
||||||
|
|
||||||
if optional_args is None:
|
|
||||||
optional_args = {}
|
|
||||||
self._port = optional_args.get('port', 22)
|
|
||||||
self._ssh_keyfile = optional_args.get('ssh_keyfile', None)
|
|
||||||
if self._ssh_keyfile != None:
|
|
||||||
self._ssh_usekeys = True
|
|
||||||
|
|
||||||
|
# Netmiko possible arguments
|
||||||
|
netmiko_argument_map = {
|
||||||
|
'port': None,
|
||||||
|
'secret': '',
|
||||||
|
'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,
|
||||||
|
}
|
||||||
|
|
||||||
|
fields = netmiko_version.split('.')
|
||||||
|
fields = [int(x) for x in fields]
|
||||||
|
maj_ver, min_ver, bug_fix = fields
|
||||||
|
if maj_ver >= 2:
|
||||||
|
netmiko_argument_map['allow_agent'] = False
|
||||||
|
elif maj_ver == 1 and min_ver >= 1:
|
||||||
|
netmiko_argument_map['allow_agent'] = False
|
||||||
|
|
||||||
|
# Build dict of any optional Netmiko args
|
||||||
|
self.netmiko_optional_args = {}
|
||||||
|
for k, v in netmiko_argument_map.items():
|
||||||
|
try:
|
||||||
|
self.netmiko_optional_args[k] = optional_args[k]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
self.global_delay_factor = optional_args.get('global_delay_factor', 1)
|
||||||
|
self.port = optional_args.get('port', 22)
|
||||||
|
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
|
|
||||||
device = {
|
self._device = ConnectHandler(device_type='vyos',
|
||||||
'device_type': 'vyos',
|
host=self._hostname,
|
||||||
'ip': self._hostname,
|
username=self._username,
|
||||||
'username': self._username,
|
password=self._password,
|
||||||
'password': self._password,
|
**self.netmiko_optional_args)
|
||||||
'use_keys': self._ssh_usekeys,
|
|
||||||
'key_file': self._ssh_keyfile,
|
|
||||||
'port' : self._port, # optional, defaults to 22
|
|
||||||
'secret': 'secret', # optional, defaults to ''
|
|
||||||
'verbose': False, # optional, defaults to False
|
|
||||||
}
|
|
||||||
|
|
||||||
self._device = ConnectHandler(**device)
|
|
||||||
self._scp_client = SCPConn(self._device)
|
self._scp_client = SCPConn(self._device)
|
||||||
|
|
||||||
|
|
||||||
@@ -140,7 +156,7 @@ class VyOSDriver(NetworkDriver):
|
|||||||
|
|
||||||
|
|
||||||
def discard_config(self):
|
def discard_config(self):
|
||||||
self._device.send_config_set(['discard'])
|
self._device.exit_config_mode()
|
||||||
|
|
||||||
def compare_config(self):
|
def compare_config(self):
|
||||||
output_compare = self._device.send_config_set(['compare'])
|
output_compare = self._device.send_config_set(['compare'])
|
||||||
@@ -149,10 +165,13 @@ class VyOSDriver(NetworkDriver):
|
|||||||
if match:
|
if match:
|
||||||
return ""
|
return ""
|
||||||
else:
|
else:
|
||||||
return output_compare
|
diff = ''.join(output_compare.splitlines(True)[1:-1])
|
||||||
|
return diff
|
||||||
|
|
||||||
def commit_config(self):
|
def commit_config(self):
|
||||||
self._device.send_config_set(['commit', 'save'])
|
if self._device.commit():
|
||||||
|
self._device.send_config_set(['save'])
|
||||||
|
self._device.exit_config_mode()
|
||||||
|
|
||||||
def rollback(self, filename=None):
|
def rollback(self, filename=None):
|
||||||
"""Rollback configuration to filename or to self.rollback_cfg file."""
|
"""Rollback configuration to filename or to self.rollback_cfg file."""
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
[pylama]
|
|
||||||
linters = mccabe,pep257,pep8,pyflakes
|
|
||||||
ignore = D203,
|
|
||||||
|
|
||||||
[pylama:pep8]
|
|
||||||
max_line_length = 120
|
|
||||||
8
requirements-dev.txt
Normal file
8
requirements-dev.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
future
|
||||||
|
coveralls
|
||||||
|
pytest
|
||||||
|
pytest-cov
|
||||||
|
pytest-json
|
||||||
|
pytest-pythonpath
|
||||||
|
pylama
|
||||||
|
-r requirements.txt
|
||||||
Reference in New Issue
Block a user