Skip to content

Commit

Permalink
renamed the function verify_checksum to fetch_and_verify for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewb12505 committed Jan 23, 2025
1 parent 4f3c2b5 commit f1678c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
minor_changes:
- proxmox_template - Add support for checksum validation with new options ``checksum_algoritm``, ``checksum`` and ``verify_checksum`` (https://github.com/ansible-collections/community.general/pull/9601)
- proxmox_template - Add support for checksum validation with new options ``checksum_algorithm``, ``checksum`` and ``verify_checksum`` (https://github.com/ansible-collections/community.general/issues/9553, https://github.com/ansible-collections/community.general/pull/9601).
5 changes: 2 additions & 3 deletions plugins/module_utils/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ def api_task_ok(self, node, taskid):
self.module.fail_json(msg='Unable to retrieve API task ID from node %s: %s' % (node, e))

def api_task_failed(self, node, taskid):
'''
Explicitly check if the task stops but exits with a failed status
'''
""" Explicitly check if the task stops but exits with a failed status
"""
try:
status = self.proxmox_api.nodes(node).tasks(taskid).status.get()
return status['status'] == 'stopped' and status['exitstatus'] != 'OK'
Expand Down
10 changes: 5 additions & 5 deletions plugins/modules/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@
version_added: 2.3.0
state:
description:
- Indicate desired state of the instance.
- V(template) was added in community.general 8.1.0.
- Indicate desired state of the instance.
- V(template) was added in community.general 8.1.0.
type: str
choices: ['present', 'started', 'absent', 'stopped', 'restarted', 'template']
default: present
Expand Down Expand Up @@ -494,8 +494,8 @@
hostname: example.org
ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
features:
- nesting=1
- mount=cifs,nfs
- nesting=1
- mount=cifs,nfs
- name: >
Create a linked clone of the template container with id 100. The newly created container with be a
Expand Down Expand Up @@ -820,7 +820,7 @@ def build_volume(
if new_value not in current_values:
update_config = True
break
# if it's not a list (or string) just compare the current value
# if it is not a list (or string) just compare the current value
else:
# some types don't match with the API, so forcing to string for comparison
if str(value) != str(current_config[arg]):
Expand Down
9 changes: 6 additions & 3 deletions plugins/modules/proxmox_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ def delete_template(self, node, storage, content_type, template, timeout):
time.sleep(1)
return False

def verify_checksum(self, node, storage, url, content_type, timeout, checksum, checksum_algorithm):
def fetch_and_verify(self, node, storage, url, content_type, timeout, checksum, checksum_algorithm):
""" Fetch a template from a web url, then verify it using a checksum.
"""
data = {
'url': url,
'content': content_type,
Expand Down Expand Up @@ -306,7 +308,8 @@ def main():
argument_spec=module_args,
required_together=[('api_token_id', 'api_token_secret')],
required_one_of=[('api_password', 'api_token_id')],
required_if=[('state', 'absent', ['template']), ('verify_checksum', True, ['checksum', 'checksum_algorithm'])],
required_if=[('state', 'absent', ['template']),
('verify_checksum', True, ['checksum', 'checksum_algorithm'])],
mutually_exclusive=[("src", "url")],
)

Expand Down Expand Up @@ -358,7 +361,7 @@ def main():
module.fail_json(changed=False, msg='failed to delete template with volid=%s:%s/%s' % (storage, content_type, template))

if verify_checksum:
if proxmox.verify_checksum(node, storage, url, content_type, timeout, checksum, checksum_algorithm):
if proxmox.fetch_and_verify(node, storage, url, content_type, timeout, checksum, checksum_algorithm):
module.exit_json(changed=True, msg="Checksum verified, template with volid=%s:%s/%s uploaded" % (storage, content_type, template))
if proxmox.fetch_template(node, storage, content_type, url, timeout):
module.exit_json(changed=True, msg='template with volid=%s:%s/%s uploaded' % (storage, content_type, template))
Expand Down

0 comments on commit f1678c9

Please sign in to comment.