-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add module proxmox_backup_info #9437
base: main
Are you sure you want to change the base?
Conversation
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.
create test for proxmox_backup_info.py module
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @raoufnezhad thanks for your contribution!
I see you have adjustments to make for the sanity tests. If I may suggest, give it a try to andebox
(by yours truly):
https://pypi.org/project/andebox/
You can run this sanity test easily in your local machine by simply running:
$ andebox test -- sanity --docker default --python 3.10 plugins/modules/your_module.py
I left a couple of other comments below as well. Thanks again!
options: | ||
api_user: | ||
description: The user must have access to the proxmox server | ||
required: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use consistent indentation. Here you started with 4 spaces then used 2 in the next level. We have been trying to use 2 at all times, that's not mandatory, but consistency is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your attention.
description: The return value provided by proxmox_backup_info. | ||
type: dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That description does not mean much. Please be either more specific or add notes to the documentation block referring to Proxmox API, and/or the return values provided by proxmoxer.
If the result value is not too big nor complex, please consider declaring contains
block with a more finely grained level of details.
Co-authored-by: Alexei Znamensky <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this option means that if it is set to true
, then all backups for this 'section' (whatever that is, I don't know the proxmox terminology) will be listed. If set to false
, what is listed depends on the other options.
Is that correct? A description that's closer to the above might be more helpful.
elements: dict | ||
contains: | ||
bktype: | ||
description: backup type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The descriptions here also need to be full sentences.
description: backup type | |
description: The type of the backup. |
- 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required: false
is redundant, please remove it from both here and the argument_spec below.
Also, use semantic markup (such as V()
), and boolean parameters may have, by definition, only the values true
and false
, no need to mention that ;-).
- 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 | |
- Include backup jobs in the result. | |
- If V(true), this module just return all backup jobs information. | |
- If V(false), the result will not include backup jobs. |
Or something like that.
Semantic markup is documented in:
https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_documenting.html#semantic-markup-within-module-documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @raoufnezhad thanks again for your contribution!
There's a number of adjustments that need to be made. Please see below, feel free to question anything.
- 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the first line is redundant:
- 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. | |
- 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. |
With the other two it is already clear what the option does.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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. |
- "Marzieh Raoufnezhad (@raoufnezhad) <[email protected]>" | ||
- "Maryam Mayabi (@mmayabi) <[email protected]>" | ||
|
||
options: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options: | |
version_added: 10.3.0 | |
options: |
returned: on success | ||
type: str | ||
enabled: | ||
description: 1 if backup is enabled else 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: 1 if backup is enabled else 0. | |
description: V(1) if backup is enabled else V(0). |
vmid: | ||
description: The VM vmid. | ||
returned: on success | ||
type: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the Proxmox VMID can be an UUID, in which case it is not an int but a str. Could you please double check and confirm here? Thx
class ProxmoxBackupInfoAnsible(ProxmoxAnsible): | ||
|
||
# Get all backup information | ||
def getJobsList(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very pythonic. Please use:
def getJobsList(self): | |
def get_jobs_list(self): |
instead. Same for other methods and variables. Python only uses CamelCase in class names.
Personally, I would even remove the "list" part in the name, because if we are getting "jobs" (plural), I think it is clear that it is a list of them.
|
||
def test_get_specific_backup_information_by_vmid(self): | ||
with pytest.raises(AnsibleExitJson) as exc_info: | ||
vmid = "101" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The vmid
parameter is int, so this should be:
vmid = "101" | |
vmid = 101 |
def specificVmBackupInfo(self, vm_name_id): | ||
fullBackupInfo = self.vmsBackupInfo() | ||
vmBackupJobs = [] | ||
for vm in fullBackupInfo: | ||
if (vm["vm_name"] == vm_name_id or int(vm["vmid"]) == vm_name_id): | ||
vmBackupJobs.append(vm) | ||
return vmBackupJobs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is right. If vm_name_id="100"
(str), then int(vm["vmid"]) == vm_named_id
is always going to be False
, even then int(vm["vmid"]) == 100
.
>>> 3 == "3"
False
Additionally, there is the naming convention (camelCase vs. snake_case), and the more pythonic way of doing this would be:
def specificVmBackupInfo(self, vm_name_id): | |
fullBackupInfo = self.vmsBackupInfo() | |
vmBackupJobs = [] | |
for vm in fullBackupInfo: | |
if (vm["vm_name"] == vm_name_id or int(vm["vmid"]) == vm_name_id): | |
vmBackupJobs.append(vm) | |
return vmBackupJobs | |
return [vm for vm in full_backup_info if vm["vm_name"] == vm_name_id or int(vm["vmid"]) == vm_name_id] |
(it won't work like that because of the type issue mentioned above - needs adjustments)
Not goin to be a huge problem here, but from a performance point of view it is much better to do the test outside the loop than inside it.
if is int
return [... if vm[vmid] == param]
if is str
return [... if vm[name] == param]
Or, make two separate functions, one for the ID another for the name, which is cleaner to read, IMHO.
vm_id=dict(type='int', required=False), | ||
vm_name=dict(type='str', required=False), | ||
backup_jobs=dict(type='bool', default=False, required=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant
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='int'), | |
vm_name=dict(type='str'), | |
backup_jobs=dict(type='bool', default=False) |
SUMMARY
This contribution proposes to add a module called
proxmox_backup_info
to the Ansible community.general collection. The module would retrieve information about backups in a Proxmox VE cluster, allowing users to query and gather details about existing backups.ISSUE TYPE
COMPONENT NAME
proxmox_backup_info
ADDITIONAL INFORMATION
The module would use the Proxmox API to fetch information about backups in the cluster. It would allow users to specify parameters such as the API host, credentials, and optionally filter by VM ID, VM Name, or backup section. The result of the module would be a list of backups with details like backup type, backup id, mode, schedule, next-run time, storage, and associated VM.