diff --git a/hyperglass/command/construct.py b/hyperglass/command/construct.py index 0c638f4..34094c3 100644 --- a/hyperglass/command/construct.py +++ b/hyperglass/command/construct.py @@ -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") diff --git a/hyperglass/configuration/models.py b/hyperglass/configuration/models.py index e4113cc..533d665 100644 --- a/hyperglass/configuration/models.py +++ b/hyperglass/configuration/models.py @@ -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):