-
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
create new proxmox_backup_schedule module #9592
base: main
Are you sure you want to change the base?
Conversation
@raoufnezhad this PR contains the following merge commits: Please rebase your branch to remove these commits. |
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
There is a number of comments - some changes that must be done, others are just suggestions, and others I am trying to understand what's going on.
--- | ||
module: proxmox_backup_schedule | ||
|
||
short_description: Scheduling VM Backups and Removing it. |
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.
short_description: Scheduling VM Backups and Removing it. | |
short_description: Scheduling VM backups and removing them |
|
||
version_added: 10.3.0 | ||
|
||
description: The proxmox_backup_schedule module modify backup jobs such as set or delete vmid. |
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: The proxmox_backup_schedule module modify backup jobs such as set or delete vmid. | |
description: The module modifies backup jobs such as set or delete C(vmid). |
backup_action: | ||
description: | ||
- If V(update_vmid), the module will update backup job with new VM ID. | ||
- If V(delete_vmid), the module will remove the VM ID from all backup jobs where the VM ID has existed. | ||
required: true | ||
type: str |
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 only these two options are valid, make them choices
. Also a little fix on the indentation:
backup_action: | |
description: | |
- If V(update_vmid), the module will update backup job with new VM ID. | |
- If V(delete_vmid), the module will remove the VM ID from all backup jobs where the VM ID has existed. | |
required: true | |
type: str | |
backup_action: | |
description: | |
- If V(update_vmid), the module will update backup job with new VM ID. | |
- If V(delete_vmid), the module will remove the VM ID from all backup jobs where the VM ID has existed. | |
required: true | |
choices: [update_vmid, delete_vmid] | |
type: str |
description: The backup job ID. | ||
required: false | ||
type: str | ||
backup_action: |
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 kind of parameter that controls the action being taken by the module, in Ansible is usually named state
. I do not see that as mandatory, but you might want to consider it.
if vm_id in vms_id: | ||
bksetInfo = [] | ||
return bksetInfo | ||
else: | ||
bk_id_vmids = bk_id_info['vmid'] + ',' + str(vm_id) | ||
self.set_vmid_backup(backup_id, bk_id_vmids) | ||
return 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.
This seems odd: if vm_id is in the list it returns a (empty) list object, else it returns a boolean object (True). The return type of the method should be consistent.
backup_schedule: | ||
description: | ||
- If V(update_vmid), the backup_schedule will return True after adding the VM ID to the backup job. | ||
- If V(delete_vmid), the backup_schedule will return a list of backup job IDs where the VM ID has existed after removing it. | ||
returned: always, but can be empty | ||
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.
Firstly, not a good idea to have a RV that results in different types - trust me, I have done that, and still needs fixing (module xfconf).
Secondly, you are declaring the type as dict
, which neither of the returned values are.
I would suggest you make two different RVs, one for the update case, another for the delete case, then make them of the right type.
if vm_name: | ||
vm_id = proxmox.vmname_2_vmid(vm_name) | ||
|
||
if (backup_action == 'update_vmid'): |
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:
if (backup_action == 'update_vmid'): | |
if backup_action == 'update_vmid': |
if (backup_action == 'update_vmid'): | ||
result['backup_schedule'] = proxmox.backup_update_vmid(vm_id, backup_id) | ||
|
||
if (backup_action == 'delete_vmid'): |
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:
if (backup_action == 'delete_vmid'): | |
if backup_action == 'delete_vmid': |
for backupItem in backupList: | ||
vmids = list(backupItem['vmid'].split(',')) | ||
if vm_id in vmids: | ||
if len(vmids) > 1 : |
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 len(vmids) > 1 : | |
if len(vmids) > 1: |
@felixfontein I would have thought this was something the validation would pick up. Any thoughts on that?
description: | ||
- The name of the Proxmox VM. | ||
- Mutually exclusive with O(vm_id). | ||
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.
please remove the required: false
from the docs, it is redundant
SUMMARY
This contribution proposes to add a module called proxmox_backup_schedule to the Ansible community.general collection. The module would schedule VM backups and removing it in a Proxmox VE cluster.
ISSUE TYPE
New Module/Plugin Pull Request
COMPONENT NAME
proxmox_backup_schedule
ADDITIONAL INFORMATION
The proxmox_backup_schedule module modify backup jobs such as set or delete vmid.