From 6780b74c633fa9fff4b0e06861a4ed434abac1bd Mon Sep 17 00:00:00 2001 From: checktheroads Date: Thu, 19 Mar 2020 09:25:57 -0700 Subject: [PATCH] don't require display_name for default vrf; closes #28 --- hyperglass/configuration/models/routers.py | 27 +++++++++------------- hyperglass/configuration/models/vrfs.py | 3 +++ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/hyperglass/configuration/models/routers.py b/hyperglass/configuration/models/routers.py index a22b118..141733c 100644 --- a/hyperglass/configuration/models/routers.py +++ b/hyperglass/configuration/models/routers.py @@ -127,12 +127,9 @@ class Router(HyperglassModel): for afi in ("ipv4", "ipv6"): vrf_afi = vrf.get(afi) + # If AFI is actually defined (enabled), and if the + # source_address field is not set, raise an error if vrf_afi is not None and vrf_afi.get("source_address") is None: - - """ - If AFI is actually defined (enabled), and if the - source_address field is not set, raise an error - """ raise ConfigError( ( "VRF '{vrf}' in router '{router}' is missing a source " @@ -143,16 +140,13 @@ class Router(HyperglassModel): afi=afi.replace("ip", "IP"), ) + # If no display_name is set for a non-default VRF, try + # to make one by replacing non-alphanumeric characters + # with whitespaces and using str.title() to make each + # word look "pretty". if vrf_name != "default" and not isinstance( vrf.get("display_name"), StrictStr ): - - """ - If no display_name is set for a non-default VRF, try - to make one by replacing non-alphanumeric characters - with whitespaces and using str.title() to make each - word look "pretty". - """ new_name = vrf["name"] new_name = re.sub(r"[^a-zA-Z0-9]", " ", new_name) new_name = re.split(" ", new_name) @@ -163,10 +157,11 @@ class Router(HyperglassModel): f"Generated '{vrf['display_name']}'" ) - """ - Validate the non-default VRF against the standard - Vrf() class. - """ + elif vrf_name == "default" and vrf.get("display_name") is None: + vrf["display_name"] = "Global" + + # Validate the non-default VRF against the standard + # Vrf() class. vrf = Vrf(**vrf) vrfs.append(vrf) diff --git a/hyperglass/configuration/models/vrfs.py b/hyperglass/configuration/models/vrfs.py index 9b52f94..431b836 100644 --- a/hyperglass/configuration/models/vrfs.py +++ b/hyperglass/configuration/models/vrfs.py @@ -223,6 +223,9 @@ class Vrf(HyperglassModel): values["ipv6"].protocol = protocol6 values["ipv6"].version = 6 + if values.get("name") == "default" and values.get("display_name") is None: + values["display_name"] = "Global" + return values def __getitem__(self, i):