diff options
| author | Devdeep Singh <devdeep.singh@citrix.com> | 2012-01-17 18:59:14 +0530 |
|---|---|---|
| committer | Devdeep Singh <devdeep.singh@citrix.com> | 2012-02-13 09:31:01 +0530 |
| commit | 6c3bc216c1f35c42604b685eebd8fa25828d0e0e (patch) | |
| tree | 5a8f6bd6bd65553c70a4e1e0a5e3b00883a81153 /plugins | |
| parent | d8f8bad0f26b4438986ab1a469d89d03b22551db (diff) | |
| download | nova-6c3bc216c1f35c42604b685eebd8fa25828d0e0e.tar.gz nova-6c3bc216c1f35c42604b685eebd8fa25828d0e0e.tar.xz nova-6c3bc216c1f35c42604b685eebd8fa25828d0e0e.zip | |
Changes for supporting fast cloning on Xenserver.
Implements blueprint fast-cloning-for-xenserver
1. use_cow_images flag is reused for xenserver to check if copy on write images should be used.
2. image-id is used to tag an image which has already been streamed from glance.
3. If cow is true, when an instance of an image is created for the first time on a given xenserver, the image is streamed from glance and copy on write disk is created for the instance.
4. For subsequent instance creation requests (of the same image), a copy on write disk is created from the base image that is already present on the host.
5. If cow is false, when an instance of an image is created for the first time on a host, the image is streamed from glance and its copy is made to create a virtual disk for the instance.
6. For subsequent instance creation requests, a copy of disk is made for creating the disk for the instance.
7. Snapshot creation code was updated to handle cow=true. Now there can be upto 3 disks in the chain. The base disk needs to be uploaded too.
8. Also added a cache_images flag. Depending on whether the flag is turned on on not, images will be cached on the host.
Change-Id: I54838a24b061c134877f3479c925c6ee78da14bc
Diffstat (limited to 'plugins')
| -rwxr-xr-x | plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index e53e4d5eb..35f60923c 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -54,6 +54,7 @@ class RetryException(Exception): def _copy_kernel_vdi(dest, copy_args): vdi_uuid = copy_args['vdi_uuid'] vdi_size = copy_args['vdi_size'] + cached_image = copy_args['cached-image'] logging.debug("copying kernel/ramdisk file from %s to /boot/guest/%s", dest, vdi_uuid) filename = KERNEL_DIR + '/' + vdi_uuid @@ -67,6 +68,17 @@ def _copy_kernel_vdi(dest, copy_args): #copy only vdi_size bytes data = f.read(vdi_size) of.write(data) + if cached_image: + #create a cache file. If caching is enabled, kernel images do not have + #to be fetched from glance. + cached_image = KERNEL_DIR + '/' + cached_image + logging.debug("copying kernel/ramdisk file from %s to /boot/guest/%s", + dest, cached_image) + cache_file = open(cached_image, 'wb') + cache_file.write(data) + cache_file.close() + logging.debug("Done. Filename: %s", cached_image) + f.close() of.close() logging.debug("Done. Filename: %s", filename) @@ -264,11 +276,17 @@ def _import_vhds(sr_path, staging_path, uuid_stack): vdi_return_list = [] paths_to_move = [] - image_info = prepare_if_exists(staging_path, 'image.vhd') + image_parent = None + base_info = prepare_if_exists(staging_path, 'base.vhd') + if base_info: + paths_to_move.append(base_info[0]) + image_parent = base_info[0] + + image_info = prepare_if_exists(staging_path, 'image.vhd', image_parent) if not image_info: raise Exception("Invalid image: image.vhd not present") - paths_to_move.append(image_info[0]) + paths_to_move.insert(0, image_info[0]) snap_info = prepare_if_exists(staging_path, 'snap.vhd', image_info[0]) @@ -302,9 +320,10 @@ def _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids): ('snap' or 'image.vhd') """ for name, uuid in vdi_uuids.items(): - source = os.path.join(sr_path, "%s.vhd" % uuid) - link_name = os.path.join(staging_path, "%s.vhd" % name) - os.link(source, link_name) + if uuid: + source = os.path.join(sr_path, "%s.vhd" % uuid) + link_name = os.path.join(staging_path, "%s.vhd" % name) + os.link(source, link_name) def _upload_tarball(staging_path, image_id, glance_host, glance_port, @@ -439,6 +458,24 @@ def _finish_subprocess(proc, cmdline): return out, err +def create_kernel_ramdisk(session, args): + """Creates a copy of the kernel/ramdisk image if it is present in the + cache. If the image is not present in the cache, it does nothing. + """ + cached_image = exists(args, 'cached-image') + image_uuid = exists(args, 'new-image-uuid') + cached_image_filename = KERNEL_DIR + '/' + cached_image + filename = KERNEL_DIR + '/' + image_uuid + + if os.path.isfile(cached_image_filename): + shutil.copyfile(cached_image_filename, filename) + logging.debug("Done. Filename: %s", filename) + else: + filename = "" + logging.debug("Cached kernel/ramdisk image not found") + return filename + + def download_vhd(session, args): """Download an image from Glance, unbundle it, and then deposit the VHDs into the storage repository @@ -491,9 +528,12 @@ def upload_vhd(session, args): def copy_kernel_vdi(session, args): vdi = exists(args, 'vdi-ref') size = exists(args, 'image-size') + cached_image = optional(args, 'cached-image') #Use the uuid as a filename vdi_uuid = session.xenapi.VDI.get_uuid(vdi) - copy_args = {'vdi_uuid': vdi_uuid, 'vdi_size': int(size)} + copy_args = {'vdi_uuid': vdi_uuid, + 'vdi_size': int(size), + 'cached-image': cached_image} filename = with_vdi_in_dom0(session, vdi, False, lambda dev: _copy_kernel_vdi('/dev/%s' % dev, copy_args)) @@ -515,4 +555,5 @@ if __name__ == '__main__': XenAPIPlugin.dispatch({'upload_vhd': upload_vhd, 'download_vhd': download_vhd, 'copy_kernel_vdi': copy_kernel_vdi, + 'create_kernel_ramdisk': create_kernel_ramdisk, 'remove_kernel_ramdisk': remove_kernel_ramdisk}) |
