mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
docker_host_info - Allow filters which are passed as lists (#160)
* Initial Commit * Adding integration tests * Adding example in docs * Adding changelog fragment * Applying initial review suggestions
This commit is contained in:
@@ -15,6 +15,7 @@ from distutils.version import LooseVersion
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, env_fallback, missing_required_lib
|
||||
from ansible.module_utils.common.collections import is_sequence
|
||||
from ansible.module_utils.common._collections_compat import Mapping, Sequence
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
@@ -927,23 +928,27 @@ class DifferenceTracker(object):
|
||||
return result
|
||||
|
||||
|
||||
def clean_dict_booleans_for_docker_api(data):
|
||||
def clean_dict_booleans_for_docker_api(data, allow_sequences=False):
|
||||
'''
|
||||
Go doesn't like Python booleans 'True' or 'False', while Ansible is just
|
||||
fine with them in YAML. As such, they need to be converted in cases where
|
||||
we pass dictionaries to the Docker API (e.g. docker_network's
|
||||
driver_options and docker_prune's filters).
|
||||
driver_options and docker_prune's filters). When `allow_sequences=True`
|
||||
YAML sequences (lists, tuples) are converted to [str] instead of str([...])
|
||||
which is the expected format of filters which accept lists such as labels.
|
||||
'''
|
||||
def sanitize(value):
|
||||
if value is True:
|
||||
return 'true'
|
||||
elif value is False:
|
||||
return 'false'
|
||||
else:
|
||||
return str(value)
|
||||
|
||||
result = dict()
|
||||
if data is not None:
|
||||
for k, v in data.items():
|
||||
if v is True:
|
||||
v = 'true'
|
||||
elif v is False:
|
||||
v = 'false'
|
||||
else:
|
||||
v = str(v)
|
||||
result[str(k)] = v
|
||||
result[str(k)] = [sanitize(e) for e in v] if allow_sequences and is_sequence(v) else sanitize(v)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user