mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-23 20:29:08 +00:00
Address issues reported by ruff check (#11043)
* Resolve E713 and E714 (not in/is tests). * Address UP018 (unnecessary str call). * UP045 requires Python 3.10+. * Address UP007 (X | Y for type annotations). * Address UP035 (import Callable from collections.abc). * Address UP006 (t.Dict -> dict). * Address UP009 (UTF-8 encoding comment). * Address UP034 (extraneous parantheses). * Address SIM910 (dict.get() with None default). * Address F401 (unused import). * Address UP020 (use builtin open). * Address B009 and B010 (getattr/setattr with constant name). * Address SIM300 (Yoda conditions). * UP029 isn't in use anyway. * Address FLY002 (static join). * Address B034 (re.sub positional args). * Address B020 (loop variable overrides input). * Address B017 (assert raise Exception). * Address SIM211 (if expression with false/true). * Address SIM113 (enumerate for loop). * Address UP036 (sys.version_info checks). * Remove unnecessary UP039. * Address SIM201 (not ==). * Address SIM212 (if expr with twisted arms). * Add changelog fragment. * Reformat.
This commit is contained in:
parent
f5943201b9
commit
3478863ef0
77 changed files with 196 additions and 222 deletions
|
|
@ -764,11 +764,11 @@ def get_template(module, client, predicate):
|
|||
|
||||
|
||||
def get_template_by_name(module, client, template_name):
|
||||
return get_template(module, client, lambda template: (template.NAME == template_name))
|
||||
return get_template(module, client, lambda template: (template_name == template.NAME))
|
||||
|
||||
|
||||
def get_template_by_id(module, client, template_id):
|
||||
return get_template(module, client, lambda template: (template.ID == template_id))
|
||||
return get_template(module, client, lambda template: (template_id == template.ID))
|
||||
|
||||
|
||||
def get_template_id(module, client, requested_id, requested_name):
|
||||
|
|
@ -803,11 +803,11 @@ def get_datastore(module, client, predicate):
|
|||
|
||||
|
||||
def get_datastore_by_name(module, client, datastore_name):
|
||||
return get_datastore(module, client, lambda datastore: (datastore.NAME == datastore_name))
|
||||
return get_datastore(module, client, lambda datastore: (datastore_name == datastore.NAME))
|
||||
|
||||
|
||||
def get_datastore_by_id(module, client, datastore_id):
|
||||
return get_datastore(module, client, lambda datastore: (datastore.ID == datastore_id))
|
||||
return get_datastore(module, client, lambda datastore: (datastore_id == datastore.ID))
|
||||
|
||||
|
||||
def get_datastore_id(module, client, requested_id, requested_name):
|
||||
|
|
@ -887,7 +887,7 @@ def get_vm_info(client, vm):
|
|||
|
||||
# LCM_STATE is VM's sub-state that is relevant only when STATE is ACTIVE
|
||||
vm_lcm_state = None
|
||||
if vm.STATE == VM_STATES.index("ACTIVE"):
|
||||
if VM_STATES.index("ACTIVE") == vm.STATE:
|
||||
vm_lcm_state = LCM_STATES[vm.LCM_STATE]
|
||||
|
||||
vm_labels, vm_attributes = get_vm_labels_and_attributes_dict(client, vm.ID)
|
||||
|
|
@ -1141,7 +1141,7 @@ def get_all_vms_by_attributes(client, attributes_dict, labels_list):
|
|||
if with_hash and vm.NAME[len(base_name) :].isdigit():
|
||||
# If the name has indexed format and after base_name it has only digits it'll be matched
|
||||
vm_list.append(vm)
|
||||
elif not with_hash and vm.NAME == name:
|
||||
elif not with_hash and name == vm.NAME:
|
||||
# If the name is not indexed it has to be same
|
||||
vm_list.append(vm)
|
||||
pool = vm_list
|
||||
|
|
@ -1600,7 +1600,7 @@ def disk_save_as(module, client, vm, disk_saveas, wait_timeout):
|
|||
disk_id = disk_saveas.get("disk_id", 0)
|
||||
|
||||
if not module.check_mode:
|
||||
if vm.STATE != VM_STATES.index("POWEROFF"):
|
||||
if VM_STATES.index("POWEROFF") != vm.STATE:
|
||||
module.fail_json(msg="'disksaveas' option can be used only when the VM is in 'POWEROFF' state")
|
||||
try:
|
||||
client.vm.disksaveas(vm.ID, disk_id, image_name, "OS", -1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue