refactor dict from literal list (#10891)

* refactor dict from literal list

* add changelog frag
This commit is contained in:
Alexei Znamensky 2025-10-11 06:09:10 +13:00 committed by GitHub
commit 5f471b8e5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 17 additions and 14 deletions

View file

@ -0,0 +1,6 @@
minor_changes:
- dependent lookup plugin - refactor dict initialization, no impact to users (https://github.com/ansible-collections/community.general/pull/10891).
- scaleway module_utils - improve code readability, no impact to users (https://github.com/ansible-collections/community.general/pull/10891).
- pacemaker_cluster.py - refactor dict initialization, no impact to users (https://github.com/ansible-collections/community.general/pull/10891).
- pacemaker_resource.py - refactor dict initialization, no impact to users (https://github.com/ansible-collections/community.general/pull/10891).
- pacemaker_stonith.py - refactor dict initialization, no impact to users (https://github.com/ansible-collections/community.general/pull/10891).

View file

@ -180,7 +180,7 @@ class LookupModule(LookupBase):
if isinstance(values, Mapping):
for idx, val in sorted(values.items()):
current[key] = dict([('key', idx), ('value', val)])
current[key] = dict(key=idx, value=val)
self.__process(result, terms, index + 1, current, templar, variables)
elif isinstance(values, Sequence):
for elt in values:

View file

@ -109,10 +109,7 @@ class SecretVariables(object):
@staticmethod
def dict_to_list(source_dict):
return [
dict(key=var[0], value=var[1])
for var in source_dict.items()
]
return [dict(key=k, value=v) for k, v in source_dict.items()]
@staticmethod
def list_to_dict(source_list, hashed=False):

View file

@ -87,7 +87,7 @@ class PacemakerCluster(StateModuleHelper):
def __init_module__(self):
self.runner = pacemaker_runner(self.module)
self.vars.set('apply_all', True if not self.module.params['name'] else False)
get_args = dict([('cli_action', 'cluster'), ('state', 'status'), ('name', None), ('apply_all', self.vars.apply_all)])
get_args = dict(cli_action='cluster', state='status', name=None, apply_all=self.vars.apply_all)
if self.module.params['state'] == "maintenance":
get_args['cli_action'] = "property"
get_args['state'] = "config"
@ -121,9 +121,9 @@ class PacemakerCluster(StateModuleHelper):
def _get(self):
with self.runner('cli_action state name') as ctx:
result = ctx.run(cli_action=self.vars.get_args['cli_action'], state=self.vars.get_args['state'], name=self.vars.get_args['name'])
return dict([('rc', result[0]),
('out', result[1] if result[1] != "" else None),
('err', result[2])])
return dict(rc=result[0],
out=(result[1] if result[1] != "" else None),
err=result[2])
def state_cleanup(self):
with self.runner('cli_action state name', output_process=self._process_command_output(True, "Fail"), check_mode_skip=True) as ctx:

View file

@ -205,9 +205,9 @@ class PacemakerResource(StateModuleHelper):
def _get(self):
with self.runner('cli_action state name') as ctx:
result = ctx.run(cli_action="resource", state='status')
return dict([('rc', result[0]),
('out', result[1] if result[1] != "" else None),
('err', result[2])])
return dict(rc=result[0],
out=(result[1] if result[1] != "" else None),
err=result[2])
def fmt_as_stack_argument(self, value, arg):
if value is not None:

View file

@ -183,8 +183,8 @@ class PacemakerStonith(StateModuleHelper):
def fmt_stonith_operations(self):
modified_stonith_operations = []
for stonith_operation in self.vars.stonith_operations:
modified_stonith_operations.append(dict([("operation_action", stonith_operation.get('operation_action')),
("operation_option", stonith_operation.get('operation_options'))]))
modified_stonith_operations.append(dict(operation_action=stonith_operation.get('operation_action'),
operation_option=stonith_operation.get('operation_options')))
return modified_stonith_operations
def state_absent(self):