add device field for commands. closes #13

This commit is contained in:
checktheroads 2019-09-03 00:40:04 -07:00
parent ca829f287c
commit 7326c23d48
2 changed files with 18 additions and 7 deletions

View file

@ -69,7 +69,7 @@ class Construct:
}
)
elif self.transport == "scrape":
conf_command = self.device_commands(self.device.nos, afi, query_type)
conf_command = self.device_commands(self.device.commands, afi, query_type)
query = conf_command.format(target=target, source=source)
logger.debug(f"Constructed query: {query}")
return query
@ -97,7 +97,7 @@ class Construct:
)
elif self.transport == "scrape":
conf_command = self.device_commands(self.device.nos, afi, query_type)
conf_command = self.device_commands(self.device.commands, afi, query_type)
query = conf_command.format(target=target, source=source)
logger.debug(f"Constructed query: {query}")
return query
@ -116,7 +116,7 @@ class Construct:
if self.transport == "rest":
query = json.dumps({"query_type": query_type, "afi": afi, "target": target})
elif self.transport == "scrape":
conf_command = self.device_commands(self.device.nos, afi, query_type)
conf_command = self.device_commands(self.device.commands, afi, query_type)
query = conf_command.format(target=target)
logger.debug(f"Constructed query: {query}")
return query
@ -135,7 +135,7 @@ class Construct:
if self.transport == "rest":
query = json.dumps({"query_type": query_type, "afi": afi, "target": target})
elif self.transport == "scrape":
conf_command = self.device_commands(self.device.nos, afi, query_type)
conf_command = self.device_commands(self.device.commands, afi, query_type)
afis = []
for afi in self.device.afis:
split_afi = afi.split("v")
@ -159,7 +159,7 @@ class Construct:
if self.transport == "rest":
query = json.dumps({"query_type": query_type, "afi": afi, "target": target})
elif self.transport == "scrape":
conf_command = self.device_commands(self.device.nos, afi, query_type)
conf_command = self.device_commands(self.device.commands, afi, query_type)
afis = []
for afi in self.device.afis:
split_afi = afi.split("v")

View file

@ -51,6 +51,7 @@ class Router(BaseSettings):
display_name: str
port: int
nos: str
commands: Union[str, None] = None
afis: List[str] = ["ipv4", "ipv6"]
proxy: Union[str, None] = None
@ -76,6 +77,12 @@ class Router(BaseSettings):
)
return v.lower()
@validator("commands", always=True)
def validate_commands(cls, v, values): # noqa: N805
if v is None:
v = values["nos"]
return v
class Routers(BaseSettings):
"""Base model for devices class."""
@ -190,7 +197,9 @@ class Proxy(BaseSettings):
@validator("nos")
def supported_nos(cls, v): # noqa: N805
"""Validates that passed nos string is supported by hyperglass"""
"""
Validates that passed nos string is supported by hyperglass.
"""
if not v == "linux_ssh":
raise UnsupportedDevice(f'"{v}" device type is not supported.')
return v
@ -229,7 +238,7 @@ class General(BaseSettings):
redis_host: Union[str, IPvAnyNetwork] = "localhost"
redis_port: int = 6379
requires_ipv6_cidr: List[str] = ["cisco_ios", "cisco_nxos"]
query_timeout: int = 15
request_timeout: int = 15
class Branding(BaseSettings):
@ -358,6 +367,8 @@ class Messages(BaseSettings):
directed_cidr: str = "{query_type} queries can not be in CIDR format."
request_timeout: str = "Request timed out."
connection_error: str = "Error connecting to {device_name}: {error}"
authentication_error: str = "Authentication error occurred."
noresponse_error: str = "No response."
class Features(BaseSettings):