mirror of
https://github.com/napalm-automation-community/napalm-vyos.git
synced 2026-09-22 04:11:14 +00:00
add def is_alive
This commit is contained in:
@@ -47,10 +47,10 @@ class VyOSDriver(NetworkDriver):
|
|||||||
_BOOT_FILENAME = "/config/config.boot"
|
_BOOT_FILENAME = "/config/config.boot"
|
||||||
|
|
||||||
def __init__(self, hostname, username, password, timeout=60, optional_args=None):
|
def __init__(self, hostname, username, password, timeout=60, optional_args=None):
|
||||||
self._hostname = hostname
|
self.hostname = hostname
|
||||||
self._username = username
|
self.username = username
|
||||||
self._password = password
|
self.password = password
|
||||||
self._timeout = timeout
|
self.timeout = timeout
|
||||||
self.device = None
|
self.device = None
|
||||||
self._scp_client = None
|
self._scp_client = None
|
||||||
self._new_config = None
|
self._new_config = None
|
||||||
@@ -82,19 +82,20 @@ class VyOSDriver(NetworkDriver):
|
|||||||
|
|
||||||
# Build dict of any optional Netmiko args
|
# Build dict of any optional Netmiko args
|
||||||
self.netmiko_optional_args = {}
|
self.netmiko_optional_args = {}
|
||||||
for k, v in netmiko_argument_map.items():
|
if optional_args is not None:
|
||||||
try:
|
for k, v in netmiko_argument_map.items():
|
||||||
self.netmiko_optional_args[k] = optional_args[k]
|
try:
|
||||||
except KeyError:
|
self.netmiko_optional_args[k] = optional_args[k]
|
||||||
pass
|
except KeyError:
|
||||||
self.global_delay_factor = optional_args.get('global_delay_factor', 1)
|
pass
|
||||||
self.port = optional_args.get('port', 22)
|
self.global_delay_factor = optional_args.get('global_delay_factor', 1)
|
||||||
|
self.port = optional_args.get('port', 22)
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
self.device = ConnectHandler(device_type='vyos',
|
self.device = ConnectHandler(device_type='vyos',
|
||||||
host=self._hostname,
|
host=self.hostname,
|
||||||
username=self._username,
|
username=self.username,
|
||||||
password=self._password,
|
password=self.password,
|
||||||
**self.netmiko_optional_args)
|
**self.netmiko_optional_args)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -105,6 +106,12 @@ class VyOSDriver(NetworkDriver):
|
|||||||
def close(self):
|
def close(self):
|
||||||
self.device.disconnect()
|
self.device.disconnect()
|
||||||
|
|
||||||
|
def is_alive(self):
|
||||||
|
"""Returns a flag with the state of the SSH connection."""
|
||||||
|
return {
|
||||||
|
'is_alive': self.device.remote_conn.transport.is_active()
|
||||||
|
}
|
||||||
|
|
||||||
def load_replace_candidate(self, filename=None, config=None):
|
def load_replace_candidate(self, filename=None, config=None):
|
||||||
"""
|
"""
|
||||||
Only configuration files are supported with load_replace_candidate.
|
Only configuration files are supported with load_replace_candidate.
|
||||||
@@ -178,8 +185,9 @@ class VyOSDriver(NetworkDriver):
|
|||||||
self.device.send_config_set(['save'])
|
self.device.send_config_set(['save'])
|
||||||
self.device.exit_config_mode()
|
self.device.exit_config_mode()
|
||||||
|
|
||||||
def rollback(self, filename=None):
|
def rollback(self):
|
||||||
"""Rollback configuration to filename or to self.rollback_cfg file."""
|
"""Rollback configuration to filename or to self.rollback_cfg file."""
|
||||||
|
filename = None
|
||||||
if filename is None:
|
if filename is None:
|
||||||
filename = self._BACKUP_FILENAME
|
filename = self._BACKUP_FILENAME
|
||||||
|
|
||||||
@@ -773,12 +781,14 @@ class VyOSDriver(NetworkDriver):
|
|||||||
|
|
||||||
return user_auth
|
return user_auth
|
||||||
|
|
||||||
def ping(self, destination, source="", ttl=255, timeout=5, size=100, count=5):
|
def ping(self, destination, source='', ttl=255, timeout=2, size=100, count=5):
|
||||||
# does not support multiple destination yet
|
# does not support multiple destination yet
|
||||||
|
|
||||||
|
deadline = timeout * count
|
||||||
|
|
||||||
command = "ping %s " % destination
|
command = "ping %s " % destination
|
||||||
command += "ttl %d " % ttl
|
command += "ttl %d " % ttl
|
||||||
command += "deadline %d " % timeout
|
command += "deadline %d " % deadline
|
||||||
command += "size %d " % size
|
command += "size %d " % size
|
||||||
command += "count %d " % count
|
command += "count %d " % count
|
||||||
if source != "":
|
if source != "":
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ class PatchedVyOSDriver(vyos.VyOSDriver):
|
|||||||
"""Patched VyOS Driver."""
|
"""Patched VyOS Driver."""
|
||||||
|
|
||||||
def __init__(self, hostname, username, password, timeout=60, optional_args=None):
|
def __init__(self, hostname, username, password, timeout=60, optional_args=None):
|
||||||
optional_args = {'port': '12206'}
|
|
||||||
super().__init__(hostname, username, password, timeout, optional_args)
|
super().__init__(hostname, username, password, timeout, optional_args)
|
||||||
|
|
||||||
self.patched_attrs = ['device']
|
self.patched_attrs = ['device']
|
||||||
|
|||||||
Reference in New Issue
Block a user