[feat] proxmox_snap: snapshot containers with configured mountpoints (#5274) (#5317)

* module_utils.proxmox: new `api_task_ok` helper + integrated with existing modules

* proxmox_snap: add `unbind` param to snapshot containers with mountpoints

* [fix] errors reported by 'test sanity pep8'
at
https://github.com/ansible-collections/community.general/pull/5274#issuecomment-1242932079

* module_utils.proxmox.api_task_ok: small improvement

* proxmox_snap.unbind: version_added, formatting errors, changelog fragment

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

* proxmox_snap.unbind: update version_added tag

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 25e3031c2f)

Co-authored-by: nxet <nxet821@protonmail.com>
This commit is contained in:
patchback[bot] 2022-09-28 23:20:21 +02:00 committed by GitHub
parent d25b6e7681
commit 869e1a1eab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 117 additions and 22 deletions

View file

@ -482,8 +482,7 @@ class ProxmoxLxcAnsible(ProxmoxAnsible):
taskid = getattr(proxmox_node, VZ_TYPE).create(vmid=vmid, storage=storage, memory=memory, swap=swap, **kwargs)
while timeout:
if (proxmox_node.tasks(taskid).status.get()['status'] == 'stopped' and
proxmox_node.tasks(taskid).status.get()['exitstatus'] == 'OK'):
if self.api_task_ok(node, taskid):
return True
timeout -= 1
if timeout == 0:
@ -496,8 +495,7 @@ class ProxmoxLxcAnsible(ProxmoxAnsible):
def start_instance(self, vm, vmid, timeout):
taskid = getattr(self.proxmox_api.nodes(vm['node']), VZ_TYPE)(vmid).status.start.post()
while timeout:
if (self.proxmox_api.nodes(vm['node']).tasks(taskid).status.get()['status'] == 'stopped' and
self.proxmox_api.nodes(vm['node']).tasks(taskid).status.get()['exitstatus'] == 'OK'):
if self.api_task_ok(vm['node'], taskid):
return True
timeout -= 1
if timeout == 0:
@ -513,8 +511,7 @@ class ProxmoxLxcAnsible(ProxmoxAnsible):
else:
taskid = getattr(self.proxmox_api.nodes(vm['node']), VZ_TYPE)(vmid).status.shutdown.post()
while timeout:
if (self.proxmox_api.nodes(vm['node']).tasks(taskid).status.get()['status'] == 'stopped' and
self.proxmox_api.nodes(vm['node']).tasks(taskid).status.get()['exitstatus'] == 'OK'):
if self.api_task_ok(vm['node'], taskid):
return True
timeout -= 1
if timeout == 0:
@ -527,8 +524,7 @@ class ProxmoxLxcAnsible(ProxmoxAnsible):
def umount_instance(self, vm, vmid, timeout):
taskid = getattr(self.proxmox_api.nodes(vm['node']), VZ_TYPE)(vmid).status.umount.post()
while timeout:
if (self.proxmox_api.nodes(vm['node']).tasks(taskid).status.get()['status'] == 'stopped' and
self.proxmox_api.nodes(vm['node']).tasks(taskid).status.get()['exitstatus'] == 'OK'):
if self.api_task_ok(vm['node'], taskid):
return True
timeout -= 1
if timeout == 0:
@ -775,8 +771,7 @@ def main():
taskid = getattr(proxmox.proxmox_api.nodes(vm['node']), VZ_TYPE).delete(vmid, **delete_params)
while timeout:
task_status = proxmox.proxmox_api.nodes(vm['node']).tasks(taskid).status.get()
if (task_status['status'] == 'stopped' and task_status['exitstatus'] == 'OK'):
if proxmox.api_task_ok(vm['node'], taskid):
module.exit_json(changed=True, msg="VM %s removed" % vmid)
timeout -= 1
if timeout == 0: