Skip to content

Commit 10f88ae

Browse files
Add source option for proxmox_tasks_info (#179)
1 parent 0425010 commit 10f88ae

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- proxmox_tasks_info - add source option to specify tasks to consider (https://github.com/ansible-collections/community.proxmox/pull/179)

plugins/modules/proxmox_tasks_info.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
- Return specific task.
2727
aliases: ['upid', 'name']
2828
type: str
29+
source:
30+
description:
31+
- Source of tasks to be considered.
32+
type: str
33+
choices: ['archive', 'active', 'all']
34+
default: archive
2935
extends_documentation_fragment:
3036
- community.proxmox.proxmox.actiongroup_proxmox
3137
- community.proxmox.proxmox.documentation
@@ -35,7 +41,7 @@
3541

3642

3743
EXAMPLES = r"""
38-
- name: List tasks on node01
44+
- name: List finished tasks on node01
3945
community.proxmox.proxmox_tasks_info:
4046
api_host: proxmoxhost
4147
api_user: root@pam
@@ -45,6 +51,17 @@
4551
node: node01
4652
register: result
4753
54+
- name: List active tasks on node02
55+
community.proxmox.proxmox_tasks_info:
56+
api_host: proxmoxhost
57+
api_user: root@pam
58+
api_password: '{{ password | default(omit) }}'
59+
api_token_id: '{{ token_id | default(omit) }}'
60+
api_token_secret: '{{ token_secret | default(omit) }}'
61+
node: node02
62+
source: active
63+
register: result
64+
4865
- name: Retrieve information about specific tasks on node01
4966
community.proxmox.proxmox_tasks_info:
5067
api_host: proxmoxhost
@@ -122,14 +139,14 @@
122139

123140

124141
class ProxmoxTaskInfoAnsible(ProxmoxAnsible):
125-
def get_task(self, upid, node):
126-
tasks = self.get_tasks(node)
142+
def get_task(self, upid, node, source):
143+
tasks = self.get_tasks(node, source)
127144
for task in tasks:
128145
if task.info['upid'] == upid:
129146
return [task]
130147

131-
def get_tasks(self, node):
132-
tasks = self.proxmox_api.nodes(node).tasks.get()
148+
def get_tasks(self, node, source):
149+
tasks = self.proxmox_api.nodes(node).tasks.get(source=source)
133150
return [ProxmoxTask(task) for task in tasks]
134151

135152

@@ -149,6 +166,7 @@ def proxmox_task_info_argument_spec():
149166
return dict(
150167
task=dict(type='str', aliases=['upid', 'name'], required=False),
151168
node=dict(type='str', required=True),
169+
source=dict(default='archive', choices=['archive', 'active', 'all']),
152170
)
153171

154172

@@ -167,10 +185,11 @@ def main():
167185
proxmox = ProxmoxTaskInfoAnsible(module)
168186
upid = module.params['task']
169187
node = module.params['node']
188+
source = module.params['source']
170189
if upid:
171-
tasks = proxmox.get_task(upid=upid, node=node)
190+
tasks = proxmox.get_task(upid=upid, node=node, source=source)
172191
else:
173-
tasks = proxmox.get_tasks(node=node)
192+
tasks = proxmox.get_tasks(node=node, source=source)
174193
if tasks is not None:
175194
result['proxmox_tasks'] = [task.info for task in tasks]
176195
module.exit_json(**result)

0 commit comments

Comments
 (0)