diff options
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}) |
