From 8439fd1f1a865891e1d5ecb4b934d5c3420517c4 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sat, 28 Dec 2024 13:17:45 +0330 Subject: [PATCH 01/35] Create proxmox_backup_info.py The `proxmox_backup_info` module displays information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API. --- plugins/modules/proxmox_backup_info.py | 187 +++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 plugins/modules/proxmox_backup_info.py diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py new file mode 100644 index 00000000000..16f96e75d07 --- /dev/null +++ b/plugins/modules/proxmox_backup_info.py @@ -0,0 +1,187 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2024 Marzieh Raoufnezhad +# Copyright (c) 2024 Maryam Mayabi +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = """ +--- +module: proxmox_backup_info + +short_description: Proxmox Schedule Backup Info + +description: The `proxmox_backup_info` module displays information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API. + +author: + - Marzieh Raoufnezhad + - Maryam Mayabi + +options: + api_user: + description: The user must have access to the proxmox server + required: true + api_password: + description: The password for the proxmox user + required: true + api_host: + description: Poroxmox server domain name or ip address + required: true + vm_name: + description: Proxmox vm name + required: false + vm_id: + description: Proxmox vm id + required: false + backup_section: + description: proxmox_backup_section + required: false + defulat: false +""" + +EXAMPLES = """ +--- +- name: Print all backup information by vmid and vm name + proxmox_backup_info: + api_user: 'myUser@pam' + api_password: '*******' + api_host: '192.168.20.20' + +--- +- name: Print proxmox backup information for a specific vm based on its name + proxmox_backup_info: + api_user: 'myUser@pam' + api_password: '*******' + api_host: '192.168.20.20' + vm_name: 'mailsrv' + +--- +- name: Print proxmox backup information for a specific vm based on its vmid + proxmox_backup_info: + api_user: 'myUser@pam' + api_password: '*******' + api_host: '192.168.20.20' + vm_id: '150' + +--- +- name: Print proxmox all backup job information + proxmox_backup_info: + api_user: 'myUser@pam' + api_password: '*******' + api_host: '192.168.20.20' + backup_section: 'true' +""" + +RETURN = """ +--- +result: + description: The return value provided by proxmox_backup_info. + type: dict +""" + +from datetime import datetime +from ansible.module_utils.basic import AnsibleModule, missing_required_lib +from ansible_collections.community.general.plugins.module_utils.proxmox import ( + proxmox_auth_argument_spec, ProxmoxAnsible, HAS_PROXMOXER, PROXMOXER_IMP_ERR, proxmox_to_ansible_bool) + +class ProxmoxBackupInfoAnsible(ProxmoxAnsible): + + # Get all backup information + def getSectionsList(self): + try: + backupSections=self.proxmox_api.cluster.backup.get() + except Exception as e: + module.fail_json(msg="Getting backup sections failed: %s" % e) + return backupSections + + # Get vm information + def getVmsList(self): + try: + vms=self.proxmox_api.cluster.resources.get(type='vm') + except Exception as e: + module.fail_json(msg="Getting vms info from cluster failed: %s" % e) + return vms + + # Get all backup information by vmid and vm name + def vmsBackupInfo(self): + backupList=self.getSectionsList() + vmInfo=self.getVmsList() + bkInfo=[] + for backupItem in backupList: + nextrun = datetime.fromtimestamp(backupItem['next-run']) + vmids=backupItem['vmid'].split(',') + for vmid in vmids: + for vm in vmInfo: + if vm['vmid'] == int(vmid): + vmName = vm['name'] + break + bkInfoData = { 'id': backupItem['id'], + 'schedule': backupItem['schedule'], + 'storage': backupItem['storage'], + 'mode': backupItem['mode'], + 'next-run': nextrun.strftime("%Y-%m-%d %H:%M:%S"), + 'enabled': backupItem['enabled'], + 'bktype': backupItem['type'], + 'vmid': vmid, + 'vm_name': vmName } + bkInfo.append(bkInfoData) + return bkInfo + + # Get proxmox backup information for a specific vm based on its vmid or vm name + def specificVmBackupInfo(self,vm_name_id): + fullBackupInfo = self.vmsBackupInfo() + vmBackupSections = [] + for vm in fullBackupInfo: + if (vm["vm_name"] == vm_name_id or int(vm["vmid"]) == vm_name_id): + vmBackupSections.append(vm) + return vmBackupSections + +def main(): + # Define module args + args = proxmox_auth_argument_spec() + backup_info_args = dict( + vm_id=dict(type='int',required=False), + vm_name=dict(type='str',required=False), + backup_section=dict(type='bool',default=False,required=False) + ) + args.update(backup_info_args) + + module = AnsibleModule( + argument_spec=args, + mutually_exclusive=[('backup_section', 'vm_id', 'vm_name')], + supports_check_mode=True) + + # Define (init) result value + result = dict( + changed=False + ) + + # Check if proxmoxer exist + if not HAS_PROXMOXER: + module.fail_json(msg=missing_required_lib('proxmoxer'), exception=PROXMOXER_IMP_ERR) + + # Start to connect to proxmox to get backup data + proxmox = ProxmoxBackupInfoAnsible(module) + vm_id = module.params['vm_id'] + vm_name = module.params['vm_name'] + backup_section = module.params['backup_section'] + + # Update result value based on what requested (module args) + if backup_section: + result['backup_info'] = proxmox.getSectionsList() + elif vm_id: + result['backup_info'] = proxmox.specificVmBackupInfo(vm_id) + elif vm_name: + result['backup_info'] = proxmox.specificVmBackupInfo(vm_name) + else: + result['backup_info'] = proxmox.vmsBackupInfo() + + # Return result value + module.exit_json(**result) + +if __name__ == '__main__': + main() From 2eb2e8ad78fdadf0ec250a8a4323571af44ba5a5 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sat, 28 Dec 2024 13:21:19 +0330 Subject: [PATCH 02/35] Create test_proxmox_backup_info.py create test for proxmox_backup_info.py module --- .../modules/test_proxmox_backup_info.py | 275 ++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100644 tests/unit/plugins/modules/test_proxmox_backup_info.py diff --git a/tests/unit/plugins/modules/test_proxmox_backup_info.py b/tests/unit/plugins/modules/test_proxmox_backup_info.py new file mode 100644 index 00000000000..066a99bbd6d --- /dev/null +++ b/tests/unit/plugins/modules/test_proxmox_backup_info.py @@ -0,0 +1,275 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2024 Marzieh Raoufnezhad +# Copyright (c) 2024 Maryam Mayabi +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import sys +import pytest + +proxmoxer = pytest.importorskip("proxmoxer") +mandatory_py_version = pytest.mark.skipif( + sys.version_info < (2, 7), + reason="The proxmoxer dependency requires python2.7 or higher", +) + +from ansible_collections.community.general.plugins.modules import proxmox_backup_info +from ansible_collections.community.general.tests.unit.compat.mock import patch +from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( + AnsibleExitJson, + AnsibleFailJson, + ModuleTestCase, + set_module_args, +) +import ansible_collections.community.general.plugins.module_utils.proxmox as proxmox_utils + +RESOURCE_LIST = [ + { + "uptime": 0, + "diskwrite": 0, + "name": "test01", + "maxcpu": 0, + "node": "NODE1", + "mem": 0, + "netout": 0, + "netin": 0, + "maxmem": 0, + "diskread": 0, + "disk": 0, + "maxdisk": 0, + "status": "running", + "cpu": 0, + "id": "qemu/100", + "template": 0, + "vmid": 100, + "type": "qemu" + }, + { + "uptime": 0, + "diskwrite": 0, + "name": "test02", + "maxcpu": 0, + "node": "NODE1", + "mem": 0, + "netout": 0, + "netin": 0, + "maxmem": 0, + "diskread": 0, + "disk": 0, + "maxdisk": 0, + "status": "running", + "cpu": 0, + "id": "qemu/101", + "template": 0, + "vmid": 101, + "type": "qemu" + }, + { + "uptime": 0, + "diskwrite": 0, + "name": "test03", + "maxcpu": 0, + "node": "NODE2", + "mem": 0, + "netout": 0, + "netin": 0, + "maxmem": 0, + "diskread": 0, + "disk": 0, + "maxdisk": 0, + "status": "running", + "cpu": 0, + "id": "qemu/102", + "template": 0, + "vmid": 102, + "type": "qemu" + } +] +BACKUP_SECTIONS = [ + { + "type": "vzdump", + "id": "backup-83831498-c631", + "storage": "local", + "vmid": "100", + "enabled": 1, + "next-run": 1735138800, + "mailnotification": "always", + "schedule": "06,18:30", + "mode": "snapshot", + "notes-template": "guestname" + }, + { + "schedule": "sat 15:00", + "notes-template": "guestname", + "mode": "snapshot", + "mailnotification": "always", + "next-run": 1735385400, + "type": "vzdump", + "enabled": 1, + "vmid": "100,101,102", + "storage": "local", + "id": "backup-70025700-2302", + } +] + +EXPECTED_BACKUP_OUTPUT = [ + { + "bktype": "vzdump", + "enabled": 1, + "id": "backup-83831498-c631", + "mode": "snapshot", + "next-run": "2024-12-25 18:30:00", + "schedule": "06,18:30", + "storage": "local", + "vm_name": "test01", + "vmid": "100" + }, + { + "bktype": "vzdump", + "enabled": 1, + "id": "backup-70025700-2302", + "mode": "snapshot", + "next-run": "2024-12-28 15:00:00", + "schedule": "sat 15:00", + "storage": "local", + "vm_name": "test01", + "vmid": "100" + }, + { + "bktype": "vzdump", + "enabled": 1, + "id": "backup-70025700-2302", + "mode": "snapshot", + "next-run": "2024-12-28 15:00:00", + "schedule": "sat 15:00", + "storage": "local", + "vm_name": "test02", + "vmid": "101" + }, + { + "bktype": "vzdump", + "enabled": 1, + "id": "backup-70025700-2302", + "mode": "snapshot", + "next-run": "2024-12-28 15:00:00", + "schedule": "sat 15:00", + "storage": "local", + "vm_name": "test03", + "vmid": "102" + } +] +EXPECTED_BACKUP_SECTION_OUTPUT = [ + { + "enabled": 1, + "id": "backup-83831498-c631", + "mailnotification": "always", + "mode": "snapshot", + "next-run": 1735138800, + "notes-template": "guestname", + "schedule": "06,18:30", + "storage": "local", + "type": "vzdump", + "vmid": "100" + }, + { + "enabled": 1, + "id": "backup-70025700-2302", + "mailnotification": "always", + "mode": "snapshot", + "next-run": 1735385400, + "notes-template": "guestname", + "schedule": "sat 15:00", + "storage": "local", + "type": "vzdump", + "vmid": "100,101,102" + } +] + +class TestProxmoxBackupInfoModule(ModuleTestCase): + def setUp(self): + super(TestProxmoxBackupInfoModule, self).setUp() + proxmox_utils.HAS_PROXMOXER = True + self.module = proxmox_backup_info + self.connect_mock = patch( + "ansible_collections.community.general.plugins.module_utils.proxmox.ProxmoxAnsible._connect", + ).start() + self.connect_mock.return_value.cluster.resources.get.return_value = ( + RESOURCE_LIST + ) + self.connect_mock.return_value.cluster.backup.get.return_value = ( + BACKUP_SECTIONS + ) + + def tearDown(self): + self.connect_mock.stop() + super(TestProxmoxBackupInfoModule, self).tearDown() + + def test_module_fail_when_required_args_missing(self): + with pytest.raises(AnsibleFailJson) as exc_info: + set_module_args({}) + self.module.main() + + result = exc_info.value.args[0] + assert result["msg"] == "missing required arguments: api_host, api_user" + + def test_get_all_backups_information(self): + with pytest.raises(AnsibleExitJson) as exc_info: + set_module_args({'api_host': 'proxmoxhost', + 'api_user': 'root@pam', + 'api_password': 'supersecret' + }) + self.module.main() + + result = exc_info.value.args[0] + assert result["backup_info"] == EXPECTED_BACKUP_OUTPUT + + def test_get_specific_backup_information_by_vmname(self): + with pytest.raises(AnsibleExitJson) as exc_info: + vmname = 'test01' + expected_output = [ + backup for backup in EXPECTED_BACKUP_OUTPUT if backup["vm_name"] == vmname + ] + set_module_args({'api_host': 'proxmoxhost', + 'api_user': 'root@pam', + 'api_password': 'supersecret', + 'vm_name': vmname + }) + self.module.main() + + result = exc_info.value.args[0] + assert result["backup_info"] == expected_output + assert len(result["backup_info"]) == 2 + + def test_get_specific_backup_information_by_vmid(self): + with pytest.raises(AnsibleExitJson) as exc_info: + vmid = "101" + expected_output = [ + backup for backup in EXPECTED_BACKUP_OUTPUT if backup["vmid"] == vmid + ] + set_module_args({'api_host': 'proxmoxhost', + 'api_user': 'root@pam', + 'api_password': 'supersecret', + 'vm_id': vmid + }) + self.module.main() + result = exc_info.value.args[0] + assert result["backup_info"] == expected_output + assert len(result["backup_info"]) == 1 + + def test_get_specific_backup_information_by_backupsection(self): + with pytest.raises(AnsibleExitJson) as exc_info: + backupsection = True + set_module_args({'api_host': 'proxmoxhost', + 'api_user': 'root@pam', + 'api_password': 'supersecret', + 'backup_section':backupsection + }) + self.module.main() + + result = exc_info.value.args[0] + assert result["backup_info"] == EXPECTED_BACKUP_SECTION_OUTPUT From 2b1c48f20e7837cbe7c58ca2ee6383dbf2a13973 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 29 Dec 2024 10:11:53 +0330 Subject: [PATCH 03/35] Update plugins/modules/proxmox_backup_info.py Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- plugins/modules/proxmox_backup_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 16f96e75d07..8218b5cfd83 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -15,7 +15,7 @@ short_description: Proxmox Schedule Backup Info -description: The `proxmox_backup_info` module displays information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API. +description: Retrieve information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API. author: - Marzieh Raoufnezhad From 469afeca1914246701124eb9d65cc901ff9de138 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:12:53 +0330 Subject: [PATCH 04/35] check tests proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 163 ++++++++++++++++--------- 1 file changed, 103 insertions(+), 60 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 8218b5cfd83..b01efc3eb0b 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -1,8 +1,8 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# Copyright (c) 2024 Marzieh Raoufnezhad -# Copyright (c) 2024 Maryam Mayabi +# Copyright (c) 2024 Marzieh Raoufnezhad +# Copyright (c) 2024 Maryam Mayabi # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # SPDX-License-Identifier: GPL-3.0-or-later @@ -13,34 +13,34 @@ --- module: proxmox_backup_info -short_description: Proxmox Schedule Backup Info +short_description: Proxmox Schedule Backup Info -description: Retrieve information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API. +description: + - Retrieve information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API. -author: - - Marzieh Raoufnezhad - - Maryam Mayabi +author: + - Marzieh Raoufnezhad (@raoufnezhad) + - Maryam Mayabi (@mmayabi) options: - api_user: - description: The user must have access to the proxmox server - required: true - api_password: - description: The password for the proxmox user - required: true - api_host: - description: Poroxmox server domain name or ip address - required: true - vm_name: - description: Proxmox vm name - required: false - vm_id: - description: Proxmox vm id - required: false - backup_section: - description: proxmox_backup_section - required: false - defulat: false + vm_name: + description: Proxmox vm name + required: False + type: str + vm_id: + description: Proxmox vm id + required: False + type: int + backup_section: + description: proxmox_backup_section + required: False + default: False + type: bool + +extends_documentation_fragment: + - community.general.proxmox.documentation + - community.general.attributes + - community.general.attributes.info_module """ EXAMPLES = """ @@ -68,94 +68,136 @@ vm_id: '150' --- -- name: Print proxmox all backup job information +- name: Print proxmox all backup job information proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' - backup_section: 'true' + backup_section: True """ RETURN = """ --- -result: - description: The return value provided by proxmox_backup_info. - type: dict +backup_info: + description: The return value provided by proxmox_backup_info. + returned: always, but can be empty + type: list + elements: dict + contains: + bktype: + description: backup type + returned: on success + type: str + enabled: + description: 1 if backup is enabled else 0. + returned: on success + type: bool + id: + description: backup job id + returned: on success + type: str + mode: + description: backup job mode such as snapshot + returned: on success + type: str + next-run: + description: next backup time + returned: on success + type: str + schedule: + description: backup job schedule + returned: on success + type: str + storage: + description: backup storage location + returned: on success + type: str + vm_name: + description: VM name + returned: on success + type: str + vmid: + description: vm id + returned: on success + type: int """ from datetime import datetime from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible_collections.community.general.plugins.module_utils.proxmox import ( - proxmox_auth_argument_spec, ProxmoxAnsible, HAS_PROXMOXER, PROXMOXER_IMP_ERR, proxmox_to_ansible_bool) + proxmox_auth_argument_spec, ProxmoxAnsible, HAS_PROXMOXER, PROXMOXER_IMP_ERR) + class ProxmoxBackupInfoAnsible(ProxmoxAnsible): # Get all backup information def getSectionsList(self): try: - backupSections=self.proxmox_api.cluster.backup.get() + backupSections = self.proxmox_api.cluster.backup.get() except Exception as e: - module.fail_json(msg="Getting backup sections failed: %s" % e) + self.module.fail_json(msg="Getting backup sections failed: %s" % e) return backupSections - + # Get vm information def getVmsList(self): try: - vms=self.proxmox_api.cluster.resources.get(type='vm') + vms = self.proxmox_api.cluster.resources.get(type='vm') except Exception as e: - module.fail_json(msg="Getting vms info from cluster failed: %s" % e) + self.module.fail_json(msg="Getting vms info from cluster failed: %s" % e) return vms # Get all backup information by vmid and vm name def vmsBackupInfo(self): - backupList=self.getSectionsList() - vmInfo=self.getVmsList() - bkInfo=[] + backupList = self.getSectionsList() + vmInfo = self.getVmsList() + bkInfo = [] for backupItem in backupList: nextrun = datetime.fromtimestamp(backupItem['next-run']) - vmids=backupItem['vmid'].split(',') + vmids = backupItem['vmid'].split(',') for vmid in vmids: for vm in vmInfo: if vm['vmid'] == int(vmid): vmName = vm['name'] break - bkInfoData = { 'id': backupItem['id'], - 'schedule': backupItem['schedule'], - 'storage': backupItem['storage'], - 'mode': backupItem['mode'], - 'next-run': nextrun.strftime("%Y-%m-%d %H:%M:%S"), - 'enabled': backupItem['enabled'], - 'bktype': backupItem['type'], - 'vmid': vmid, - 'vm_name': vmName } + bkInfoData = {'id': backupItem['id'], + 'schedule': backupItem['schedule'], + 'storage': backupItem['storage'], + 'mode': backupItem['mode'], + 'next-run': nextrun.strftime("%Y-%m-%d %H:%M:%S"), + 'enabled': backupItem['enabled'], + 'bktype': backupItem['type'], + 'vmid': vmid, + 'vm_name': vmName} bkInfo.append(bkInfoData) return bkInfo - + # Get proxmox backup information for a specific vm based on its vmid or vm name - def specificVmBackupInfo(self,vm_name_id): + def specificVmBackupInfo(self, vm_name_id): fullBackupInfo = self.vmsBackupInfo() vmBackupSections = [] for vm in fullBackupInfo: if (vm["vm_name"] == vm_name_id or int(vm["vmid"]) == vm_name_id): vmBackupSections.append(vm) return vmBackupSections - + + def main(): # Define module args args = proxmox_auth_argument_spec() backup_info_args = dict( - vm_id=dict(type='int',required=False), - vm_name=dict(type='str',required=False), - backup_section=dict(type='bool',default=False,required=False) - ) + vm_id=dict(type='int', required=False), + vm_name=dict(type='str', required=False), + backup_section=dict(type='bool', default=False, required=False) + ) args.update(backup_info_args) module = AnsibleModule( argument_spec=args, mutually_exclusive=[('backup_section', 'vm_id', 'vm_name')], - supports_check_mode=True) - - # Define (init) result value + supports_check_mode=True + ) + + # Define (init) result value result = dict( changed=False ) @@ -183,5 +225,6 @@ def main(): # Return result value module.exit_json(**result) + if __name__ == '__main__': main() From 5ede419574ee5e9a126ca23464b35f0619a0aa08 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:14:17 +0330 Subject: [PATCH 05/35] check tests test_proxmox_backup_info.py --- tests/unit/plugins/modules/test_proxmox_backup_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/plugins/modules/test_proxmox_backup_info.py b/tests/unit/plugins/modules/test_proxmox_backup_info.py index 066a99bbd6d..3fda18d35a8 100644 --- a/tests/unit/plugins/modules/test_proxmox_backup_info.py +++ b/tests/unit/plugins/modules/test_proxmox_backup_info.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# Copyright (c) 2024 Marzieh Raoufnezhad -# Copyright (c) 2024 Maryam Mayabi +# Copyright (c) 2024 Marzieh Raoufnezhad +# Copyright (c) 2024 Maryam Mayabi # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # SPDX-License-Identifier: GPL-3.0-or-later From 193a13cb84607099e65422acc369fc2ea759ea5b Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:22:27 +0330 Subject: [PATCH 06/35] Update check tests test_proxmox_backup_info.py --- .../modules/test_proxmox_backup_info.py | 101 +++++++++--------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/tests/unit/plugins/modules/test_proxmox_backup_info.py b/tests/unit/plugins/modules/test_proxmox_backup_info.py index 3fda18d35a8..943df7ba571 100644 --- a/tests/unit/plugins/modules/test_proxmox_backup_info.py +++ b/tests/unit/plugins/modules/test_proxmox_backup_info.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# Copyright (c) 2024 Marzieh Raoufnezhad -# Copyright (c) 2024 Maryam Mayabi +# Copyright (c) 2024 Marzieh Raoufnezhad +# Copyright (c) 2024 Maryam Mayabi # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # SPDX-License-Identifier: GPL-3.0-or-later @@ -32,62 +32,62 @@ { "uptime": 0, "diskwrite": 0, - "name": "test01", + "name": "test01", "maxcpu": 0, - "node": "NODE1", + "node": "NODE1", "mem": 0, "netout": 0, "netin": 0, "maxmem": 0, "diskread": 0, - "disk": 0, + "disk": 0, "maxdisk": 0, "status": "running", "cpu": 0, "id": "qemu/100", - "template": 0, - "vmid": 100, - "type": "qemu" + "template": 0, + "vmid": 100, + "type": "qemu" }, { "uptime": 0, "diskwrite": 0, - "name": "test02", + "name": "test02", "maxcpu": 0, - "node": "NODE1", + "node": "NODE1", "mem": 0, "netout": 0, "netin": 0, "maxmem": 0, - "diskread": 0, - "disk": 0, + "diskread": 0, + "disk": 0, "maxdisk": 0, "status": "running", "cpu": 0, "id": "qemu/101", - "template": 0, - "vmid": 101, - "type": "qemu" + "template": 0, + "vmid": 101, + "type": "qemu" }, { "uptime": 0, "diskwrite": 0, - "name": "test03", + "name": "test03", "maxcpu": 0, - "node": "NODE2", + "node": "NODE2", "mem": 0, "netout": 0, "netin": 0, "maxmem": 0, - "diskread": 0, - "disk": 0, + "diskread": 0, + "disk": 0, "maxdisk": 0, "status": "running", "cpu": 0, "id": "qemu/102", - "template": 0, - "vmid": 102, - "type": "qemu" + "template": 0, + "vmid": 102, + "type": "qemu" } ] BACKUP_SECTIONS = [ @@ -104,14 +104,14 @@ "notes-template": "guestname" }, { - "schedule": "sat 15:00", + "schedule": "sat 15:00", "notes-template": "guestname", - "mode": "snapshot", - "mailnotification": "always", - "next-run": 1735385400, - "type": "vzdump", - "enabled": 1, - "vmid": "100,101,102", + "mode": "snapshot", + "mailnotification": "always", + "next-run": 1735385400, + "type": "vzdump", + "enabled": 1, + "vmid": "100,101,102", "storage": "local", "id": "backup-70025700-2302", } @@ -190,6 +190,7 @@ } ] + class TestProxmoxBackupInfoModule(ModuleTestCase): def setUp(self): super(TestProxmoxBackupInfoModule, self).setUp() @@ -219,10 +220,11 @@ def test_module_fail_when_required_args_missing(self): def test_get_all_backups_information(self): with pytest.raises(AnsibleExitJson) as exc_info: - set_module_args({'api_host': 'proxmoxhost', - 'api_user': 'root@pam', - 'api_password': 'supersecret' - }) + set_module_args({ + 'api_host': 'proxmoxhost', + 'api_user': 'root@pam', + 'api_password': 'supersecret' + }) self.module.main() result = exc_info.value.args[0] @@ -234,11 +236,12 @@ def test_get_specific_backup_information_by_vmname(self): expected_output = [ backup for backup in EXPECTED_BACKUP_OUTPUT if backup["vm_name"] == vmname ] - set_module_args({'api_host': 'proxmoxhost', - 'api_user': 'root@pam', - 'api_password': 'supersecret', - 'vm_name': vmname - }) + set_module_args({ + 'api_host': 'proxmoxhost', + 'api_user': 'root@pam', + 'api_password': 'supersecret', + 'vm_name': vmname + }) self.module.main() result = exc_info.value.args[0] @@ -251,11 +254,12 @@ def test_get_specific_backup_information_by_vmid(self): expected_output = [ backup for backup in EXPECTED_BACKUP_OUTPUT if backup["vmid"] == vmid ] - set_module_args({'api_host': 'proxmoxhost', - 'api_user': 'root@pam', - 'api_password': 'supersecret', - 'vm_id': vmid - }) + set_module_args({ + 'api_host': 'proxmoxhost', + 'api_user': 'root@pam', + 'api_password': 'supersecret', + 'vm_id': vmid + }) self.module.main() result = exc_info.value.args[0] assert result["backup_info"] == expected_output @@ -264,11 +268,12 @@ def test_get_specific_backup_information_by_vmid(self): def test_get_specific_backup_information_by_backupsection(self): with pytest.raises(AnsibleExitJson) as exc_info: backupsection = True - set_module_args({'api_host': 'proxmoxhost', - 'api_user': 'root@pam', - 'api_password': 'supersecret', - 'backup_section':backupsection - }) + set_module_args({ + 'api_host': 'proxmoxhost', + 'api_user': 'root@pam', + 'api_password': 'supersecret', + 'backup_section': backupsection + }) self.module.main() result = exc_info.value.args[0] From f0f76c4f74f16e8ff5a0d8531305776adfa9b7ee Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:44:13 +0330 Subject: [PATCH 07/35] Update check tests proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index b01efc3eb0b..de092cd208d 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -1,8 +1,8 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# Copyright (c) 2024 Marzieh Raoufnezhad -# Copyright (c) 2024 Maryam Mayabi +# Copyright (c) 2024 Marzieh Raoufnezhad +# Copyright (c) 2024 Maryam Mayabi # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # SPDX-License-Identifier: GPL-3.0-or-later @@ -19,8 +19,8 @@ - Retrieve information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API. author: - - Marzieh Raoufnezhad (@raoufnezhad) - - Maryam Mayabi (@mmayabi) + - "Marzieh Raoufnezhad (@raoufnezhad)" + - "Maryam Mayabi (@mmayabi)" options: vm_name: @@ -41,17 +41,16 @@ - community.general.proxmox.documentation - community.general.attributes - community.general.attributes.info_module + - community.general.proxmox.actiongroup_proxmox """ EXAMPLES = """ ---- - name: Print all backup information by vmid and vm name proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' ---- - name: Print proxmox backup information for a specific vm based on its name proxmox_backup_info: api_user: 'myUser@pam' @@ -59,7 +58,6 @@ api_host: '192.168.20.20' vm_name: 'mailsrv' ---- - name: Print proxmox backup information for a specific vm based on its vmid proxmox_backup_info: api_user: 'myUser@pam' @@ -67,7 +65,6 @@ api_host: '192.168.20.20' vm_id: '150' ---- - name: Print proxmox all backup job information proxmox_backup_info: api_user: 'myUser@pam' From 1fd11062c8b2c8a64153b78f831a555e4d0ba51e Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:57:54 +0330 Subject: [PATCH 08/35] Update authors proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index de092cd208d..54136a37711 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -19,8 +19,8 @@ - Retrieve information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API. author: - - "Marzieh Raoufnezhad (@raoufnezhad)" - - "Maryam Mayabi (@mmayabi)" + - "Marzieh Raoufnezhad (@raoufnezhad) " + - "Maryam Mayabi (@mmayabi) " options: vm_name: From 0be21d8c26cd7ca139e2545be01a1454b800d289 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 29 Dec 2024 13:03:50 +0330 Subject: [PATCH 09/35] Update active maintainers for proxmox_backup_info module --- .github/BOTMETA.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index dbe3c9cfe19..f25fab1096d 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -1129,6 +1129,8 @@ files: maintainers: helldorado krauthosting $modules/proxmox_backup.py: maintainers: IamLunchbox + $modules/proxmox_backup_info.py: + maintainers: raoufnezhad mmayabi $modules/proxmox_nic.py: maintainers: Kogelvis krauthosting $modules/proxmox_node_info.py: From deba34901d53791d30f3ba89349d88bf43c292cb Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 29 Dec 2024 13:08:13 +0330 Subject: [PATCH 10/35] Update add proxmox_backup_info module in proxmox group --- meta/runtime.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/meta/runtime.yml b/meta/runtime.yml index 5b3bb0b6f06..12c026b5bbd 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -17,6 +17,7 @@ action_groups: proxmox: - proxmox - proxmox_backup + - proxmox_backup_info - proxmox_disk - proxmox_domain_info - proxmox_group_info From 4fcdd00fd1ac244a4455e2cdc2f30cad0725dec2 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 29 Dec 2024 13:39:41 +0330 Subject: [PATCH 11/35] edit timestamp to UTC test_proxmox_backup_info.py --- tests/unit/plugins/modules/test_proxmox_backup_info.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/plugins/modules/test_proxmox_backup_info.py b/tests/unit/plugins/modules/test_proxmox_backup_info.py index 943df7ba571..18c0f9e5942 100644 --- a/tests/unit/plugins/modules/test_proxmox_backup_info.py +++ b/tests/unit/plugins/modules/test_proxmox_backup_info.py @@ -123,7 +123,7 @@ "enabled": 1, "id": "backup-83831498-c631", "mode": "snapshot", - "next-run": "2024-12-25 18:30:00", + "next-run": "2024-12-25 15:00:00", "schedule": "06,18:30", "storage": "local", "vm_name": "test01", @@ -134,7 +134,7 @@ "enabled": 1, "id": "backup-70025700-2302", "mode": "snapshot", - "next-run": "2024-12-28 15:00:00", + "next-run": "2024-12-28 11:30:00", "schedule": "sat 15:00", "storage": "local", "vm_name": "test01", @@ -145,7 +145,7 @@ "enabled": 1, "id": "backup-70025700-2302", "mode": "snapshot", - "next-run": "2024-12-28 15:00:00", + "next-run": "2024-12-28 11:30:00", "schedule": "sat 15:00", "storage": "local", "vm_name": "test02", @@ -156,7 +156,7 @@ "enabled": 1, "id": "backup-70025700-2302", "mode": "snapshot", - "next-run": "2024-12-28 15:00:00", + "next-run": "2024-12-28 11:30:00", "schedule": "sat 15:00", "storage": "local", "vm_name": "test03", From 57791ab3ea84066958b9a7afb94335c83213989b Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:05:04 +0330 Subject: [PATCH 12/35] Update vm name or vmid to VM name or VM id proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 54136a37711..f597d775f20 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -24,11 +24,11 @@ options: vm_name: - description: Proxmox vm name + description: Proxmox VM name required: False type: str vm_id: - description: Proxmox vm id + description: Proxmox VM id required: False type: int backup_section: @@ -45,20 +45,20 @@ """ EXAMPLES = """ -- name: Print all backup information by vmid and vm name +- name: Print all backup information by VM id and VM name proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' -- name: Print proxmox backup information for a specific vm based on its name +- name: Print proxmox backup information for a specific VM based on its name proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' vm_name: 'mailsrv' -- name: Print proxmox backup information for a specific vm based on its vmid +- name: Print proxmox backup information for a specific VM based on its VM id proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' @@ -88,7 +88,7 @@ enabled: description: 1 if backup is enabled else 0. returned: on success - type: bool + type: int id: description: backup job id returned: on success @@ -114,7 +114,7 @@ returned: on success type: str vmid: - description: vm id + description: VM id returned: on success type: int """ @@ -135,15 +135,15 @@ def getSectionsList(self): self.module.fail_json(msg="Getting backup sections failed: %s" % e) return backupSections - # Get vm information + # Get VM information def getVmsList(self): try: vms = self.proxmox_api.cluster.resources.get(type='vm') except Exception as e: - self.module.fail_json(msg="Getting vms info from cluster failed: %s" % e) + self.module.fail_json(msg="Getting VMs info from cluster failed: %s" % e) return vms - # Get all backup information by vmid and vm name + # Get all backup information by VM id and VM name def vmsBackupInfo(self): backupList = self.getSectionsList() vmInfo = self.getVmsList() @@ -168,7 +168,7 @@ def vmsBackupInfo(self): bkInfo.append(bkInfoData) return bkInfo - # Get proxmox backup information for a specific vm based on its vmid or vm name + # Get proxmox backup information for a specific VM based on its VM id or VM name def specificVmBackupInfo(self, vm_name_id): fullBackupInfo = self.vmsBackupInfo() vmBackupSections = [] From 8e8dfb0ee93465bbbee251d3777ca99593d8c262 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:45:09 +0330 Subject: [PATCH 13/35] update documentation in proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index f597d775f20..c269a85f6a4 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -13,7 +13,7 @@ --- module: proxmox_backup_info -short_description: Proxmox Schedule Backup Info +short_description: Retrieve information on Proxmox scheduled backups description: - Retrieve information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API. @@ -24,17 +24,17 @@ options: vm_name: - description: Proxmox VM name - required: False + description: The name of the Proxmox VM. + required: false type: str vm_id: - description: Proxmox VM id - required: False + description: The ID of the Proxmox VM. + required: false type: int backup_section: - description: proxmox_backup_section - required: False - default: False + description: The backup_section value is true or false. if this be true, proxmox backup info module just return all backup job information. + required: false + default: false type: bool extends_documentation_fragment: @@ -70,13 +70,13 @@ api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' - backup_section: True + backup_section: true """ RETURN = """ --- backup_info: - description: The return value provided by proxmox_backup_info. + description: The return value provides backup job information based on VM ID or VM name, or total backup job information. returned: always, but can be empty type: list elements: dict From 87d99c869ba8813202ac7109e0ad237c1c735c2d Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 30 Dec 2024 11:22:40 +0330 Subject: [PATCH 14/35] Update backup_section decription in proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index c269a85f6a4..467420d40bf 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -32,7 +32,7 @@ required: false type: int backup_section: - description: The backup_section value is true or false. if this be true, proxmox backup info module just return all backup job information. + description: The backup_section value is true or false. if this be true, this module just return all backup job information. required: false default: false type: bool From 95c5fdd1cc09bc4db46d7ced319d7097eb4fc664 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Tue, 31 Dec 2024 09:02:41 +0330 Subject: [PATCH 15/35] Update plugins/modules/proxmox_backup_info.py Co-authored-by: Felix Fontein --- plugins/modules/proxmox_backup_info.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 467420d40bf..18b9628728d 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -47,9 +47,9 @@ EXAMPLES = """ - name: Print all backup information by VM id and VM name proxmox_backup_info: - api_user: 'myUser@pam' - api_password: '*******' - api_host: '192.168.20.20' + api_user: 'myUser@pam' + api_password: '*******' + api_host: '192.168.20.20' - name: Print proxmox backup information for a specific VM based on its name proxmox_backup_info: From 86dc5eda5c89d77aab4a5e650bf603876cefe093 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Tue, 31 Dec 2024 10:05:28 +0330 Subject: [PATCH 16/35] change backup_section to backup_jobs --- plugins/modules/proxmox_backup_info.py | 51 ++++++++++++++------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 18b9628728d..6b5882b962b 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -31,8 +31,11 @@ description: The ID of the Proxmox VM. required: false type: int - backup_section: - description: The backup_section value is true or false. if this be true, this module just return all backup job information. + backup_jobs: + description: + - The backup_jobs value is true or false. + - If set to true, this module just return all backup jobs information. + - If set to false, what is listed depends on the other options. required: false default: false type: bool @@ -70,7 +73,7 @@ api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' - backup_section: true + backup_jobs: true """ RETURN = """ @@ -82,7 +85,7 @@ elements: dict contains: bktype: - description: backup type + description: The type of the backup. returned: on success type: str enabled: @@ -90,31 +93,31 @@ returned: on success type: int id: - description: backup job id + description: The backup job id. returned: on success type: str mode: - description: backup job mode such as snapshot + description: The backup job mode such as snapshot. returned: on success type: str next-run: - description: next backup time + description: The next backup time. returned: on success type: str schedule: - description: backup job schedule + description: The backup job schedule. returned: on success type: str storage: - description: backup storage location + description: The backup storage location. returned: on success type: str vm_name: - description: VM name + description: The VM name. returned: on success type: str vmid: - description: VM id + description: The VM vmid. returned: on success type: int """ @@ -128,12 +131,12 @@ class ProxmoxBackupInfoAnsible(ProxmoxAnsible): # Get all backup information - def getSectionsList(self): + def getJobsList(self): try: - backupSections = self.proxmox_api.cluster.backup.get() + backupJobs = self.proxmox_api.cluster.backup.get() except Exception as e: - self.module.fail_json(msg="Getting backup sections failed: %s" % e) - return backupSections + self.module.fail_json(msg="Getting backup jobs failed: %s" % e) + return backupJobs # Get VM information def getVmsList(self): @@ -145,7 +148,7 @@ def getVmsList(self): # Get all backup information by VM id and VM name def vmsBackupInfo(self): - backupList = self.getSectionsList() + backupList = self.getJobsList() vmInfo = self.getVmsList() bkInfo = [] for backupItem in backupList: @@ -171,11 +174,11 @@ def vmsBackupInfo(self): # Get proxmox backup information for a specific VM based on its VM id or VM name def specificVmBackupInfo(self, vm_name_id): fullBackupInfo = self.vmsBackupInfo() - vmBackupSections = [] + vmBackupJobs = [] for vm in fullBackupInfo: if (vm["vm_name"] == vm_name_id or int(vm["vmid"]) == vm_name_id): - vmBackupSections.append(vm) - return vmBackupSections + vmBackupJobs.append(vm) + return vmBackupJobs def main(): @@ -184,13 +187,13 @@ def main(): backup_info_args = dict( vm_id=dict(type='int', required=False), vm_name=dict(type='str', required=False), - backup_section=dict(type='bool', default=False, required=False) + backup_jobs=dict(type='bool', default=False, required=False) ) args.update(backup_info_args) module = AnsibleModule( argument_spec=args, - mutually_exclusive=[('backup_section', 'vm_id', 'vm_name')], + mutually_exclusive=[('backup_jobs', 'vm_id', 'vm_name')], supports_check_mode=True ) @@ -207,11 +210,11 @@ def main(): proxmox = ProxmoxBackupInfoAnsible(module) vm_id = module.params['vm_id'] vm_name = module.params['vm_name'] - backup_section = module.params['backup_section'] + backup_jobs = module.params['backup_jobs'] # Update result value based on what requested (module args) - if backup_section: - result['backup_info'] = proxmox.getSectionsList() + if backup_jobs: + result['backup_info'] = proxmox.getJobsList() elif vm_id: result['backup_info'] = proxmox.specificVmBackupInfo(vm_id) elif vm_name: From cca7ead7a2211705c9c33c5ffc691485b931f15b Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Tue, 31 Dec 2024 10:05:37 +0330 Subject: [PATCH 17/35] change backup_section to backup_jobs --- .../plugins/modules/test_proxmox_backup_info.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/unit/plugins/modules/test_proxmox_backup_info.py b/tests/unit/plugins/modules/test_proxmox_backup_info.py index 18c0f9e5942..27cc7b594ed 100644 --- a/tests/unit/plugins/modules/test_proxmox_backup_info.py +++ b/tests/unit/plugins/modules/test_proxmox_backup_info.py @@ -90,7 +90,7 @@ "type": "qemu" } ] -BACKUP_SECTIONS = [ +BACKUP_JOBS = [ { "type": "vzdump", "id": "backup-83831498-c631", @@ -163,7 +163,7 @@ "vmid": "102" } ] -EXPECTED_BACKUP_SECTION_OUTPUT = [ +EXPECTED_BACKUP_JOBS_OUTPUT = [ { "enabled": 1, "id": "backup-83831498-c631", @@ -203,7 +203,7 @@ def setUp(self): RESOURCE_LIST ) self.connect_mock.return_value.cluster.backup.get.return_value = ( - BACKUP_SECTIONS + BACKUP_JOBS ) def tearDown(self): @@ -265,16 +265,16 @@ def test_get_specific_backup_information_by_vmid(self): assert result["backup_info"] == expected_output assert len(result["backup_info"]) == 1 - def test_get_specific_backup_information_by_backupsection(self): + def test_get_specific_backup_information_by_backupjobs(self): with pytest.raises(AnsibleExitJson) as exc_info: - backupsection = True + backupjobs = True set_module_args({ 'api_host': 'proxmoxhost', 'api_user': 'root@pam', 'api_password': 'supersecret', - 'backup_section': backupsection + 'backup_jobs': backupjobs }) self.module.main() result = exc_info.value.args[0] - assert result["backup_info"] == EXPECTED_BACKUP_SECTION_OUTPUT + assert result["backup_info"] == EXPECTED_BACKUP_JOBS_OUTPUT From b4d2fd8b5bc798141e5a5ce368c93a2d1a2de98f Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Tue, 31 Dec 2024 10:30:24 +0330 Subject: [PATCH 18/35] remove whitespace in line 35 and 36 --- plugins/modules/proxmox_backup_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 6b5882b962b..3acee284135 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -32,8 +32,8 @@ required: false type: int backup_jobs: - description: - - The backup_jobs value is true or false. + description: + - The backup_jobs value is true or false. - If set to true, this module just return all backup jobs information. - If set to false, what is listed depends on the other options. required: false From 68abb06857b490192a11db84504100da4d8c6f72 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Tue, 31 Dec 2024 11:45:16 +0330 Subject: [PATCH 19/35] improve descriptions --- plugins/modules/proxmox_backup_info.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 3acee284135..9d8a5cea894 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -24,18 +24,22 @@ options: vm_name: - description: The name of the Proxmox VM. + description: + - The name of the Proxmox VM. + - If vm_name is defined, the returned list will contain backup jobs that have been parsed and filtered based on vm_name value. required: false type: str vm_id: - description: The ID of the Proxmox VM. + description: + - The ID of the Proxmox VM. + - If vm_id is defined, the returned list will contain backup jobs that have been parsed and filtered based on vm_id value. required: false type: int backup_jobs: description: - The backup_jobs value is true or false. - - If set to true, this module just return all backup jobs information. - - If set to false, what is listed depends on the other options. + - If V(true), the module will return all backup jobs information. + - If V(false), the module will parse all backup jobs based on VM IDs and return a list of VMs' backup information. required: false default: false type: bool From 61d475a5045f810d8d5532d839bc88ff0e3df0c2 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Tue, 31 Dec 2024 12:30:14 +0330 Subject: [PATCH 20/35] check again proxmox_backup_info.py module From 7323293f3d7d44d2d177128bf47ac4ae85d7abb5 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 5 Jan 2025 11:35:52 +0330 Subject: [PATCH 21/35] change vmid type and some descriptions proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 44 ++++++++++++++------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 9d8a5cea894..ab237898e04 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -15,6 +15,8 @@ short_description: Retrieve information on Proxmox scheduled backups +version_added: 10.3.0 + description: - Retrieve information such as backup times, VM name, VM ID, mode, backup type, and backup schedule using the Proxmox Server API. @@ -26,18 +28,17 @@ vm_name: description: - The name of the Proxmox VM. - - If vm_name is defined, the returned list will contain backup jobs that have been parsed and filtered based on vm_name value. + - If defined, the returned list will contain backup jobs that have been parsed and filtered based on O(vm_name) value. required: false type: str vm_id: description: - The ID of the Proxmox VM. - - If vm_id is defined, the returned list will contain backup jobs that have been parsed and filtered based on vm_id value. + - If defined, the returned list will contain backup jobs that have been parsed and filtered based on O(vm_id) value. required: false - type: int + type: str backup_jobs: description: - - The backup_jobs value is true or false. - If V(true), the module will return all backup jobs information. - If V(false), the module will parse all backup jobs based on VM IDs and return a list of VMs' backup information. required: false @@ -93,7 +94,7 @@ returned: on success type: str enabled: - description: 1 if backup is enabled else 0. + description: V(1) if backup is enabled else V(0). returned: on success type: int id: @@ -123,7 +124,7 @@ vmid: description: The VM vmid. returned: on success - type: int + type: str """ from datetime import datetime @@ -135,7 +136,7 @@ class ProxmoxBackupInfoAnsible(ProxmoxAnsible): # Get all backup information - def getJobsList(self): + def get_Jobs_List(self): try: backupJobs = self.proxmox_api.cluster.backup.get() except Exception as e: @@ -143,7 +144,7 @@ def getJobsList(self): return backupJobs # Get VM information - def getVmsList(self): + def get_Vms_List(self): try: vms = self.proxmox_api.cluster.resources.get(type='vm') except Exception as e: @@ -151,9 +152,9 @@ def getVmsList(self): return vms # Get all backup information by VM id and VM name - def vmsBackupInfo(self): - backupList = self.getJobsList() - vmInfo = self.getVmsList() + def vms_Backup_Info(self): + backupList = self.get_Jobs_List() + vmInfo = self.get_Vms_List() bkInfo = [] for backupItem in backupList: nextrun = datetime.fromtimestamp(backupItem['next-run']) @@ -176,11 +177,12 @@ def vmsBackupInfo(self): return bkInfo # Get proxmox backup information for a specific VM based on its VM id or VM name - def specificVmBackupInfo(self, vm_name_id): - fullBackupInfo = self.vmsBackupInfo() + def specific_VmBackup_Info(self, vm_name_id): + fullBackupInfo = self.vms_Backup_Info() vmBackupJobs = [] for vm in fullBackupInfo: - if (vm["vm_name"] == vm_name_id or int(vm["vmid"]) == vm_name_id): + #if (vm["vm_name"] == vm_name_id or int(vm["vmid"]) == vm_name_id): + if (vm["vm_name"] == vm_name_id or vm["vmid"] == vm_name_id): vmBackupJobs.append(vm) return vmBackupJobs @@ -189,9 +191,9 @@ def main(): # Define module args args = proxmox_auth_argument_spec() backup_info_args = dict( - vm_id=dict(type='int', required=False), - vm_name=dict(type='str', required=False), - backup_jobs=dict(type='bool', default=False, required=False) + vm_id=dict(type='str'), + vm_name=dict(type='str'), + backup_jobs=dict(type='bool', default=False) ) args.update(backup_info_args) @@ -218,13 +220,13 @@ def main(): # Update result value based on what requested (module args) if backup_jobs: - result['backup_info'] = proxmox.getJobsList() + result['backup_info'] = proxmox.get_Jobs_List() elif vm_id: - result['backup_info'] = proxmox.specificVmBackupInfo(vm_id) + result['backup_info'] = proxmox.specific_VmBackup_Info(vm_id) elif vm_name: - result['backup_info'] = proxmox.specificVmBackupInfo(vm_name) + result['backup_info'] = proxmox.specific_VmBackup_Info(vm_name) else: - result['backup_info'] = proxmox.vmsBackupInfo() + result['backup_info'] = proxmox.vms_Backup_Info() # Return result value module.exit_json(**result) From e981db4a102c7364c0a1109f1557a656af791546 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 5 Jan 2025 11:57:31 +0330 Subject: [PATCH 22/35] delete comment #if ... --- plugins/modules/proxmox_backup_info.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index ab237898e04..ef6cbe8c3ed 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -180,8 +180,7 @@ def vms_Backup_Info(self): def specific_VmBackup_Info(self, vm_name_id): fullBackupInfo = self.vms_Backup_Info() vmBackupJobs = [] - for vm in fullBackupInfo: - #if (vm["vm_name"] == vm_name_id or int(vm["vmid"]) == vm_name_id): + for vm in fullBackupInfo: if (vm["vm_name"] == vm_name_id or vm["vmid"] == vm_name_id): vmBackupJobs.append(vm) return vmBackupJobs From 2b99f17f0acdbacb6bf159fc2307b955daad07a2 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 5 Jan 2025 12:13:01 +0330 Subject: [PATCH 23/35] solve trailing whitespace error --- plugins/modules/proxmox_backup_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index ef6cbe8c3ed..1a4c902cbc2 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -180,7 +180,7 @@ def vms_Backup_Info(self): def specific_VmBackup_Info(self, vm_name_id): fullBackupInfo = self.vms_Backup_Info() vmBackupJobs = [] - for vm in fullBackupInfo: + for vm in fullBackupInfo: if (vm["vm_name"] == vm_name_id or vm["vmid"] == vm_name_id): vmBackupJobs.append(vm) return vmBackupJobs From 4cfb923098690741da8811c642a58c160ab82d2a Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Tue, 7 Jan 2025 09:27:14 +0330 Subject: [PATCH 24/35] Update the name of the functions --- plugins/modules/proxmox_backup_info.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 1a4c902cbc2..3bcb0f74517 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -136,7 +136,7 @@ class ProxmoxBackupInfoAnsible(ProxmoxAnsible): # Get all backup information - def get_Jobs_List(self): + def get_jobs_list(self): try: backupJobs = self.proxmox_api.cluster.backup.get() except Exception as e: @@ -144,7 +144,7 @@ def get_Jobs_List(self): return backupJobs # Get VM information - def get_Vms_List(self): + def get_vms_list(self): try: vms = self.proxmox_api.cluster.resources.get(type='vm') except Exception as e: @@ -152,9 +152,9 @@ def get_Vms_List(self): return vms # Get all backup information by VM id and VM name - def vms_Backup_Info(self): - backupList = self.get_Jobs_List() - vmInfo = self.get_Vms_List() + def vms_backup_info(self): + backupList = self.get_jobs_list() + vmInfo = self.get_vms_list() bkInfo = [] for backupItem in backupList: nextrun = datetime.fromtimestamp(backupItem['next-run']) @@ -177,8 +177,8 @@ def vms_Backup_Info(self): return bkInfo # Get proxmox backup information for a specific VM based on its VM id or VM name - def specific_VmBackup_Info(self, vm_name_id): - fullBackupInfo = self.vms_Backup_Info() + def specific_vmbackup_info(self, vm_name_id): + fullBackupInfo = self.vms_backup_info() vmBackupJobs = [] for vm in fullBackupInfo: if (vm["vm_name"] == vm_name_id or vm["vmid"] == vm_name_id): @@ -219,13 +219,13 @@ def main(): # Update result value based on what requested (module args) if backup_jobs: - result['backup_info'] = proxmox.get_Jobs_List() + result['backup_info'] = proxmox.get_jobs_list() elif vm_id: - result['backup_info'] = proxmox.specific_VmBackup_Info(vm_id) + result['backup_info'] = proxmox.specific_vmbackup_info(vm_id) elif vm_name: - result['backup_info'] = proxmox.specific_VmBackup_Info(vm_name) + result['backup_info'] = proxmox.specific_vmbackup_info(vm_name) else: - result['backup_info'] = proxmox.vms_Backup_Info() + result['backup_info'] = proxmox.vms_backup_info() # Return result value module.exit_json(**result) From f8e18c32122fa7ac46f4b88e87b0bf71d985b8fc Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 12 Jan 2025 11:12:37 +0330 Subject: [PATCH 25/35] Update proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 31 ++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 3bcb0f74517..b86e42da3df 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -27,20 +27,23 @@ options: vm_name: description: - - The name of the Proxmox VM. + - The name of the Proxmox VM. - If defined, the returned list will contain backup jobs that have been parsed and filtered based on O(vm_name) value. + - Mutually exclusive with O(vm_id) and O(backup_jobs). required: false type: str vm_id: description: - The ID of the Proxmox VM. - If defined, the returned list will contain backup jobs that have been parsed and filtered based on O(vm_id) value. + - Mutually exclusive with O(vm_name) and O(backup_jobs). required: false type: str backup_jobs: description: - If V(true), the module will return all backup jobs information. - If V(false), the module will parse all backup jobs based on VM IDs and return a list of VMs' backup information. + - Mutually exclusive with O(vm_id) and O(vm_name). required: false default: false type: bool @@ -61,24 +64,24 @@ - name: Print proxmox backup information for a specific VM based on its name proxmox_backup_info: - api_user: 'myUser@pam' - api_password: '*******' - api_host: '192.168.20.20' - vm_name: 'mailsrv' + api_user: 'myUser@pam' + api_password: '*******' + api_host: '192.168.20.20' + vm_name: 'mailsrv' - name: Print proxmox backup information for a specific VM based on its VM id proxmox_backup_info: - api_user: 'myUser@pam' - api_password: '*******' - api_host: '192.168.20.20' - vm_id: '150' + api_user: 'myUser@pam' + api_password: '*******' + api_host: '192.168.20.20' + vm_id: '150' - name: Print proxmox all backup job information proxmox_backup_info: - api_user: 'myUser@pam' - api_password: '*******' - api_host: '192.168.20.20' - backup_jobs: true + api_user: 'myUser@pam' + api_password: '*******' + api_host: '192.168.20.20' + backup_jobs: true """ RETURN = """ @@ -122,7 +125,7 @@ returned: on success type: str vmid: - description: The VM vmid. + description: The VM id. returned: on success type: str """ From 64bac842372a92a5cd8b5724b05754e4e4c01dc3 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Sun, 12 Jan 2025 11:42:07 +0330 Subject: [PATCH 26/35] Update proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index b86e42da3df..1dd982d8234 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -27,7 +27,7 @@ options: vm_name: description: - - The name of the Proxmox VM. + - The name of the Proxmox VM. - If defined, the returned list will contain backup jobs that have been parsed and filtered based on O(vm_name) value. - Mutually exclusive with O(vm_id) and O(backup_jobs). required: false From 62f4e9fb72324e1c35920e998fbf6b6b698669b0 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 13 Jan 2025 08:24:34 +0330 Subject: [PATCH 27/35] Update tests/unit/plugins/modules/test_proxmox_backup_info.py Co-authored-by: Felix Fontein --- tests/unit/plugins/modules/test_proxmox_backup_info.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/unit/plugins/modules/test_proxmox_backup_info.py b/tests/unit/plugins/modules/test_proxmox_backup_info.py index 27cc7b594ed..ad39580cf5d 100644 --- a/tests/unit/plugins/modules/test_proxmox_backup_info.py +++ b/tests/unit/plugins/modules/test_proxmox_backup_info.py @@ -13,10 +13,6 @@ import pytest proxmoxer = pytest.importorskip("proxmoxer") -mandatory_py_version = pytest.mark.skipif( - sys.version_info < (2, 7), - reason="The proxmoxer dependency requires python2.7 or higher", -) from ansible_collections.community.general.plugins.modules import proxmox_backup_info from ansible_collections.community.general.tests.unit.compat.mock import patch From 181da99b596f5399f83e1b75bf4d1dd2ab221ee5 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 13 Jan 2025 08:31:15 +0330 Subject: [PATCH 28/35] Update test_proxmox_backup_info.py --- tests/unit/plugins/modules/test_proxmox_backup_info.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/plugins/modules/test_proxmox_backup_info.py b/tests/unit/plugins/modules/test_proxmox_backup_info.py index ad39580cf5d..73a15b8ab83 100644 --- a/tests/unit/plugins/modules/test_proxmox_backup_info.py +++ b/tests/unit/plugins/modules/test_proxmox_backup_info.py @@ -9,7 +9,6 @@ __metaclass__ = type -import sys import pytest proxmoxer = pytest.importorskip("proxmoxer") From dc15fbefb5fd7d1981a58fa178130ddfbb0908bd Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:52:09 +0330 Subject: [PATCH 29/35] Update runtime.yml --- meta/runtime.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/meta/runtime.yml b/meta/runtime.yml index 12c026b5bbd..aefc2b57cca 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -18,6 +18,7 @@ action_groups: - proxmox - proxmox_backup - proxmox_backup_info + - proxmox_backup_schedule - proxmox_disk - proxmox_domain_info - proxmox_group_info From e8fc1b04ac2c1f28db0aedaaaade7d6e905b6d0e Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:52:47 +0330 Subject: [PATCH 30/35] add proxmox_backup_schedule module in runtime.yml From eeeb27d3c88998bb0ca481c8a9f06e29934f20e8 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:55:55 +0330 Subject: [PATCH 31/35] add proxmox_backup_schedule.py module in BOTMETA.yml --- .github/BOTMETA.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index f25fab1096d..6cb0eb1be0e 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -1131,6 +1131,8 @@ files: maintainers: IamLunchbox $modules/proxmox_backup_info.py: maintainers: raoufnezhad mmayabi + $modules/proxmox_backup_schedule.py: + maintainers: raoufnezhad mmayabi $modules/proxmox_nic.py: maintainers: Kogelvis krauthosting $modules/proxmox_node_info.py: From 6b4498907a3914b31ce6e67056f11de4a6743374 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 13 Jan 2025 10:00:08 +0330 Subject: [PATCH 32/35] remove proxmox_backup_schedule module runtime.yml --- meta/runtime.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/meta/runtime.yml b/meta/runtime.yml index aefc2b57cca..0dff6eab2d7 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -17,8 +17,7 @@ action_groups: proxmox: - proxmox - proxmox_backup - - proxmox_backup_info - - proxmox_backup_schedule + - proxmox_backup_info - proxmox_disk - proxmox_domain_info - proxmox_group_info From 3ccbc64c5dc609895c1b8c1db3fe35cd39561e9f Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 13 Jan 2025 10:00:53 +0330 Subject: [PATCH 33/35] remove proxmox_backup_schedule.py module in BOTMETA.yml --- .github/BOTMETA.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index 6cb0eb1be0e..f25fab1096d 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -1131,8 +1131,6 @@ files: maintainers: IamLunchbox $modules/proxmox_backup_info.py: maintainers: raoufnezhad mmayabi - $modules/proxmox_backup_schedule.py: - maintainers: raoufnezhad mmayabi $modules/proxmox_nic.py: maintainers: Kogelvis krauthosting $modules/proxmox_node_info.py: From b129c4c839542b123e3f2723a61ab53ac53fc62f Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:13:59 +0330 Subject: [PATCH 34/35] change some id to ID proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 1dd982d8234..92683bc2f44 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -56,27 +56,27 @@ """ EXAMPLES = """ -- name: Print all backup information by VM id and VM name +- name: Print all backup information by VM ID and VM name. proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' -- name: Print proxmox backup information for a specific VM based on its name +- name: Print proxmox backup information for a specific VM based on its name. proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' vm_name: 'mailsrv' -- name: Print proxmox backup information for a specific VM based on its VM id +- name: Print proxmox backup information for a specific VM based on its VM ID. proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' vm_id: '150' -- name: Print proxmox all backup job information +- name: Print proxmox all backup job information. proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' @@ -101,7 +101,7 @@ returned: on success type: int id: - description: The backup job id. + description: The backup job ID. returned: on success type: str mode: @@ -125,7 +125,7 @@ returned: on success type: str vmid: - description: The VM id. + description: The VM ID. returned: on success type: str """ @@ -154,7 +154,7 @@ def get_vms_list(self): self.module.fail_json(msg="Getting VMs info from cluster failed: %s" % e) return vms - # Get all backup information by VM id and VM name + # Get all backup information by VM ID and VM name def vms_backup_info(self): backupList = self.get_jobs_list() vmInfo = self.get_vms_list() @@ -179,7 +179,7 @@ def vms_backup_info(self): bkInfo.append(bkInfoData) return bkInfo - # Get proxmox backup information for a specific VM based on its VM id or VM name + # Get proxmox backup information for a specific VM based on its VM ID or VM name def specific_vmbackup_info(self, vm_name_id): fullBackupInfo = self.vms_backup_info() vmBackupJobs = [] From 5d0ea04542ff314633c474ef56d0c5164c9af8e1 Mon Sep 17 00:00:00 2001 From: raoufnezhad <72685312+raoufnezhad@users.noreply.github.com> Date: Mon, 20 Jan 2025 09:30:11 +0330 Subject: [PATCH 35/35] Update proxmox_backup_info.py --- plugins/modules/proxmox_backup_info.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/modules/proxmox_backup_info.py b/plugins/modules/proxmox_backup_info.py index 92683bc2f44..29531e9d7c0 100644 --- a/plugins/modules/proxmox_backup_info.py +++ b/plugins/modules/proxmox_backup_info.py @@ -56,28 +56,28 @@ """ EXAMPLES = """ -- name: Print all backup information by VM ID and VM name. - proxmox_backup_info: +- name: Print all backup information by VM ID and VM name + community.general.proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' -- name: Print proxmox backup information for a specific VM based on its name. - proxmox_backup_info: +- name: Print Proxmox backup information for a specific VM based on its name + community.general.proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' vm_name: 'mailsrv' -- name: Print proxmox backup information for a specific VM based on its VM ID. - proxmox_backup_info: +- name: Print Proxmox backup information for a specific VM based on its VM ID + community.general.proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' vm_id: '150' -- name: Print proxmox all backup job information. - proxmox_backup_info: +- name: Print Proxmox all backup job information + community.general.proxmox_backup_info: api_user: 'myUser@pam' api_password: '*******' api_host: '192.168.20.20' @@ -88,7 +88,7 @@ --- backup_info: description: The return value provides backup job information based on VM ID or VM name, or total backup job information. - returned: always, but can be empty + returned: on success, but can be empty type: list elements: dict contains: