Skip to content
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

Fixed attach disk before create snapshots and other minor bug #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion sdk/examples/upload_disk_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def create_disk(image_info, disk_id, sd_name, disks_service):
format=types.DiskFormat.RAW,
provisioned_size=provisioned_size,
initial_size=initial_size,
# sparse=False, # In case of iSCSI Storage discomment this.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sparse=True is valid when using qcow2 format, which is the only format supported
for snapshots.

Only raw=sparse is not supported for block storage domains (FC, iSCSI)

storage_domains=[
types.StorageDomain(
name=sd_name
Expand Down Expand Up @@ -300,7 +301,7 @@ def get_images_chain(disk_path):
vms_service = system_service.vms_service()

# Get images chain (snapshots)
images_chain = get_images_chain(disk_path)
images_chain = get_images_chain(os.path.dirname(disk_path))

try:
# Create disk by base volume info
Expand All @@ -316,6 +317,18 @@ def get_images_chain(disk_path):
# Locate VM service
vm_service = vms_service.vm_service(vmId)

# Attach disk to vm
vm_service.disk_attachments_service().add(
types.DiskAttachment(
disk=disk,
interface=types.DiskInterface.VIRTIO,
bootable=False,
active=True,
)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

# We waited until OK for it when we created the disk. We wait 5s for security
time.sleep(5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is sleep needed? how is it relevant for security?


# Creating a snapshot for each image
for image in images_chain[1:]:
image_id = os.path.basename(image['filename'])
Expand Down