Advertisement
Guest User

Untitled

a guest
Sep 9th, 2011
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. # From this point we have a VDI on Xen host;
  2. # If anything goes wrong, we need to remember its uuid.
  3. try:
  4. filename = None
  5. vdi_uuid = session.get_xenapi().VDI.get_uuid(vdi_ref)
  6. with_vdi_attached_here(session, vdi_ref, False,
  7. lambda dev:
  8. _stream_disk(dev, image_type,
  9. virtual_size, image_file))
  10. if image_type in (ImageType.KERNEL, ImageType.RAMDISK):
  11. # We need to invoke a plugin for copying the
  12. # content of the VDI into the proper path.
  13. LOG.debug(_("Copying VDI %s to /boot/guest on dom0"), vdi_ref)
  14. fn = "copy_kernel_vdi"
  15. args = {}
  16. args['vdi-ref'] = vdi_ref
  17. # Let the plugin copy the correct number of bytes.
  18. args['image-size'] = str(vdi_size)
  19. task = session.async_call_plugin('glance', fn, args)
  20. filename = session.wait_for_task(task, instance_id)
  21. # Remove the VDI as it is not needed anymore.
  22. session.get_xenapi().VDI.destroy(vdi_ref)
  23. LOG.debug(_("Kernel/Ramdisk VDI %s destroyed"), vdi_ref)
  24. return [dict(vdi_type=ImageType.to_string(image_type),
  25. vdi_uuid=None,
  26. file=filename)]
  27. else:
  28. return [dict(vdi_type=ImageType.to_string(image_type),
  29. vdi_uuid=vdi_uuid,
  30. file=None)]
  31. except (cls.XenAPI.Failure, IOError, OSError) as e:
  32. # We look for XenAPI and OS failures.
  33. LOG.exception(_("instance %s: Failed to fetch glance image"),
  34. instance_id, exc_info=sys.exc_info())
  35. e.args = e.args + ([dict(vdi_type=ImageType.
  36. to_string(image_type),
  37. vdi_uuid=vdi_uuid,
  38. file=filename)],)
  39. raise e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement