Add regexp field to ip dns static (#142)

* Add regexp field to "ip dns static"

* Change test_invalid_required_missing to use "ip dhcp-server"

"ip dns static" requires name or regexp so it cannot be used in this test.

* Add required_one_of attribute to APIData

Used by "ip dns static" which requires either "name" or "regexp.

* Add mutually_exclusive attribute to APIData

Used by "ip dns static" where only one of "name" or "regexp" can be used.

* Add changelog fragment
This commit is contained in:
Andrei Costescu 2022-12-29 08:51:40 +01:00 committed by GitHub
parent 62da7dd4e3
commit 586edbc211
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 98 additions and 4 deletions

View file

@ -13,6 +13,8 @@ __metaclass__ = type
class APIData(object):
def __init__(self, primary_keys=None,
stratify_keys=None,
required_one_of=None,
mutually_exclusive=None,
has_identifier=False,
single_value=False,
unknown_mechanism=False,
@ -25,6 +27,8 @@ class APIData(object):
raise ValueError('unknown_mechanism and fully_understood cannot be combined')
self.primary_keys = primary_keys
self.stratify_keys = stratify_keys
self.required_one_of = required_one_of or []
self.mutually_exclusive = mutually_exclusive or []
self.has_identifier = has_identifier
self.single_value = single_value
self.unknown_mechanism = unknown_mechanism
@ -43,6 +47,20 @@ class APIData(object):
for sk in stratify_keys:
if sk not in fields:
raise ValueError('Stratify key {sk} must be in fields!'.format(sk=sk))
if required_one_of:
for index, require_list in enumerate(required_one_of):
if not isinstance(require_list, list):
raise ValueError('Require one of element at index #{index} must be a list!'.format(index=index + 1))
for rk in require_list:
if rk not in fields:
raise ValueError('Require one of key {rk} must be in fields!'.format(rk=rk))
if mutually_exclusive:
for index, exclusive_list in enumerate(mutually_exclusive):
if not isinstance(exclusive_list, list):
raise ValueError('Mutually exclusive element at index #{index} must be a list!'.format(index=index + 1))
for ek in exclusive_list:
if ek not in fields:
raise ValueError('Mutually exclusive key {ek} must be in fields!'.format(ek=ek))
class KeyInfo(object):
@ -1356,7 +1374,8 @@ PATHS = {
),
('ip', 'dns', 'static'): APIData(
fully_understood=True,
stratify_keys=('name', ),
required_one_of=[['name', 'regexp']],
mutually_exclusive=[['name', 'regexp']],
fields={
'address': KeyInfo(),
'cname': KeyInfo(),
@ -1365,8 +1384,9 @@ PATHS = {
'forward-to': KeyInfo(),
'mx-exchange': KeyInfo(),
'mx-preference': KeyInfo(),
'name': KeyInfo(required=True),
'name': KeyInfo(),
'ns': KeyInfo(),
'regexp': KeyInfo(),
'srv-port': KeyInfo(),
'srv-priority': KeyInfo(),
'srv-target': KeyInfo(),