fix ruff issues
Some checks failed
ci/woodpecker/pr/sanity-test/3 Pipeline failed
ci/woodpecker/pr/sanity-test/2 Pipeline failed
ci/woodpecker/pr/unit-test/1 Pipeline was successful
ci/woodpecker/pr/sanity-test/1 Pipeline failed
ci/woodpecker/pr/unit-test/2 Pipeline was successful
ci/woodpecker/pr/unit-test/3 Pipeline was successful
ci/woodpecker/pr/unit-test/4 Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/build-package unknown status
ci/woodpecker/pr/docs unknown status
Some checks failed
ci/woodpecker/pr/sanity-test/3 Pipeline failed
ci/woodpecker/pr/sanity-test/2 Pipeline failed
ci/woodpecker/pr/unit-test/1 Pipeline was successful
ci/woodpecker/pr/sanity-test/1 Pipeline failed
ci/woodpecker/pr/unit-test/2 Pipeline was successful
ci/woodpecker/pr/unit-test/3 Pipeline was successful
ci/woodpecker/pr/unit-test/4 Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/build-package unknown status
ci/woodpecker/pr/docs unknown status
This commit is contained in:
parent
c3c0298617
commit
36394d1873
@ -299,13 +299,13 @@ def _compare_state(desired_state, current_state, ignore=None):
|
|||||||
|
|
||||||
if ignore is None:
|
if ignore is None:
|
||||||
ignore = []
|
ignore = []
|
||||||
if type(desired_state) is list:
|
if isinstance(desired_state, list):
|
||||||
if (type(current_state) != list) or (len(desired_state) != len(current_state)):
|
if not isinstance(current_state, list) or (len(desired_state) != len(current_state)):
|
||||||
return False
|
return False
|
||||||
return set(desired_state) == set(current_state)
|
return set(desired_state) == set(current_state)
|
||||||
|
|
||||||
if type(desired_state) is dict:
|
if isinstance(desired_state, dict):
|
||||||
if type(current_state) != dict:
|
if not isinstance(current_state, dict):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# iterate over dictionary keys
|
# iterate over dictionary keys
|
||||||
@ -341,7 +341,7 @@ def _convert_to_seconds(original_value):
|
|||||||
ray = value.split("s")
|
ray = value.split("s")
|
||||||
seconds += int(ray.pop(0))
|
seconds += int(ray.pop(0))
|
||||||
return seconds
|
return seconds
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001,S110
|
||||||
pass
|
pass
|
||||||
return original_value
|
return original_value
|
||||||
|
|
||||||
@ -376,9 +376,9 @@ def get_keys_updated(desired_state, current_state, ignore=None):
|
|||||||
continue
|
continue
|
||||||
new_value = desired_state[key]
|
new_value = desired_state[key]
|
||||||
old_value = current_state[key]
|
old_value = current_state[key]
|
||||||
if "ttl" in key and (_convert_to_seconds(old_value) != _convert_to_seconds(new_value)):
|
if (
|
||||||
differences.append(key)
|
"ttl" in key and (_convert_to_seconds(old_value) != _convert_to_seconds(new_value))
|
||||||
elif not _compare_state(new_value, old_value):
|
) or not _compare_state(new_value, old_value):
|
||||||
differences.append(key)
|
differences.append(key)
|
||||||
return differences
|
return differences
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ class Pkcs(object): # noqa
|
|||||||
def load_privatekey(self, path, passphrase=None):
|
def load_privatekey(self, path, passphrase=None):
|
||||||
"""Load the specified OpenSSL private key."""
|
"""Load the specified OpenSSL private key."""
|
||||||
try:
|
try:
|
||||||
privatekey = (
|
return (
|
||||||
crypto.load_privatekey(
|
crypto.load_privatekey(
|
||||||
crypto.FILETYPE_PEM,
|
crypto.FILETYPE_PEM,
|
||||||
open(path, "rb").read(), # noqa
|
open(path, "rb").read(), # noqa
|
||||||
@ -212,8 +212,6 @@ class Pkcs(object): # noqa
|
|||||||
open(path, "rb").read(), # noqa
|
open(path, "rb").read(), # noqa
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return privatekey
|
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
raise PkcsError(exc) from exc
|
raise PkcsError(exc) from exc
|
||||||
|
|
||||||
@ -221,8 +219,7 @@ class Pkcs(object): # noqa
|
|||||||
"""Load the specified certificate."""
|
"""Load the specified certificate."""
|
||||||
try:
|
try:
|
||||||
cert_content = open(path, "rb").read() # noqa
|
cert_content = open(path, "rb").read() # noqa
|
||||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_content)
|
return crypto.load_certificate(crypto.FILETYPE_PEM, cert_content)
|
||||||
return cert
|
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
raise PkcsError(exc) from exc
|
raise PkcsError(exc) from exc
|
||||||
|
|
||||||
|
@ -842,8 +842,7 @@ from ansible.module_utils.basic import AnsibleModule, env_fallback
|
|||||||
|
|
||||||
def get_nextvmid(module, proxmox):
|
def get_nextvmid(module, proxmox):
|
||||||
try:
|
try:
|
||||||
vmid = proxmox.cluster.nextid.get()
|
return proxmox.cluster.nextid.get()
|
||||||
return vmid
|
|
||||||
except Exception as e: # noqa
|
except Exception as e: # noqa
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg=f"Unable to get next vmid. Failed with exception: {to_native(e)}",
|
msg=f"Unable to get next vmid. Failed with exception: {to_native(e)}",
|
||||||
@ -1331,7 +1330,7 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Ensure source VM name exists when cloning
|
# Ensure source VM name exists when cloning
|
||||||
if -1 == vmid:
|
if vmid == -1:
|
||||||
module.fail_json(msg=f"VM with name = {clone} does not exist in cluster")
|
module.fail_json(msg=f"VM with name = {clone} does not exist in cluster")
|
||||||
|
|
||||||
# Ensure source VM id exists when cloning
|
# Ensure source VM id exists when cloning
|
||||||
@ -1356,7 +1355,7 @@ def main():
|
|||||||
)
|
)
|
||||||
except Exception as e: # noqa
|
except Exception as e: # noqa
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
vmid=vmid, msg=f"Unable to delete settings on VM {name} with vmid {vmid}: {str(e)}"
|
vmid=vmid, msg=f"Unable to delete settings on VM {name} with vmid {vmid}: {e!s}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if revert is not None:
|
if revert is not None:
|
||||||
@ -1369,7 +1368,7 @@ def main():
|
|||||||
module.fail_json(
|
module.fail_json(
|
||||||
vmid=vmid,
|
vmid=vmid,
|
||||||
msg=f"Unable to revert settings on VM {name} with vmid {vmid}:"
|
msg=f"Unable to revert settings on VM {name} with vmid {vmid}:"
|
||||||
f"Maybe is not a pending task...{str(e)}",
|
f"Maybe is not a pending task...{e!s}",
|
||||||
)
|
)
|
||||||
|
|
||||||
if state == "present":
|
if state == "present":
|
||||||
@ -1504,7 +1503,7 @@ def main():
|
|||||||
elif state == "started":
|
elif state == "started":
|
||||||
status = {}
|
status = {}
|
||||||
try:
|
try:
|
||||||
if -1 == vmid:
|
if vmid == -1:
|
||||||
module.fail_json(msg=f"VM with name = {name} does not exist in cluster")
|
module.fail_json(msg=f"VM with name = {name} does not exist in cluster")
|
||||||
vm = get_vm(proxmox, vmid)
|
vm = get_vm(proxmox, vmid)
|
||||||
if not vm:
|
if not vm:
|
||||||
@ -1525,7 +1524,7 @@ def main():
|
|||||||
elif state == "stopped":
|
elif state == "stopped":
|
||||||
status = {}
|
status = {}
|
||||||
try:
|
try:
|
||||||
if -1 == vmid:
|
if vmid == -1:
|
||||||
module.fail_json(msg=f"VM with name = {name} does not exist in cluster")
|
module.fail_json(msg=f"VM with name = {name} does not exist in cluster")
|
||||||
|
|
||||||
vm = get_vm(proxmox, vmid)
|
vm = get_vm(proxmox, vmid)
|
||||||
@ -1550,7 +1549,7 @@ def main():
|
|||||||
elif state == "restarted":
|
elif state == "restarted":
|
||||||
status = {}
|
status = {}
|
||||||
try:
|
try:
|
||||||
if -1 == vmid:
|
if vmid == -1:
|
||||||
module.fail_json(msg=f"VM with name = {name} does not exist in cluster")
|
module.fail_json(msg=f"VM with name = {name} does not exist in cluster")
|
||||||
|
|
||||||
vm = get_vm(proxmox, vmid)
|
vm = get_vm(proxmox, vmid)
|
||||||
@ -1602,7 +1601,7 @@ def main():
|
|||||||
|
|
||||||
elif state == "current":
|
elif state == "current":
|
||||||
status = {}
|
status = {}
|
||||||
if -1 == vmid:
|
if vmid == -1:
|
||||||
module.fail_json(msg=f"VM with name = {name} does not exist in cluster")
|
module.fail_json(msg=f"VM with name = {name} does not exist in cluster")
|
||||||
vm = get_vm(proxmox, vmid)
|
vm = get_vm(proxmox, vmid)
|
||||||
if not vm:
|
if not vm:
|
||||||
|
Loading…
Reference in New Issue
Block a user