forked from mirrors/thatmattlove-hyperglass
✨ Add networks config model
This commit is contained in:
parent
9d933944ef
commit
4bc56895a9
2 changed files with 30 additions and 8 deletions
|
|
@ -65,6 +65,7 @@ try:
|
|||
devices = models.Routers.import_params(user_devices["router"])
|
||||
credentials = models.Credentials.import_params(user_devices["credential"])
|
||||
proxies = models.Proxies.import_params(user_devices["proxy"])
|
||||
networks = models.Networks.import_params(user_devices["network"])
|
||||
except ValidationError as validation_errors:
|
||||
errors = validation_errors.errors()
|
||||
for error in errors:
|
||||
|
|
|
|||
|
|
@ -132,7 +132,35 @@ class Routers(BaseSettings):
|
|||
class Config:
|
||||
"""Pydantic Config"""
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
validate_all = True
|
||||
validate_assignment = True
|
||||
|
||||
|
||||
class Network(BaseSettings):
|
||||
"""Model for per-network/asn config in devices.yaml"""
|
||||
|
||||
asn: int
|
||||
display_name: str
|
||||
|
||||
|
||||
class Networks(BaseSettings):
|
||||
"""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()
|
||||
for (netname, params) in input_params.items():
|
||||
netname = clean_name(netname)
|
||||
setattr(Networks, netname, Network(**params))
|
||||
return obj
|
||||
|
||||
class Config:
|
||||
"""Pydantic Config"""
|
||||
|
||||
validate_all = True
|
||||
validate_assignment = True
|
||||
|
|
@ -164,8 +192,6 @@ class Credentials(BaseSettings):
|
|||
class Config:
|
||||
"""Pydantic Config"""
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
validate_all = True
|
||||
validate_assignment = True
|
||||
|
||||
|
|
@ -207,8 +233,6 @@ class Proxies(BaseSettings):
|
|||
class Config:
|
||||
"""Pydantic Config"""
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
validate_all = True
|
||||
validate_assignment = True
|
||||
|
||||
|
|
@ -489,7 +513,6 @@ class Params(BaseSettings):
|
|||
class Config:
|
||||
"""Pydantic Config"""
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
validate_all = True
|
||||
validate_assignment = True
|
||||
|
||||
|
|
@ -636,7 +659,5 @@ class Commands(BaseSettings):
|
|||
class Config:
|
||||
"""Pydantic Config"""
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
validate_all = False
|
||||
validate_assignment = True
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue