Skip to content

Commit

Permalink
Replace module._check_required_* calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Mar 23, 2021
1 parent c416215 commit a90a600
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ Name | Description
--- | ---
[vyos.vyos.vyos](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_cliconf.rst)|Use vyos cliconf to run command on VyOS platform

### Filter plugins
Name | Description
--- | ---

### Modules
Name | Description
--- | ---
Expand Down
3 changes: 3 additions & 0 deletions changelogs/fragments/replace-check_required.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
trivial:
- Replace module._check_required_* calls removed in ansible-core 2.11 with calls from common.validation
9 changes: 7 additions & 2 deletions plugins/modules/vyos_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@

from copy import deepcopy

from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.validation import check_required_if
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
remove_default_spec,
)
Expand Down Expand Up @@ -256,7 +258,10 @@ def map_params_to_obj(module, required_if=None):
if item.get(key) is None:
item[key] = module.params[key]

module._check_required_if(required_if, item)
try:
check_required_if(required_if, item)
except TypeError as exc:
module.fail_json(to_text(exc))
obj.append(item.copy())

else:
Expand Down Expand Up @@ -294,7 +299,7 @@ def main():
remove_default_spec(aggregate_spec)

argument_spec = dict(
aggregate=dict(type="list", elements="dict", options=aggregate_spec),
aggregate=dict(type="list", elements="dict", options=aggregate_spec)
)

argument_spec.update(element_spec)
Expand Down
9 changes: 7 additions & 2 deletions plugins/modules/vyos_static_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@

from copy import deepcopy

from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.validation import check_required_together
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
remove_default_spec,
)
Expand Down Expand Up @@ -238,7 +240,10 @@ def map_params_to_obj(module, required_together=None):
if item.get(key) is None:
item[key] = module.params[key]

module._check_required_together(required_together, item)
try:
check_required_together(required_together, item)
except TypeError as exc:
module.fail_json(to_text(exc))
d = item.copy()
if "/" in d["prefix"]:
d["mask"] = d["prefix"].split("/")[1]
Expand Down Expand Up @@ -289,7 +294,7 @@ def main():
remove_default_spec(aggregate_spec)

argument_spec = dict(
aggregate=dict(type="list", elements="dict", options=aggregate_spec),
aggregate=dict(type="list", elements="dict", options=aggregate_spec)
)

argument_spec.update(element_spec)
Expand Down
7 changes: 6 additions & 1 deletion plugins/modules/vyos_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@

from copy import deepcopy

from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.validation import check_required_one_of
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
remove_default_spec,
)
Expand Down Expand Up @@ -258,7 +260,10 @@ def map_params_to_obj(module):
module.fail_json(msg="vlan_id is required")

d["vlan_id"] = str(d["vlan_id"])
module._check_required_one_of(module.required_one_of, item)
try:
check_required_one_of(module.required_one_of, item)
except TypeError as exc:
module.fail_json(to_text(exc))

obj.append(d)
else:
Expand Down

0 comments on commit a90a600

Please sign in to comment.