Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make api_modify to ignore builtin items #130

Merged
merged 6 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelogs/fragments/130-api-modify-builtin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
minor_changes:
- api_info - new parametr ``include_builtin``
therfert marked this conversation as resolved.
Show resolved Hide resolved
(https://github.com/ansible-collections/community.routeros/pull/130).
bugfixes:
therfert marked this conversation as resolved.
Show resolved Hide resolved
- api_modify - ignore ``builtin`` entries
(https://github.com/ansible-collections/community.routeros/pull/130).
20 changes: 17 additions & 3 deletions plugins/modules/api_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
description:
- Allows to retrieve information for a path using the API.
- This can be used to backup a path to restore it with the M(community.routeros.api_modify) module.
- Entries are normalized, and dynamic entries are not returned. Use the I(handle_disabled) and
I(hide_defaults) options to control normalization, the I(include_dynamic) option to also return
dynamic entries, and use I(unfiltered) to return all fields including counters.
- Entries are normalized, dynamic and builtin entries are not returned. Use the I(handle_disabled) and
I(hide_defaults) options to control normalization, the I(include_dynamic) and I(include_builtin) options to also return
dynamic resp. builtin entries, and use I(unfiltered) to return all fields including counters.
- B(Note) that this module is still heavily in development, and only supports B(some) paths.
If you want to support new paths, or think you found problems with existing paths, please first
L(create an issue in the community.routeros Issue Tracker,https://github.com/ansible-collections/community.routeros/issues/).
Expand Down Expand Up @@ -196,6 +196,13 @@
- If set to C(true), they are returned as well, and the C(dynamic) keys are returned as well.
type: bool
default: false
include_builtin:
description:
- Whether to include builtin values.
- By default, they are not returned, and the C(builtin) keys are omitted.
- If set to C(true), they are returned as well, and the C(builtin) keys are returned as well.
type: bool
default: false
therfert marked this conversation as resolved.
Show resolved Hide resolved
seealso:
- module: community.routeros.api
- module: community.routeros.api_facts
Expand Down Expand Up @@ -273,6 +280,7 @@ def main():
handle_disabled=dict(type='str', choices=['exclamation', 'null-value', 'omit'], default='exclamation'),
hide_defaults=dict(type='bool', default=True),
include_dynamic=dict(type='bool', default=False),
include_builtin=dict(type='bool', default=False),
)
module_args.update(api_argument_spec())

Expand All @@ -292,6 +300,7 @@ def main():
handle_disabled = module.params['handle_disabled']
hide_defaults = module.params['hide_defaults']
include_dynamic = module.params['include_dynamic']
include_builtin = module.params['include_builtin']
try:
api_path = compose_api_path(api, path)

Expand All @@ -301,12 +310,17 @@ def main():
if not include_dynamic:
if entry.get('dynamic', False):
continue
if not include_builtin:
if entry.get('builtin', False):
continue
if not unfiltered:
for k in list(entry):
if k == '.id':
continue
if k == 'dynamic' and include_dynamic:
continue
if k == 'builtin' and include_builtin:
continue
if k not in path_info.fields:
entry.pop(k)
if handle_disabled != 'omit':
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/api_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- Use the M(community.routeros.api_find_and_modify) module to modify one or multiple entries in a controlled way
depending on some search conditions.
- To make a backup of a path that can be restored with this module, use the M(community.routeros.api_info) module.
- The module ignores dynamic entries.
- The module ignores dynamic and builtin entries.
- B(Note) that this module is still heavily in development, and only supports B(some) paths.
If you want to support new paths, or think you found problems with existing paths, please first
L(create an issue in the community.routeros Issue Tracker,https://github.com/ansible-collections/community.routeros/issues/).
Expand Down Expand Up @@ -483,7 +483,7 @@ def match_entries(new_entries, old_entries, path_info, module):
def remove_dynamic(entries):
result = []
for entry in entries:
if entry.get('dynamic', False):
if entry.get('dynamic', False) or entry.get('builtin', False):
continue
result.append(entry)
return result
Expand Down