mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
add netmiko_delay_factor parameter; add output parsing module
This commit is contained in:
@@ -42,7 +42,7 @@ 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 `<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. |
|
||||
@@ -55,6 +55,11 @@ The following global settings can be set in `hyperglass.yaml`:
|
||||
| `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
|
||||
|
||||
|
@@ -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."""
|
||||
|
@@ -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()
|
||||
|
1
hyperglass/parsing/__init__.py
Normal file
1
hyperglass/parsing/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Parsing utilities for command output."""
|
25
hyperglass/parsing/common.py
Normal file
25
hyperglass/parsing/common.py
Normal file
@@ -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,)
|
Reference in New Issue
Block a user