2019-12-29 23:57:39 -07:00
|
|
|
"""Validate network configuration variables."""
|
2019-09-11 01:35:31 -07:00
|
|
|
|
2019-12-31 18:29:43 -07:00
|
|
|
# Third Party Imports
|
|
|
|
from pydantic import StrictStr
|
|
|
|
|
2019-09-11 01:35:31 -07:00
|
|
|
# Project Imports
|
2019-10-04 16:54:32 -07:00
|
|
|
from hyperglass.configuration.models._utils import HyperglassModel
|
2019-10-09 03:10:52 -07:00
|
|
|
from hyperglass.configuration.models._utils import clean_name
|
2019-09-11 01:35:31 -07:00
|
|
|
|
|
|
|
|
2019-10-04 16:54:32 -07:00
|
|
|
class Network(HyperglassModel):
|
2019-12-29 23:57:39 -07:00
|
|
|
"""Validation Model for per-network/asn config in devices.yaml."""
|
2019-09-11 01:35:31 -07:00
|
|
|
|
2019-12-31 18:29:43 -07:00
|
|
|
name: StrictStr
|
|
|
|
display_name: StrictStr
|
2019-09-11 01:35:31 -07:00
|
|
|
|
|
|
|
|
2019-10-04 16:54:32 -07:00
|
|
|
class Networks(HyperglassModel):
|
2019-12-29 23:57:39 -07:00
|
|
|
"""Base model for networks class."""
|
2019-09-11 01:35:31 -07:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def import_params(cls, input_params):
|
2019-12-31 18:29:43 -07:00
|
|
|
"""Import loaded YAML, initialize per-network definitions.
|
|
|
|
|
|
|
|
Remove unsupported characters from network names, dynamically
|
|
|
|
set attributes for the networks class. Add cls.networks
|
|
|
|
attribute so network objects can be accessed inside a dict.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
input_params {dict} -- Unvalidated network definitions
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
{object} -- Validated networks object
|
2019-09-11 01:35:31 -07:00
|
|
|
"""
|
|
|
|
obj = Networks()
|
|
|
|
networks = {}
|
|
|
|
for (netname, params) in input_params.items():
|
|
|
|
netname = clean_name(netname)
|
|
|
|
setattr(Networks, netname, Network(**params))
|
|
|
|
networks.update({netname: Network(**params).dict()})
|
|
|
|
Networks.networks = networks
|
|
|
|
return obj
|