modules: update code to python3 (#10904)
Some checks failed
EOL CI / EOL Sanity (Ⓐ2.17) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.17+py3.10) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.17+py3.12) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.17+py3.7) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/3/) (push) Has been cancelled
nox / Run extra sanity tests (push) Has been cancelled

* modules: update code to python3

* pamd: rollback changes

* add changelog frag

* fix/improve assignments using generators

* Update plugins/modules/launchd.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2025-10-14 08:42:48 +13:00 committed by GitHub
commit 3b83df3f79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 113 additions and 86 deletions

View file

@ -0,0 +1,30 @@
minor_changes:
- bitbucket_access_key - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- bitbucket_pipeline_known_host - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- bitbucket_pipeline_variable - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- bzr - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- capabilities - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- gitlab_milestone - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- haproxy - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- homebrew - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- homebrew_cask - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- hwc_network_vpc - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- hwc_smn_topic - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- idrac_redfish_config - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- idrac_redfish_info - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- influxdb_retention_policy - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- ini_file - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- interfaces_file - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- launchd - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- logentries - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- packet_sshkey - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- pamd - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- taiga_issue - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- vdo - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- vertica_role - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- vertica_schema - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- vertica_user - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- vexata_eg - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- vexata_volume - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- xcc_redfish_command - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).
- zypper - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10904).

View file

@ -155,7 +155,7 @@ def get_existing_deploy_key(module, bitbucket):
if info['status'] != 200: if info['status'] != 200:
module.fail_json(msg='Failed to retrieve the list of deploy keys: {0}'.format(info)) module.fail_json(msg='Failed to retrieve the list of deploy keys: {0}'.format(info))
res = next(iter(filter(lambda v: v['label'] == module.params['label'], content['values'])), None) res = next((v for v in content['values'] if v['label'] == module.params['label']), None)
if res is not None: if res is not None:
return res return res

View file

@ -151,7 +151,7 @@ def get_existing_known_host(module, bitbucket):
if info['status'] != 200: if info['status'] != 200:
module.fail_json(msg='Failed to retrieve list of known hosts: {0}'.format(info)) module.fail_json(msg='Failed to retrieve list of known hosts: {0}'.format(info))
host = next(filter(lambda v: v['hostname'] == module.params['name'], content['values']), None) host = next((v for v in content['values'] if v['hostname'] == module.params['name']), None)
if host is not None: if host is not None:
return host return host

View file

@ -139,7 +139,7 @@ def get_existing_pipeline_variable(module, bitbucket):
return None return None
page += 1 page += 1
var = next(filter(lambda v: v['key'] == module.params['name'], content['values']), None) var = next((v for v in content['values'] if v['key'] == module.params['name']), None)
if var is not None: if var is not None:
var['name'] = var.pop('key') var['name'] = var.pop('key')

View file

@ -101,8 +101,9 @@ class Bzr(object):
cmd = [self.bzr_path, "status", "-S"] cmd = [self.bzr_path, "status", "-S"]
rc, stdout, stderr = self.module.run_command(cmd, cwd=self.dest) rc, stdout, stderr = self.module.run_command(cmd, cwd=self.dest)
lines = stdout.splitlines() lines = stdout.splitlines()
mods_re = re.compile('^\\?\\?.*$')
lines = filter(lambda c: not re.search('^\\?\\?.*$', c), lines) lines = [c for c in lines if not mods_re.search(c)]
return len(lines) > 0 return len(lines) > 0
def reset(self, force): def reset(self, force):

View file

@ -91,7 +91,7 @@ class CapabilitiesModule(object):
self.module.exit_json(changed=True, msg='capabilities changed') self.module.exit_json(changed=True, msg='capabilities changed')
else: else:
# remove from current cap list if it is already set (but op/flags differ) # remove from current cap list if it is already set (but op/flags differ)
current = list(filter(lambda x: x[0] != self.capability_tup[0], current)) current = [x for x in current if x[0] != self.capability_tup[0]]
# add new cap with correct op/flags # add new cap with correct op/flags
current.append(self.capability_tup) current.append(self.capability_tup)
self.module.exit_json(changed=True, state=self.state, msg='capabilities changed', stdout=self.setcap(self.path, current)) self.module.exit_json(changed=True, state=self.state, msg='capabilities changed', stdout=self.setcap(self.path, current))
@ -101,7 +101,7 @@ class CapabilitiesModule(object):
self.module.exit_json(changed=True, msg='capabilities changed') self.module.exit_json(changed=True, msg='capabilities changed')
else: else:
# remove from current cap list and then set current list # remove from current cap list and then set current list
current = filter(lambda x: x[0] != self.capability_tup[0], current) current = [x for x in current if x[0] != self.capability_tup[0]]
self.module.exit_json(changed=True, state=self.state, msg='capabilities changed', stdout=self.setcap(self.path, current)) self.module.exit_json(changed=True, state=self.state, msg='capabilities changed', stdout=self.setcap(self.path, current))
self.module.exit_json(changed=False, state=self.state) self.module.exit_json(changed=False, state=self.state)

View file

@ -268,7 +268,7 @@ class GitlabMilestones(object):
def get_milestone_id(self, _title): def get_milestone_id(self, _title):
_milestone_list = self.gitlab_object.milestones.list() _milestone_list = self.gitlab_object.milestones.list()
_found = list(filter(lambda x: x.title == _title, _milestone_list)) _found = [x for x in _milestone_list if x.title == _title]
if _found: if _found:
return _found[0].id return _found[0].id
else: else:

View file

@ -297,7 +297,7 @@ class HAProxy(object):
""" """
data = self.execute('show stat', 200, False).lstrip('# ') data = self.execute('show stat', 200, False).lstrip('# ')
r = csv.DictReader(data.splitlines()) r = csv.DictReader(data.splitlines())
return tuple(map(lambda d: d['pxname'], filter(lambda d: d['svname'] == 'BACKEND', r))) return tuple(d['pxname'] for d in r if d['svname'] == 'BACKEND')
def discover_version(self): def discover_version(self):
""" """
@ -346,13 +346,11 @@ class HAProxy(object):
""" """
data = self.execute('show stat', 200, False).lstrip('# ') data = self.execute('show stat', 200, False).lstrip('# ')
r = csv.DictReader(data.splitlines()) r = csv.DictReader(data.splitlines())
state = tuple(
map( def unpack_state(d):
lambda d: {'status': d['status'], 'weight': d['weight'], 'scur': d['scur']}, return {'status': d['status'], 'weight': d['weight'], 'scur': d['scur']}
filter(lambda d: (pxname is None or d['pxname']
== pxname) and d['svname'] == svname, r) state = tuple(unpack_state(d) for d in r if (pxname is None or d['pxname'] == pxname) and d['svname'] == svname)
)
)
return state or None return state or None
def wait_until_status(self, pxname, svname, status): def wait_until_status(self, pxname, svname, status):

View file

@ -192,7 +192,7 @@ class HomebrewException(Exception):
# utils ------------------------------------------------------------------- {{{ # utils ------------------------------------------------------------------- {{{
def _create_regex_group_complement(s): def _create_regex_group_complement(s):
lines = (line.strip() for line in s.split('\n') if line.strip()) lines = (line.strip() for line in s.split('\n') if line.strip())
chars = filter(None, (line.split('#')[0].strip() for line in lines)) chars = [_f for _f in (line.split('#')[0].strip() for line in lines) if _f]
group = r'[^' + r''.join(chars) + r']' group = r'[^' + r''.join(chars) + r']'
return re.compile(group) return re.compile(group)

View file

@ -169,7 +169,7 @@ class HomebrewCaskException(Exception):
# utils ------------------------------------------------------------------- {{{ # utils ------------------------------------------------------------------- {{{
def _create_regex_group_complement(s): def _create_regex_group_complement(s):
lines = (line.strip() for line in s.split('\n') if line.strip()) lines = (line.strip() for line in s.split('\n') if line.strip())
chars = filter(None, (line.split('#')[0].strip() for line in lines)) chars = [_f for _f in (line.split('#')[0].strip() for line in lines) if _f]
group = r'[^' + r''.join(chars) + r']' group = r'[^' + r''.join(chars) + r']'
return re.compile(group) return re.compile(group)
# /utils ------------------------------------------------------------------ }}} # /utils ------------------------------------------------------------------ }}}

View file

@ -376,13 +376,13 @@ def response_to_hash(module, response):
This is for doing comparisons with Ansible's current parameters. This is for doing comparisons with Ansible's current parameters.
""" """
return { return {
u'id': response.get(u'id'), 'id': response.get('id'),
u'name': response.get(u'name'), 'name': response.get('name'),
u'cidr': response.get(u'cidr'), 'cidr': response.get('cidr'),
u'status': response.get(u'status'), 'status': response.get('status'),
u'routes': VpcRoutesArray( 'routes': VpcRoutesArray(
response.get(u'routes', []), module).from_response(), response.get('routes', []), module).from_response(),
u'enable_shared_snat': response.get(u'enable_shared_snat') 'enable_shared_snat': response.get('enable_shared_snat')
} }
@ -480,14 +480,14 @@ class VpcRoutesArray(object):
def _request_for_item(self, item): def _request_for_item(self, item):
return { return {
u'destination': item.get('destination'), 'destination': item.get('destination'),
u'nexthop': item.get('next_hop') 'nexthop': item.get('next_hop')
} }
def _response_from_item(self, item): def _response_from_item(self, item):
return { return {
u'destination': item.get(u'destination'), 'destination': item.get('destination'),
u'next_hop': item.get(u'nexthop') 'next_hop': item.get('nexthop')
} }

View file

@ -312,13 +312,12 @@ def response_to_hash(module, response):
This is for doing comparisons with Ansible's current parameters. This is for doing comparisons with Ansible's current parameters.
""" """
return { return {
u'create_time': response.get(u'create_time'), 'create_time': response.get('create_time'),
u'display_name': response.get(u'display_name'), 'display_name': response.get('display_name'),
u'name': response.get(u'name'), 'name': response.get('name'),
u'push_policy': _push_policy_convert_from_response( 'push_policy': _push_policy_convert_from_response(response.get('push_policy')),
response.get('push_policy')), 'topic_urn': response.get('topic_urn'),
u'topic_urn': response.get(u'topic_urn'), 'update_time': response.get('update_time')
u'update_time': response.get(u'update_time')
} }

View file

@ -205,14 +205,14 @@ class IdracRedfishUtils(RedfishUtils):
for attr_name, attr_value in attributes.items(): for attr_name, attr_value in attributes.items():
# Check if attribute exists # Check if attribute exists
if attr_name not in data[u'Attributes']: if attr_name not in data['Attributes']:
# Skip and proceed to next attribute if this isn't valid # Skip and proceed to next attribute if this isn't valid
attrs_bad.update({attr_name: attr_value}) attrs_bad.update({attr_name: attr_value})
continue continue
# Find out if value is already set to what we want. If yes, exclude # Find out if value is already set to what we want. If yes, exclude
# those attributes # those attributes
if data[u'Attributes'][attr_name] == attr_value: if data['Attributes'][attr_name] == attr_value:
attrs_skipped.update({attr_name: attr_value}) attrs_skipped.update({attr_name: attr_value})
else: else:
attrs_to_patch.update({attr_name: attr_value}) attrs_to_patch.update({attr_name: attr_value})

View file

@ -149,8 +149,8 @@ class IdracRedfishUtils(RedfishUtils):
# Manager attributes are supported as part of iDRAC OEM extension # Manager attributes are supported as part of iDRAC OEM extension
# Attributes are supported only on iDRAC9 # Attributes are supported only on iDRAC9
try: try:
for members in data[u'Links'][u'Oem'][u'Dell'][u'DellAttributes']: for members in data['Links']['Oem']['Dell']['DellAttributes']:
attributes_uri = members[u'@odata.id'] attributes_uri = members['@odata.id']
response = self.get_request(self.root_uri + attributes_uri) response = self.get_request(self.root_uri + attributes_uri)
if response['ret'] is False: if response['ret'] is False:

View file

@ -181,7 +181,7 @@ def parse_duration_literal(value, extended=False):
lookup = (EXTENDED_DURATION_REGEX if extended else DURATION_REGEX).findall(value) lookup = (EXTENDED_DURATION_REGEX if extended else DURATION_REGEX).findall(value)
for duration_literal in lookup: for duration_literal in lookup:
filtered_literal = list(filter(None, duration_literal)) filtered_literal = [_f for _f in duration_literal if _f]
duration_val = float(filtered_literal[0]) duration_val = float(filtered_literal[0])
duration += duration_val * DURATION_UNIT_NANOSECS[filtered_literal[1]] duration += duration_val * DURATION_UNIT_NANOSECS[filtered_literal[1]]

View file

@ -342,30 +342,30 @@ def do_ini(module, filename, section=None, section_has_values=None, option=None,
ini_lines = [to_text(line) for line in ini_file.readlines()] ini_lines = [to_text(line) for line in ini_file.readlines()]
if module._diff: if module._diff:
diff['before'] = u''.join(ini_lines) diff['before'] = ''.join(ini_lines)
changed = False changed = False
# ini file could be empty # ini file could be empty
if not ini_lines: if not ini_lines:
ini_lines.append(u'\n') ini_lines.append('\n')
# last line of file may not contain a trailing newline # last line of file may not contain a trailing newline
if ini_lines[-1] == u"" or ini_lines[-1][-1] != u'\n': if ini_lines[-1] == "" or ini_lines[-1][-1] != '\n':
ini_lines[-1] += u'\n' ini_lines[-1] += '\n'
changed = True changed = True
# append fake section lines to simplify the logic # append fake section lines to simplify the logic
# At top: # At top:
# Fake random section to do not match any other in the file # Fake random section to do not match any other in the file
# Using commit hash as fake section name # Using commit hash as fake section name
fake_section_name = u"ad01e11446efb704fcdbdb21f2c43757423d91c5" fake_section_name = "ad01e11446efb704fcdbdb21f2c43757423d91c5"
# Insert it at the beginning # Insert it at the beginning
ini_lines.insert(0, u'[%s]' % fake_section_name) ini_lines.insert(0, '[%s]' % fake_section_name)
# At bottom: # At bottom:
ini_lines.append(u'[') ini_lines.append('[')
# If no section is defined, fake section is used # If no section is defined, fake section is used
if not section: if not section:
@ -375,9 +375,9 @@ def do_ini(module, filename, section=None, section_has_values=None, option=None,
section_start = section_end = 0 section_start = section_end = 0
msg = 'OK' msg = 'OK'
if no_extra_spaces: if no_extra_spaces:
assignment_format = u'%s=%s\n' assignment_format = '%s=%s\n'
else: else:
assignment_format = u'%s = %s\n' assignment_format = '%s = %s\n'
option_no_value_present = False option_no_value_present = False
@ -390,7 +390,7 @@ def do_ini(module, filename, section=None, section_has_values=None, option=None,
for index, line in enumerate(ini_lines): for index, line in enumerate(ini_lines):
# end of section: # end of section:
if within_section and line.startswith(u'['): if within_section and line.startswith('['):
if check_section_has_values( if check_section_has_values(
section_has_values, ini_lines[section_start:index] section_has_values, ini_lines[section_start:index]
): ):
@ -434,7 +434,7 @@ def do_ini(module, filename, section=None, section_has_values=None, option=None,
matched_value = match.group(8) matched_value = match.group(8)
if not matched_value and allow_no_value: if not matched_value and allow_no_value:
# replace existing option with no value line(s) # replace existing option with no value line(s)
newline = u'%s\n' % option newline = '%s\n' % option
option_no_value_present = True option_no_value_present = True
else: else:
# replace existing option=value line(s) # replace existing option=value line(s)
@ -443,7 +443,7 @@ def do_ini(module, filename, section=None, section_has_values=None, option=None,
values.remove(matched_value) values.remove(matched_value)
elif not values and allow_no_value: elif not values and allow_no_value:
# replace existing option with no value line(s) # replace existing option with no value line(s)
newline = u'%s\n' % option newline = '%s\n' % option
(changed, msg) = update_section_line(option, changed, section_lines, index, changed_lines, ignore_spaces, newline, msg) (changed, msg) = update_section_line(option, changed, section_lines, index, changed_lines, ignore_spaces, newline, msg)
option_no_value_present = True option_no_value_present = True
break break
@ -482,12 +482,12 @@ def do_ini(module, filename, section=None, section_has_values=None, option=None,
changed = True changed = True
elif element is None and allow_no_value: elif element is None and allow_no_value:
# insert option with no value line # insert option with no value line
section_lines.insert(index, u'%s\n' % option) section_lines.insert(index, '%s\n' % option)
msg = 'option added' msg = 'option added'
changed = True changed = True
elif option and not values and allow_no_value and not option_no_value_present: elif option and not values and allow_no_value and not option_no_value_present:
# insert option with no value line(s) # insert option with no value line(s)
section_lines.insert(index, u'%s\n' % option) section_lines.insert(index, '%s\n' % option)
msg = 'option added' msg = 'option added'
changed = True changed = True
break break
@ -523,7 +523,7 @@ def do_ini(module, filename, section=None, section_has_values=None, option=None,
del ini_lines[-1:] del ini_lines[-1:]
if not within_section and state == 'present': if not within_section and state == 'present':
ini_lines.append(u'[%s]\n' % section) ini_lines.append('[%s]\n' % section)
msg = 'section and option added' msg = 'section and option added'
if section_has_values: if section_has_values:
for condition in section_has_values: for condition in section_has_values:
@ -532,7 +532,7 @@ def do_ini(module, filename, section=None, section_has_values=None, option=None,
for value in condition['values']: for value in condition['values']:
ini_lines.append(assignment_format % (condition['option'], value)) ini_lines.append(assignment_format % (condition['option'], value))
elif allow_no_value: elif allow_no_value:
ini_lines.append(u'%s\n' % condition['option']) ini_lines.append('%s\n' % condition['option'])
elif not exclusive: elif not exclusive:
for value in condition['values']: for value in condition['values']:
if value not in values: if value not in values:
@ -541,13 +541,13 @@ def do_ini(module, filename, section=None, section_has_values=None, option=None,
for value in values: for value in values:
ini_lines.append(assignment_format % (option, value)) ini_lines.append(assignment_format % (option, value))
elif option and not values and allow_no_value: elif option and not values and allow_no_value:
ini_lines.append(u'%s\n' % option) ini_lines.append('%s\n' % option)
else: else:
msg = 'only section added' msg = 'only section added'
changed = True changed = True
if module._diff: if module._diff:
diff['after'] = u''.join(ini_lines) diff['after'] = ''.join(ini_lines)
backup_file = None backup_file = None
if changed and not module.check_mode: if changed and not module.check_mode:

View file

@ -303,7 +303,7 @@ def set_interface_option(module, lines, iface, option, raw_value, state, address
changed, lines = addOptionAfterLine(option, value, iface, lines, last_line_dict, iface_options, address_family) changed, lines = addOptionAfterLine(option, value, iface, lines, last_line_dict, iface_options, address_family)
else: else:
if option in ["pre-up", "up", "down", "post-up"]: if option in ["pre-up", "up", "down", "post-up"]:
if len(list(filter(lambda i: i['value'] == value, target_options))) < 1: if len([i for i in target_options if i['value'] == value]) < 1:
changed, lines = addOptionAfterLine(option, value, iface, lines, target_options[-1], iface_options, address_family) changed, lines = addOptionAfterLine(option, value, iface, lines, target_options[-1], iface_options, address_family)
else: else:
# if more than one option found edit the last one # if more than one option found edit the last one

View file

@ -258,8 +258,7 @@ class Plist:
return self.__file return self.__file
class LaunchCtlTask(object): class LaunchCtlTask(metaclass=ABCMeta):
__metaclass__ = ABCMeta
WAITING_TIME = 5 # seconds WAITING_TIME = 5 # seconds
def __init__(self, module, service, plist): def __init__(self, module, service, plist):

View file

@ -149,7 +149,7 @@ def main():
# Handle multiple log files # Handle multiple log files
logs = p["path"].split(",") logs = p["path"].split(",")
logs = filter(None, logs) logs = [_f for _f in logs if _f]
if p["state"] in ["present", "followed"]: if p["state"] in ["present", "followed"]:
follow_log(module, le_path, logs, name=p['name'], logtype=p['logtype']) follow_log(module, le_path, logs, name=p['name'], logtype=p['logtype'])

View file

@ -174,7 +174,7 @@ def get_sshkey_selector(module):
def act_on_sshkeys(target_state, module, packet_conn): def act_on_sshkeys(target_state, module, packet_conn):
selector = get_sshkey_selector(module) selector = get_sshkey_selector(module)
existing_sshkeys = packet_conn.list_ssh_keys() existing_sshkeys = packet_conn.list_ssh_keys()
matching_sshkeys = filter(selector, existing_sshkeys) matching_sshkeys = list(filter(selector, existing_sshkeys))
changed = False changed = False
if target_state == 'present': if target_state == 'present':
if matching_sshkeys == []: if matching_sshkeys == []:

View file

@ -167,28 +167,28 @@ def manage_issue(taiga_host, project_name, issue_subject, issue_priority,
api.auth(username=username, password=password) api.auth(username=username, password=password)
user_id = api.me().id user_id = api.me().id
project_list = list(filter(lambda x: x.name == project_name, api.projects.list(member=user_id))) project_list = [x for x in api.projects.list(member=user_id) if x.name == project_name]
if len(project_list) != 1: if len(project_list) != 1:
return False, changed, "Unable to find project %s" % project_name, {} return False, changed, "Unable to find project %s" % project_name, {}
project = project_list[0] project = project_list[0]
project_id = project.id project_id = project.id
priority_list = list(filter(lambda x: x.name == issue_priority, api.priorities.list(project=project_id))) priority_list = [x for x in api.priorities.list(project=project_id) if x.name == issue_priority]
if len(priority_list) != 1: if len(priority_list) != 1:
return False, changed, "Unable to find issue priority %s for project %s" % (issue_priority, project_name), {} return False, changed, "Unable to find issue priority %s for project %s" % (issue_priority, project_name), {}
priority_id = priority_list[0].id priority_id = priority_list[0].id
status_list = list(filter(lambda x: x.name == issue_status, api.issue_statuses.list(project=project_id))) status_list = [x for x in api.issue_statuses.list(project=project_id) if x.name == issue_status]
if len(status_list) != 1: if len(status_list) != 1:
return False, changed, "Unable to find issue status %s for project %s" % (issue_status, project_name), {} return False, changed, "Unable to find issue status %s for project %s" % (issue_status, project_name), {}
status_id = status_list[0].id status_id = status_list[0].id
type_list = list(filter(lambda x: x.name == issue_type, project.list_issue_types())) type_list = [x for x in project.list_issue_types() if x.name == issue_type]
if len(type_list) != 1: if len(type_list) != 1:
return False, changed, "Unable to find issue type %s for project %s" % (issue_type, project_name), {} return False, changed, "Unable to find issue type %s for project %s" % (issue_type, project_name), {}
type_id = type_list[0].id type_id = type_list[0].id
severity_list = list(filter(lambda x: x.name == issue_severity, project.list_severities())) severity_list = [x for x in project.list_severities() if x.name == issue_severity]
if len(severity_list) != 1: if len(severity_list) != 1:
return False, changed, "Unable to find severity %s for project %s" % (issue_severity, project_name), {} return False, changed, "Unable to find severity %s for project %s" % (issue_severity, project_name), {}
severity_id = severity_list[0].id severity_id = severity_list[0].id
@ -205,7 +205,7 @@ def manage_issue(taiga_host, project_name, issue_subject, issue_priority,
} }
# An issue is identified by the project_name, the issue_subject and the issue_type # An issue is identified by the project_name, the issue_subject and the issue_type
matching_issue_list = list(filter(lambda x: x.subject == issue_subject and x.type == type_id, project.list_issues())) matching_issue_list = [x for x in project.list_issues() if x.subject == issue_subject and x.type == type_id]
matching_issue_list_len = len(matching_issue_list) matching_issue_list_len = len(matching_issue_list)
if matching_issue_list_len == 0: if matching_issue_list_len == 0:

View file

@ -270,7 +270,7 @@ def inventory_vdos(module, vdocmd):
def list_running_vdos(module, vdocmd): def list_running_vdos(module, vdocmd):
rc, vdolistout, err = module.run_command([vdocmd, "list"]) rc, vdolistout, err = module.run_command([vdocmd, "list"])
runningvdolist = filter(None, vdolistout.split('\n')) runningvdolist = [_f for _f in vdolistout.split('\n') if _f]
return runningvdolist return runningvdolist

View file

@ -194,7 +194,7 @@ def main():
assigned_roles = [] assigned_roles = []
if module.params['assigned_roles']: if module.params['assigned_roles']:
assigned_roles = module.params['assigned_roles'].split(',') assigned_roles = module.params['assigned_roles'].split(',')
assigned_roles = filter(None, assigned_roles) assigned_roles = [_f for _f in assigned_roles if _f]
state = module.params['state'] state = module.params['state']
db = '' db = ''
if module.params['db']: if module.params['db']:

View file

@ -256,11 +256,11 @@ def main():
usage_roles = [] usage_roles = []
if module.params['usage_roles']: if module.params['usage_roles']:
usage_roles = module.params['usage_roles'].split(',') usage_roles = module.params['usage_roles'].split(',')
usage_roles = filter(None, usage_roles) usage_roles = [_f for _f in usage_roles if _f]
create_roles = [] create_roles = []
if module.params['create_roles']: if module.params['create_roles']:
create_roles = module.params['create_roles'].split(',') create_roles = module.params['create_roles'].split(',')
create_roles = filter(None, create_roles) create_roles = [_f for _f in create_roles if _f]
owner = module.params['owner'] owner = module.params['owner']
state = module.params['state'] state = module.params['state']
db = '' db = ''

View file

@ -320,7 +320,7 @@ def main():
roles = [] roles = []
if module.params['roles']: if module.params['roles']:
roles = module.params['roles'].split(',') roles = module.params['roles'].split(',')
roles = filter(None, roles) roles = [_f for _f in roles if _f]
state = module.params['state'] state = module.params['state']
if state == 'locked': if state == 'locked':
locked = True locked = True

View file

@ -84,7 +84,7 @@ def get_eg(module, array):
name = module.params['name'] name = module.params['name']
try: try:
egs = array.list_egs() egs = array.list_egs()
eg = filter(lambda eg: eg['name'] == name, egs) eg = [eg for eg in egs if eg['name'] == name]
if len(eg) == 1: if len(eg) == 1:
return eg[0] return eg[0]
else: else:
@ -98,7 +98,7 @@ def get_vg_id(module, array):
name = module.params['vg'] name = module.params['vg']
try: try:
vgs = array.list_vgs() vgs = array.list_vgs()
vg = filter(lambda vg: vg['name'] == name, vgs) vg = [vg for vg in vgs if vg['name'] == name]
if len(vg) == 1: if len(vg) == 1:
return vg[0]['id'] return vg[0]['id']
else: else:
@ -112,7 +112,7 @@ def get_ig_id(module, array):
name = module.params['ig'] name = module.params['ig']
try: try:
igs = array.list_igs() igs = array.list_igs()
ig = filter(lambda ig: ig['name'] == name, igs) ig = [ig for ig in igs if ig['name'] == name]
if len(ig) == 1: if len(ig) == 1:
return ig[0]['id'] return ig[0]['id']
else: else:
@ -126,7 +126,7 @@ def get_pg_id(module, array):
name = module.params['pg'] name = module.params['pg']
try: try:
pgs = array.list_pgs() pgs = array.list_pgs()
pg = filter(lambda pg: pg['name'] == name, pgs) pg = [pg for pg in pgs if pg['name'] == name]
if len(pg) == 1: if len(pg) == 1:
return pg[0]['id'] return pg[0]['id']
else: else:

View file

@ -81,7 +81,7 @@ def get_volume(module, array):
name = module.params['name'] name = module.params['name']
try: try:
vols = array.list_volumes() vols = array.list_volumes()
vol = filter(lambda v: v['name'] == name, vols) vol = [v for v in vols if v['name'] == name]
if len(vol) == 1: if len(vol) == 1:
return vol[0] return vol[0]
else: else:

View file

@ -348,8 +348,8 @@ class XCCRedfishUtils(RedfishUtils):
return response return response
data = response['data'] data = response['data']
virt_media_list = [] virt_media_list = []
for member in data[u'Members']: for member in data['Members']:
virt_media_list.append(member[u'@odata.id']) virt_media_list.append(member['@odata.id'])
resources, headers = self._read_virt_media_resources(virt_media_list) resources, headers = self._read_virt_media_resources(virt_media_list)
# find the VirtualMedia resource to eject # find the VirtualMedia resource to eject
@ -422,8 +422,8 @@ class XCCRedfishUtils(RedfishUtils):
return response return response
data = response['data'] data = response['data']
virt_media_list = [] virt_media_list = []
for member in data[u'Members']: for member in data['Members']:
virt_media_list.append(member[u'@odata.id']) virt_media_list.append(member['@odata.id'])
resources, headers = self._read_virt_media_resources(virt_media_list) resources, headers = self._read_virt_media_resources(virt_media_list)
# eject all inserted media one by one # eject all inserted media one by one
@ -477,8 +477,8 @@ class XCCRedfishUtils(RedfishUtils):
return response return response
data = response['data'] data = response['data']
virt_media_list = [] virt_media_list = []
for member in data[u'Members']: for member in data['Members']:
virt_media_list.append(member[u'@odata.id']) virt_media_list.append(member['@odata.id'])
resources, headers = self._read_virt_media_resources(virt_media_list) resources, headers = self._read_virt_media_resources(virt_media_list)
# see if image already inserted; if so, nothing to do # see if image already inserted; if so, nothing to do

View file

@ -641,7 +641,7 @@ def main():
update_cache = module.params['update_cache'] update_cache = module.params['update_cache']
# remove empty strings from package list # remove empty strings from package list
name = list(filter(None, name)) name = [_f for _f in name if _f]
# Refresh repositories # Refresh repositories
if update_cache and not module.check_mode: if update_cache and not module.check_mode: