forked from mirrors/thatmattlove-hyperglass
fix device_type selection for linux platforms
This commit is contained in:
parent
e3f40b4f7b
commit
7fd35f5d6f
3 changed files with 25 additions and 2 deletions
|
|
@ -80,3 +80,8 @@ DRIVER_MAP = {
|
|||
"frr": "netmiko",
|
||||
"http": "hyperglass_http_client",
|
||||
}
|
||||
|
||||
LINUX_PLATFORMS = (
|
||||
"frr",
|
||||
"bird",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class NetmikoConnection(SSHConnection):
|
|||
driver_kwargs = {
|
||||
"host": host or self.device._target,
|
||||
"port": port or self.device.port,
|
||||
"device_type": self.device.platform,
|
||||
"device_type": self.device.get_device_type(),
|
||||
"username": self.device.credential.username,
|
||||
"global_delay_factor": 0.1,
|
||||
"timeout": math.floor(params.request_timeout * 1.25),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,12 @@ from hyperglass.log import log
|
|||
from hyperglass.util import get_driver, get_fmt_keys, resolve_hostname
|
||||
from hyperglass.state import use_state
|
||||
from hyperglass.settings import Settings
|
||||
from hyperglass.constants import DRIVER_MAP, SCRAPE_HELPERS, SUPPORTED_STRUCTURED_OUTPUT
|
||||
from hyperglass.constants import (
|
||||
DRIVER_MAP,
|
||||
SCRAPE_HELPERS,
|
||||
LINUX_PLATFORMS,
|
||||
SUPPORTED_STRUCTURED_OUTPUT,
|
||||
)
|
||||
from hyperglass.exceptions.private import ConfigError, UnsupportedDevice
|
||||
|
||||
# Local
|
||||
|
|
@ -124,6 +129,19 @@ class Device(HyperglassModelWithId, extra="allow"):
|
|||
return True
|
||||
return False
|
||||
|
||||
def get_device_type(self) -> str:
|
||||
"""Get the `device_type` field for use by Netmiko.
|
||||
|
||||
In some cases, the platform might be different than the
|
||||
device_type. For example, any linux-based platform like FRR,
|
||||
BIRD, or OpenBGPD will have directives associated with those
|
||||
platforms, but the `device_type` sent to Netmiko needs to be
|
||||
`linux_ssh`.
|
||||
"""
|
||||
if self.platform in LINUX_PLATFORMS:
|
||||
return "linux_ssh"
|
||||
return self.platform
|
||||
|
||||
def _validate_directive_attrs(self) -> None:
|
||||
|
||||
# Set of all keys except for built-in key `target`.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue