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

33 lines
988 B
Python
Raw Normal View History

"""Validate network configuration variables."""
# Project Imports
2019-10-04 16:54:32 -07:00
from hyperglass.configuration.models._utils import HyperglassModel
from hyperglass.configuration.models._utils import clean_name
2019-10-04 16:54:32 -07:00
class Network(HyperglassModel):
"""Validation Model for per-network/asn config in devices.yaml."""
name: str
display_name: str
2019-10-04 16:54:32 -07:00
class Networks(HyperglassModel):
"""Base model for networks class."""
@classmethod
def import_params(cls, input_params):
"""
Imports passed dict from YAML config, removes unsupported
characters from device names, dynamically sets attributes for
the credentials class.
"""
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