2019-12-29 23:57:39 -07:00
|
|
|
"""Validate SSH proxy configuration variables."""
|
2019-09-11 01:35:31 -07:00
|
|
|
|
|
|
|
# Third Party Imports
|
2019-12-31 18:29:43 -07:00
|
|
|
from pydantic import StrictInt
|
|
|
|
from pydantic import StrictStr
|
2019-09-11 01:35:31 -07:00
|
|
|
from pydantic import validator
|
|
|
|
|
|
|
|
# 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
|
|
|
|
from hyperglass.configuration.models.credentials import Credential
|
2019-09-11 01:35:31 -07:00
|
|
|
from hyperglass.exceptions import UnsupportedDevice
|
|
|
|
|
|
|
|
|
2019-10-04 16:54:32 -07:00
|
|
|
class Proxy(HyperglassModel):
|
2019-12-29 23:57:39 -07:00
|
|
|
"""Validation model for per-proxy config in devices.yaml."""
|
2019-09-11 01:35:31 -07:00
|
|
|
|
2019-12-31 18:29:43 -07:00
|
|
|
name: StrictStr
|
|
|
|
address: StrictStr
|
|
|
|
port: StrictInt = 22
|
2019-10-09 03:10:52 -07:00
|
|
|
credential: Credential
|
2019-12-31 18:29:43 -07:00
|
|
|
nos: StrictStr = "linux_ssh"
|
2019-09-11 01:35:31 -07:00
|
|
|
|
|
|
|
@validator("nos")
|
2019-12-31 18:29:43 -07:00
|
|
|
def supported_nos(cls, value):
|
|
|
|
"""Verify NOS is supported by hyperglass.
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
UnsupportedDevice: Raised if NOS is not supported.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
{str} -- Valid NOS name
|
2019-09-11 01:35:31 -07:00
|
|
|
"""
|
2019-12-29 23:57:39 -07:00
|
|
|
if not value == "linux_ssh":
|
|
|
|
raise UnsupportedDevice(f'"{value}" device type is not supported.')
|
|
|
|
return value
|
2019-09-11 01:35:31 -07:00
|
|
|
|
|
|
|
|
2019-10-04 16:54:32 -07:00
|
|
|
class Proxies(HyperglassModel):
|
2019-12-29 23:57:39 -07:00
|
|
|
"""Validation model for SSH proxy configuration."""
|
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-proxy definitions.
|
|
|
|
|
|
|
|
Remove unsupported characters from proxy names, dynamically
|
|
|
|
set attributes for the proxies class.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
input_params {dict} -- Unvalidated proxy definitions
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
{object} -- Validated proxies object
|
2019-09-11 01:35:31 -07:00
|
|
|
"""
|
|
|
|
obj = Proxies()
|
|
|
|
for (devname, params) in input_params.items():
|
|
|
|
dev = clean_name(devname)
|
|
|
|
setattr(Proxies, dev, Proxy(**params))
|
|
|
|
return obj
|