use dict comprehension in plugins, part 2 (#8822)

* use dict comprehension in plugins

* add changelog frag
This commit is contained in:
Alexei Znamensky 2024-09-06 07:47:28 +12:00 committed by GitHub
parent ecc048bc12
commit 7e978c77b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 76 additions and 68 deletions

View file

@ -185,8 +185,7 @@ def get_token(module_params):
'password': auth_password,
}
# Remove empty items, for instance missing client_secret
payload = dict(
(k, v) for k, v in temp_payload.items() if v is not None)
payload = {k: v for k, v in temp_payload.items() if v is not None}
try:
r = json.loads(to_native(open_url(auth_url, method='POST',
validate_certs=validate_certs, http_agent=http_agent, timeout=connection_timeout,

View file

@ -45,11 +45,11 @@ def module_fails_on_exception(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
def fix_key(k):
return k if k not in conflict_list else "_" + k
def fix_var_conflicts(output):
result = dict([
(k if k not in conflict_list else "_" + k, v)
for k, v in output.items()
])
result = {fix_key(k): v for k, v in output.items()}
return result
try:

View file

@ -613,9 +613,11 @@ class RedfishUtils(object):
ai = dict((p['Name'], p)
for p in params if 'Name' in p)
if not ai:
ai = dict((k[:-24],
{'AllowableValues': v}) for k, v in action.items()
if k.endswith('@Redfish.AllowableValues'))
ai = {
k[:-24]: {'AllowableValues': v}
for k, v in action.items()
if k.endswith('@Redfish.AllowableValues')
}
return ai
def _get_allowable_values(self, action, name, default_values=None):
@ -2242,7 +2244,7 @@ class RedfishUtils(object):
continue
# If already set to requested value, remove it from PATCH payload
if data[u'Attributes'][attr_name] == attributes[attr_name]:
if data[u'Attributes'][attr_name] == attr_value:
del attrs_to_patch[attr_name]
warning = ""
@ -2780,9 +2782,11 @@ class RedfishUtils(object):
def virtual_media_insert_via_patch(self, options, param_map, uri, data, image_only=False):
# get AllowableValues
ai = dict((k[:-24],
{'AllowableValues': v}) for k, v in data.items()
if k.endswith('@Redfish.AllowableValues'))
ai = {
k[:-24]: {'AllowableValues': v}
for k, v in data.items()
if k.endswith('@Redfish.AllowableValues')
}
# construct payload
payload = self._insert_virt_media_payload(options, param_map, data, ai)
if 'Inserted' not in payload and not image_only:

View file

@ -51,11 +51,11 @@ def scaleway_waitable_resource_argument_spec():
def payload_from_object(scw_object):
return dict(
(k, v)
return {
k: v
for k, v in scw_object.items()
if k != 'id' and v is not None
)
}
class ScalewayException(Exception):
@ -117,10 +117,7 @@ class SecretVariables(object):
@staticmethod
def list_to_dict(source_list, hashed=False):
key_value = 'hashed_value' if hashed else 'value'
return dict(
(var['key'], var[key_value])
for var in source_list
)
return {var['key']: var[key_value] for var in source_list}
@classmethod
def decode(cls, secrets_list, values_list):