diff --git a/docs/docs/configuration.mdx b/docs/docs/configuration.mdx index f6dec43..bbeeac4 100644 --- a/docs/docs/configuration.mdx +++ b/docs/docs/configuration.mdx @@ -41,20 +41,25 @@ Configuration files may be located in one of the following directories: The following global settings can be set in `hyperglass.yaml`: -| Parameter | Type | Default | Description | -| :----------------- | :-----: | :----------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `debug` | Boolean | `false` | Enable application-wide debug mode. **This will generate a log of logs!** | -| `developer_mode` | Boolean | `false` | If enabled, the hyperglass backend (Python) and frontend (React/Javascript) applications are "unlinked", so that React tools can be used for front end development. A `` convenience component is also displayed in the UI for easier UI development.' | -| `primary_asn` | String | `'65000'` | Your network's primary ASN. This field is used to set some useful defaults such as the subtitle and PeeringDB URL. | -| `org_name` | String | `'Beloved Hyperglass User'` | Your organization's name. This field is used in the UI & API documentation to set fields such as `` HTML tags for SEO and the terms & conditions footer component. | -| `site_title` | String | `'hyperglass'` | The name of your hyperglass site. This field is used in the UI & API documentation to set fields such as the `` HTML tag, and the terms & conditions footer component. | -| `site_description` | String | `'{org_name} Network Looking Glass'` | A short description of your hyperglass site. This field is used in th UI & API documentation to set the `<meta name="description"/>` tag. `{org_name}` may be used to insert the value of the `org_name` field. | -| `site_keywords` | List | | Keywords pertaining to your hyperglass site. This field is used to generate `<meta name="keywords"/>` HTML tags, which helps tremendously with [SEO](https://support.google.com/webmasters/answer/7451184). | -| `request_timeout` | Integer | `30` | Global timeout in seconds for all requests. The UI uses this field's exact value when submitting queries. The backend uses this field's value, minus one second, for its own timeout handling. This is to ensure a contextual timeout error is presented to the end user in the event of a backend application timeout. | -| `listen_address` | String | `'localhost'` | Local IP Address or hostname the hyperglass application listens on to serve web traffic. | -| `listen_port` | Integer | `8001` | Local TCP port the hyperglass application listens on to serve web traffic. | -| `log_file` | String | | Path to a log file to which hyperglass can write logs. If none is set, hyperglass will write logs to a file located at `/tmp/`, with a uniquely generated name for each time hyperglass is started. | -| `cors_origins` | List | `[]` | Allowed [CORS](https://developer.mozilla.org/docs/Web/HTTP/CORS) hosts. By default, no CORS hosts are allowed. | +| Parameter | Type | Default | Description | +| :--------------------- | :--------------: | :----------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `debug` | Boolean | `false` | Enable application-wide debug mode. **This will generate a log of logs!** | +| `developer_mode` | Boolean | `false` | If enabled, the hyperglass backend (Python) and frontend (React/Javascript) applications are "unlinked", so that React tools can be used for front end development. A `<Debugger />` convenience component is also displayed in the UI for easier UI development.' | +| `primary_asn` | String | `'65000'` | Your network's primary ASN. This field is used to set some useful defaults such as the subtitle and PeeringDB URL. | +| `org_name` | String | `'Beloved Hyperglass User'` | Your organization's name. This field is used in the UI & API documentation to set fields such as `<meta/>` HTML tags for SEO and the terms & conditions footer component. | +| `site_title` | String | `'hyperglass'` | The name of your hyperglass site. This field is used in the UI & API documentation to set fields such as the `<title/>` HTML tag, and the terms & conditions footer component. | +| `site_description` | String | `'{org_name} Network Looking Glass'` | A short description of your hyperglass site. This field is used in th UI & API documentation to set the `<meta name="description"/>` tag. `{org_name}` may be used to insert the value of the `org_name` field. | +| `site_keywords` | List | | Keywords pertaining to your hyperglass site. This field is used to generate `<meta name="keywords"/>` HTML tags, which helps tremendously with [SEO](https://support.google.com/webmasters/answer/7451184). | +| `request_timeout` | Integer | `30` | Global timeout in seconds for all requests. The UI uses this field's exact value when submitting queries. The backend uses this field's value, minus one second, for its own timeout handling. This is to ensure a contextual timeout error is presented to the end user in the event of a backend application timeout. | +| `listen_address` | String | `'localhost'` | Local IP Address or hostname the hyperglass application listens on to serve web traffic. | +| `listen_port` | Integer | `8001` | Local TCP port the hyperglass application listens on to serve web traffic. | +| `log_file` | String | | Path to a log file to which hyperglass can write logs. If none is set, hyperglass will write logs to a file located at `/tmp/`, with a uniquely generated name for each time hyperglass is started. | +| `cors_origins` | List | `[]` | Allowed [CORS](https://developer.mozilla.org/docs/Web/HTTP/CORS) hosts. By default, no CORS hosts are allowed. | +| `netmiko_delay_factor` | Integer \| Float | `0.1` | Override the [Netmiko global delay factor](https://ktbyers.github.io/netmiko/docs/netmiko/index.html). | + +:::note +The `netmiko_delay_factor` parameter should only be used if you're experiencing strange SSH connection issues. By default, Netmiko uses a `global_delay_factor` of `1`, which tends to be a bit slow for running a simple show command. hyperglass overrides this to `0.1` by default, but you can override this to whatever value suits your environment if needed. +::: #### Example diff --git a/hyperglass/configuration/models/_utils.py b/hyperglass/configuration/models/_utils.py index 82a4c72..928603a 100644 --- a/hyperglass/configuration/models/_utils.py +++ b/hyperglass/configuration/models/_utils.py @@ -4,13 +4,16 @@ import os import re from pathlib import Path +from typing import TypeVar # Third Party -from pydantic import HttpUrl, BaseModel +from pydantic import HttpUrl, BaseModel, StrictInt, StrictFloat # Project from hyperglass.util import log, clean_name +IntFloat = TypeVar("IntFloat", StrictInt, StrictFloat) + class HyperglassModel(BaseModel): """Base model for all hyperglass configuration models.""" diff --git a/hyperglass/configuration/models/params.py b/hyperglass/configuration/models/params.py index 15f5bd2..4a27ef1 100644 --- a/hyperglass/configuration/models/params.py +++ b/hyperglass/configuration/models/params.py @@ -21,9 +21,9 @@ from pydantic import ( from hyperglass.configuration.models.web import Web from hyperglass.configuration.models.docs import Docs from hyperglass.configuration.models.cache import Cache -from hyperglass.configuration.models._utils import HyperglassModel from hyperglass.configuration.models.queries import Queries from hyperglass.configuration.models.messages import Messages +from hyperglass.configuration.models._utils import HyperglassModel, IntFloat class Params(HyperglassModel): @@ -83,7 +83,7 @@ class Params(HyperglassModel): description='Keywords pertaining to your hyperglass site. This field is used to generate `<meta name="keywords"/>` HTML tags, which helps tremendously with SEO.', ) request_timeout: StrictInt = Field( - 65, + 90, title="Request Timeout", description="Global timeout in seconds for all requests. The frontend application (UI) uses this field's exact value when submitting queries. The backend application uses this field's value, minus one second, for its own timeout handling. This is to ensure a contextual timeout error is presented to the end user in the event of a backend application timeout.", ) @@ -107,6 +107,11 @@ class Params(HyperglassModel): title="Cross-Origin Resource Sharing", description="Allowed CORS hosts. By default, no CORS hosts are allowed.", ) + netmiko_delay_factor: IntFloat = Field( + 0.1, + title="Netmiko Delay Factor", + description="Override the netmiko global delay factor.", + ) # Sub Level Params cache: Cache = Cache() diff --git a/hyperglass/parsing/__init__.py b/hyperglass/parsing/__init__.py new file mode 100644 index 0000000..a3270f0 --- /dev/null +++ b/hyperglass/parsing/__init__.py @@ -0,0 +1 @@ +"""Parsing utilities for command output.""" diff --git a/hyperglass/parsing/common.py b/hyperglass/parsing/common.py new file mode 100644 index 0000000..b618ee9 --- /dev/null +++ b/hyperglass/parsing/common.py @@ -0,0 +1,25 @@ +"""Command parsers applied to all unstructured output.""" + + +async def remove_command(commands, output): + """Remove anything before the command if found in output. + + Arguments: + command {str} -- Command run for query + output {str} -- Raw output + + Returns: + {str} -- Parsed output + """ + _output = output.strip().split("\n") + + for command in commands: + for line in _output: + if command in line: + idx = _output.index(line) + 1 + _output = _output[idx:] + + return "\n".join(_output) + + +parsers = (remove_command,)