1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

fix import

This commit is contained in:
checktheroads
2020-01-17 02:50:57 -07:00
parent ca90cb4e10
commit 0728965999
285 changed files with 24331 additions and 9611 deletions

View File

@@ -5,14 +5,20 @@ import asyncio
from pathlib import Path
# Third Party Imports
import ujson as json
import yaml
from aiofile import AIOFile
from pydantic import ValidationError
# Project Imports
from hyperglass.configuration.markdown import get_markdown
from hyperglass.configuration.models import commands as _commands
from hyperglass.configuration.models import params as _params
from hyperglass.configuration.models import routers as _routers
from hyperglass.constants import CREDIT
from hyperglass.constants import DEFAULT_HELP
from hyperglass.constants import DEFAULT_DETAILS
from hyperglass.constants import DEFAULT_TERMS
from hyperglass.constants import LOG_HANDLER
from hyperglass.constants import LOG_HANDLER_FILE
from hyperglass.constants import LOG_LEVELS
@@ -314,6 +320,60 @@ def _build_queries():
return queries
content_params = json.loads(
params.general.json(
include={"primary_asn", "org_name", "site_title", "site_description"}
)
)
def _build_vrf_help():
"""Build a dict of vrfs as keys, help content as values.
Returns:
{dict} -- Formatted VRF help
"""
all_help = {}
for vrf in devices.vrf_objects:
vrf_help = {}
for command in Supported.query_types:
cmd = getattr(vrf.info, command)
help_params = content_params
if cmd.params.title is None:
cmd.params.title = (
f"{vrf.display_name}: {getattr(params.branding.text, command)}"
)
help_params.update(cmd.params.dict())
md = asyncio.run(
get_markdown(
config_path=cmd,
default=DEFAULT_DETAILS[command],
params=help_params,
)
)
vrf_help.update(
{command: {"content": md, "enable": cmd.enable, "params": help_params}}
)
all_help.update({vrf.name: vrf_help})
return all_help
content_vrf = _build_vrf_help()
content_help = asyncio.run(
get_markdown(
config_path=params.branding.help_menu,
default=DEFAULT_HELP,
params=content_params,
)
)
content_terms = asyncio.run(
get_markdown(
config_path=params.branding.terms, default=DEFAULT_TERMS, params=content_params
)
)
content_credit = CREDIT
vrfs = _build_vrfs()
queries = _build_queries()
networks = _build_networks()
@@ -346,6 +406,12 @@ _frontend_params.update(
"devices": frontend_devices,
"networks": networks,
"vrfs": vrfs,
"content": {
"help_menu": content_help,
"terms": content_terms,
"credit": content_credit,
"vrf": content_vrf,
},
}
)
frontend_params = _frontend_params

View File

@@ -0,0 +1,63 @@
# Third Party Imports
from aiofile import AIOFile
# Project Imports
from hyperglass.util import log
async def _get_file(path_obj):
"""Read a file.
Arguments:
path_obj {Path} -- Path to file.
Returns:
{str} -- File contents
"""
async with AIOFile(path_obj, "r") as raw_file:
file = await raw_file.read()
return file
async def format_markdown(content, params):
"""Format content with config parameters.
Arguments:
content {str} -- Unformatted content
Returns:
{str} -- Formatted content
"""
try:
fmt = content.format(**params)
except KeyError:
fmt = content
return fmt
async def get_markdown(config_path, default, params):
"""Get markdown file if specified, or use default.
Format the content with config parameters.
Arguments:
config_path {object} -- content config
default {str} -- default content
Returns:
{str} -- Formatted content
"""
log.debug(f"Getting Markdown content for '{params['title']}'")
if config_path.enable and config_path.file is not None:
md = await _get_file(config_path.file)
else:
md = default
log.debug(f"Unformatted Content for '{params['title']}':\n{md}")
md_fmt = await format_markdown(md, params)
log.debug(f"Formatted Content for '{params['title']}':\n{md_fmt}")
return md_fmt

View File

@@ -22,8 +22,6 @@ from hyperglass.configuration.models._utils import HyperglassModel
class Branding(HyperglassModel):
"""Validation model for params.branding."""
site_title: StrictStr = "hyperglass"
class Colors(HyperglassModel):
"""Validation model for params.colors."""
@@ -103,11 +101,11 @@ class Branding(HyperglassModel):
logo_dark = values.get("dark")
default_logo_light = (
Path(__file__).parent.parent.parent
/ "static/ui/images/hyperglass-light.png"
/ "static/images/hyperglass-light.png"
)
default_logo_dark = (
Path(__file__).parent.parent.parent
/ "static/ui/images/hyperglass-dark.png"
/ "static/images/hyperglass-dark.png"
)
# Use light logo as dark logo if dark logo is undefined.

View File

@@ -26,6 +26,7 @@ class General(HyperglassModel):
debug: StrictBool = False
primary_asn: StrictStr = "65001"
org_name: StrictStr = "The Company"
site_title: StrictStr = "hyperglass"
site_description: StrictStr = "{org_name} Network Looking Glass"
site_keywords: List[StrictStr] = [
"hyperglass",

View File

@@ -32,7 +32,7 @@ class OpenGraph(HyperglassModel):
if value is None:
value = (
Path(__file__).parent.parent.parent
/ "static/ui/images/hyperglass-opengraph.png"
/ "static/images/hyperglass-opengraph.png"
)
with PilImage.open(value) as img:
width, height = img.size

View File

@@ -12,19 +12,38 @@ from typing import Optional
# Third Party Imports
from pydantic import FilePath
from pydantic import IPvAnyNetwork
from pydantic import StrictBool
from pydantic import StrictStr
from pydantic import constr
from pydantic import validator
# Project Imports
from hyperglass.configuration.models._utils import HyperglassModel
from hyperglass.configuration.models._utils import HyperglassModelExtra
class InfoConfigParams(HyperglassModelExtra):
"""Validation model for per-help params."""
title: Optional[StrictStr]
class InfoConfig(HyperglassModel):
"""Validation model for help configuration."""
enable: StrictBool = True
file: Optional[FilePath]
params: InfoConfigParams = InfoConfigParams()
class Info(HyperglassModel):
"""Validation model for per-VRF help files."""
"""Validation model for per-VRF, per-Command help."""
bgp_aspath: Optional[FilePath]
bgp_community: Optional[FilePath]
bgp_aspath: InfoConfig = InfoConfig()
bgp_community: InfoConfig = InfoConfig()
bgp_route: InfoConfig = InfoConfig()
ping: InfoConfig = InfoConfig()
traceroute: InfoConfig = InfoConfig()
class DeviceVrf4(HyperglassModel):