-
Notifications
You must be signed in to change notification settings - Fork 54
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
Added disk selection and exclusion of deactivated disks #87
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -107,6 +107,26 @@ def create_argparser(): | |||||||
default=None, | ||||||||
) | ||||||||
|
||||||||
dsk = p.add_argument_group("VM's disks arguments") | ||||||||
dsk.add_argument( | ||||||||
"--bootable_only", | ||||||||
help="Backup Bootable Disk Only", | ||||||||
dest="bootable_only", | ||||||||
default=None, | ||||||||
) | ||||||||
dsk.add_argument( | ||||||||
"--with_disks_deactivated", | ||||||||
help="Backup deactivated disks", | ||||||||
dest="with_disks_deactivated", | ||||||||
default=None, | ||||||||
) | ||||||||
dsk.add_argument( | ||||||||
"--disks_id_exclude", | ||||||||
help="an array of exclude disks id", | ||||||||
dest="disks_id_exclude", | ||||||||
default=None, | ||||||||
) | ||||||||
|
||||||||
dcg = p.add_argument_group("Data Centre's related options") | ||||||||
dcg.add_argument( | ||||||||
"--export-domain", | ||||||||
|
@@ -333,6 +353,32 @@ def main(argv): | |||||||
|
||||||||
vm = vm[0] | ||||||||
|
||||||||
# Get the Attachments Disk | ||||||||
disk_attachments = vms_service.vm_service(vm.id).disk_attachments_service().list() | ||||||||
disksBackup = [] | ||||||||
BootableOnly = config.get_bootable_only() | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here ^^
Suggested change
|
||||||||
for disk_attachment in disk_attachments: | ||||||||
if BootableOnly: | ||||||||
if disk_attachment.bootable == True: | ||||||||
disksBackup.append(disk_attachment) | ||||||||
break | ||||||||
elif config.get_with_disks_deactivated() or disk_attachment.active: | ||||||||
disksBackup.append(disk_attachment) | ||||||||
|
||||||||
if not BootableOnly: | ||||||||
disks_id_exclude=config.get_disks_id_exclude() | ||||||||
if disks_id_exclude: | ||||||||
disksBackup = [disk for disk in disksBackup if disk.id not in disks_id_exclude] | ||||||||
|
||||||||
for disk_attachment in disksBackup: | ||||||||
if disk_attachment.bootable == True: | ||||||||
logger.info("Finding bootable disk: %s", disk_attachment.id) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it will be better to use the new python3 format like:
Suggested change
IMHO it looks better and more readable. |
||||||||
else: | ||||||||
logger.info("Finding disk: %s", disk_attachment.id) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same ^^
Suggested change
|
||||||||
# print disk_attachment.id | ||||||||
# break | ||||||||
# print disks_id[0].__dict__ | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this code is not necessary maybe you can remove it
Suggested change
|
||||||||
|
||||||||
# Delete old backup snapshots | ||||||||
VMTools.delete_snapshots(api, vm, config, vm_from_list) | ||||||||
|
||||||||
|
@@ -349,6 +395,7 @@ def main(argv): | |||||||
types.Snapshot( | ||||||||
description=config.get_snapshot_description(), | ||||||||
persist_memorystate=config.get_persist_memorystate(), | ||||||||
disk_attachments=disksBackup, | ||||||||
), | ||||||||
) | ||||||||
VMTools.wait_for_snapshot_operation(api, vm, config, "creation") | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -86,3 +86,12 @@ logger_file_path= | |||||
|
||||||
# If this value is True, the VM is being paused during snapshot creation. | ||||||
persist_memorystate=False | ||||||
|
||||||
# Backup Bootable Disk Only | ||||||
bootable_only=False | ||||||
|
||||||
# Backup deactivated disks, set to False to skip deactivated disks backup (Recommend). | ||||||
# This True - causes an error deleting a snapshot of the VM when the state is on. | ||||||
with_disks_deactivated=False | ||||||
# an array of exclude disks id,exampel ["6d811aa25-52a1-45c3-9f40-1c7c868182c9","6e78d7c2-5786-4dz2-a966-fd308c23f08e"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo
Suggested change
|
||||||
disks_id_exclude: [] |
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 the python convention
https://peps.python.org/pep-0008/#function-and-variable-names
like: