mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-25 11:54:06 +00:00
library: accept space-separated string for list
This allows for
ip:
address: '192.168.1.5/24'
instead of
ip:
address:
- '192.168.1.5/24'
This commit is contained in:
parent
6334379e93
commit
0ba7123d8d
2 changed files with 151 additions and 0 deletions
|
|
@ -579,6 +579,13 @@ class ArgValidatorList(ArgValidator):
|
|||
def construct_name(self, name):
|
||||
return ('' if n is None else n) + name
|
||||
def _validate(self, value, name):
|
||||
|
||||
if isinstance(value, Util.STRING_TYPE):
|
||||
# we expect a list. However, for convenience allow to
|
||||
# specify a string, separated by space. Escaping is
|
||||
# not supported. If you need that, define a proper list.
|
||||
value = [s for s in value.split(' ') if s]
|
||||
|
||||
result = []
|
||||
for (idx, v) in enumerate(value):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -234,6 +234,150 @@ class TestValidator(unittest.TestCase):
|
|||
]),
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
[
|
||||
{
|
||||
'autoconnect': True,
|
||||
'name': 'prod1',
|
||||
'parent': None,
|
||||
'ip': {
|
||||
'ip_is_present': True,
|
||||
'dhcp4': False,
|
||||
'route_metric6': None,
|
||||
'route_metric4': None,
|
||||
'dns_search': [],
|
||||
'dhcp4_send_hostname': None,
|
||||
'gateway6': None,
|
||||
'gateway4': None,
|
||||
'auto6': True,
|
||||
'dns': [],
|
||||
'address': [
|
||||
{
|
||||
'is_v4': True,
|
||||
'prefix': 24,
|
||||
'family': 2,
|
||||
'address': '192.168.174.5'
|
||||
}
|
||||
]
|
||||
},
|
||||
'state': 'up',
|
||||
'mtu': 1450,
|
||||
'check_iface_exists': True,
|
||||
'mac': '52:54:00:44:9f:ba',
|
||||
'master': None,
|
||||
'vlan_id': None,
|
||||
'ignore_errors': None,
|
||||
'interface_name': None,
|
||||
'type': 'ethernet',
|
||||
'slave_type': None,
|
||||
'wait': None
|
||||
},
|
||||
],
|
||||
n.AnsibleUtil.ARGS_CONNECTIONS.validate([
|
||||
{
|
||||
'name': 'prod1',
|
||||
'state': 'up',
|
||||
'type': 'ethernet',
|
||||
'autoconnect': 'yes',
|
||||
'mac': '52:54:00:44:9f:ba',
|
||||
'mtu': 1450,
|
||||
'ip': {
|
||||
'address': '192.168.174.5/24',
|
||||
}
|
||||
}
|
||||
]),
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
[
|
||||
{
|
||||
'autoconnect': True,
|
||||
'name': 'prod1',
|
||||
'parent': None,
|
||||
'ip': {
|
||||
'ip_is_present': False,
|
||||
'dhcp4': True,
|
||||
'auto6': True,
|
||||
'address': [],
|
||||
'route_metric6': None,
|
||||
'route_metric4': None,
|
||||
'dns_search': [],
|
||||
'dhcp4_send_hostname': None,
|
||||
'gateway6': None,
|
||||
'gateway4': None,
|
||||
'dns': []
|
||||
},
|
||||
'state': 'up',
|
||||
'mtu': 1450,
|
||||
'check_iface_exists': True,
|
||||
'mac': '52:54:00:44:9f:ba',
|
||||
'master': None,
|
||||
'vlan_id': None,
|
||||
'ignore_errors': None,
|
||||
'interface_name': None,
|
||||
'type': 'ethernet',
|
||||
'slave_type': None,
|
||||
'wait': None
|
||||
},
|
||||
{
|
||||
'autoconnect': True,
|
||||
'name': 'prod.100',
|
||||
'parent': 'prod1',
|
||||
'ip': {
|
||||
'ip_is_present': True,
|
||||
'dhcp4': False,
|
||||
'route_metric6': None,
|
||||
'route_metric4': None,
|
||||
'dns_search': [],
|
||||
'dhcp4_send_hostname': None,
|
||||
'gateway6': None,
|
||||
'gateway4': None,
|
||||
'auto6': True,
|
||||
'dns': [],
|
||||
'address': [
|
||||
{
|
||||
'is_v4': True,
|
||||
'prefix': 24,
|
||||
'family': 2,
|
||||
'address': '192.168.174.5'
|
||||
}
|
||||
]
|
||||
},
|
||||
'mac': None,
|
||||
'mtu': None,
|
||||
'check_iface_exists': True,
|
||||
'state': 'up',
|
||||
'master': None,
|
||||
'slave_type': None,
|
||||
'ignore_errors': None,
|
||||
'interface_name': 'prod.100',
|
||||
'type': 'vlan',
|
||||
'vlan_id': 100,
|
||||
'wait': None
|
||||
}
|
||||
],
|
||||
n.AnsibleUtil.ARGS_CONNECTIONS.validate([
|
||||
{
|
||||
'name': 'prod1',
|
||||
'state': 'up',
|
||||
'type': 'ethernet',
|
||||
'autoconnect': 'yes',
|
||||
'mac': '52:54:00:44:9f:ba',
|
||||
'mtu': 1450,
|
||||
},
|
||||
{
|
||||
'name': 'prod.100',
|
||||
'state': 'up',
|
||||
'type': 'vlan',
|
||||
'parent': 'prod1',
|
||||
'vlan_id': '100',
|
||||
'ip': {
|
||||
'address': [ '192.168.174.5/24' ],
|
||||
}
|
||||
}
|
||||
]),
|
||||
)
|
||||
|
||||
self.assertValidationError(n.AnsibleUtil.ARGS_CONNECTIONS,
|
||||
[ { } ])
|
||||
self.assertValidationError(n.AnsibleUtil.ARGS_CONNECTIONS,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue