summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-02-14 03:38:14 +0000
committerGerrit Code Review <review@openstack.org>2012-02-14 03:38:14 +0000
commitca51f9822f5ac9d66e0454cdbcb8ac17a416958b (patch)
treeefeeca6bb73b76f4bdcf95152070cd86c80e4622 /plugins
parent14b79e78176b84f25ae666e9352041905fe8289e (diff)
parent6c3bc216c1f35c42604b685eebd8fa25828d0e0e (diff)
downloadnova-ca51f9822f5ac9d66e0454cdbcb8ac17a416958b.tar.gz
nova-ca51f9822f5ac9d66e0454cdbcb8ac17a416958b.tar.xz
nova-ca51f9822f5ac9d66e0454cdbcb8ac17a416958b.zip
Merge "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."
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/xenserver/xenapi/etc/xapi.d/plugins/glance53
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})