Can now correctly launch images with external kernels through glance.
Further tests and Pep8 fixes to come.
This commit is contained in:
@@ -52,7 +52,7 @@ XENAPI_POWER_STATE = {
|
||||
SECTOR_SIZE = 512
|
||||
MBR_SIZE_SECTORS = 63
|
||||
MBR_SIZE_BYTES = MBR_SIZE_SECTORS * SECTOR_SIZE
|
||||
|
||||
KERNEL_DIR = '/boot/guest'
|
||||
|
||||
class ImageType:
|
||||
"""
|
||||
@@ -299,7 +299,7 @@ class VMHelper(HelperBase):
|
||||
access, type)
|
||||
|
||||
@classmethod
|
||||
def _fetch_image_glance(cls, session, instance_id, image, access, typ):
|
||||
def _fetch_image_glance(cls, session, instance_id, image, access, type):
|
||||
sr = find_sr(session)
|
||||
if sr is None:
|
||||
raise exception.NotFound('Cannot find SR to write VDI to')
|
||||
@@ -310,7 +310,8 @@ class VMHelper(HelperBase):
|
||||
virtual_size = int(meta['size'])
|
||||
|
||||
vdi_size = virtual_size
|
||||
if typ == ImageType.DISK:
|
||||
logging.debug("Size for image %s:%d",image,virtual_size)
|
||||
if type == ImageType.DISK:
|
||||
# Make room for MBR.
|
||||
vdi_size += MBR_SIZE_BYTES
|
||||
|
||||
@@ -319,7 +320,7 @@ class VMHelper(HelperBase):
|
||||
|
||||
def stream(dev):
|
||||
offset = 0
|
||||
if typ == ImageType.DISK:
|
||||
if type == ImageType.DISK:
|
||||
offset = MBR_SIZE_BYTES
|
||||
_write_partition(virtual_size, dev)
|
||||
|
||||
@@ -329,7 +330,18 @@ class VMHelper(HelperBase):
|
||||
f.write(chunk)
|
||||
|
||||
with_vdi_attached_here(session, vdi, False, stream)
|
||||
return session.get_xenapi().VDI.get_uuid(vdi)
|
||||
if (type==ImageType.KERNEL_RAMDISK):
|
||||
#we need to invoke a plugin for copying VDI's content into proper path
|
||||
fn = "copy_kernel_vdi"
|
||||
args = {}
|
||||
args['vdi-ref'] = vdi
|
||||
args['image-size']=str(vdi_size)
|
||||
task = session.async_call_plugin('glance', fn, args)
|
||||
filename=session.wait_for_task(instance_id,task)
|
||||
#TODO(salvatore-orlando): remove the VDI as it is not needed anymore
|
||||
return filename
|
||||
else:
|
||||
return session.get_xenapi().VDI.get_uuid(vdi)
|
||||
|
||||
@classmethod
|
||||
def _fetch_image_objectstore(cls, session, instance_id, image, access,
|
||||
@@ -364,7 +376,6 @@ class VMHelper(HelperBase):
|
||||
fn = "is_vdi_pv"
|
||||
args = {}
|
||||
args['vdi-ref'] = vdi_ref
|
||||
#TODO: Call proper function in plugin
|
||||
task = session.async_call_plugin('objectstore', fn, args)
|
||||
pv_str = session.wait_for_task(task)
|
||||
if pv_str.lower() == 'true':
|
||||
|
||||
@@ -40,8 +40,35 @@ from pluginlib_nova import *
|
||||
configure_logging('glance')
|
||||
|
||||
CHUNK_SIZE = 8192
|
||||
KERNEL_DIR = '/boot/guest'
|
||||
FILE_SR_PATH = '/var/run/sr-mount'
|
||||
|
||||
def copy_kernel_vdi(session,args):
|
||||
vdi = exists(args, 'vdi-ref')
|
||||
size = exists(args,'image-size')
|
||||
#Use the uuid as a filename
|
||||
vdi_uuid=session.xenapi.VDI.get_uuid(vdi)
|
||||
copy_args={'vdi_uuid':vdi_uuid,'vdi_size':int(size)}
|
||||
filename=with_vdi_in_dom0(session, vdi, False,
|
||||
lambda dev:
|
||||
_copy_kernel_vdi('/dev/%s' % dev,copy_args))
|
||||
return filename
|
||||
|
||||
def _copy_kernel_vdi(dest,copy_args):
|
||||
vdi_uuid=copy_args['vdi_uuid']
|
||||
vdi_size=copy_args['vdi_size']
|
||||
logging.debug("copying kernel/ramdisk file from %s to /boot/guest/%s",dest,vdi_uuid)
|
||||
filename=KERNEL_DIR + '/' + vdi_uuid
|
||||
#read data from /dev/ and write into a file on /boot/guest
|
||||
of=open(filename,'wb')
|
||||
f=open(dest,'rb')
|
||||
data=f.read(vdi_size)
|
||||
of.write(data)
|
||||
f.close()
|
||||
of.close()
|
||||
logging.debug("Done. Filename: %s",filename)
|
||||
return filename
|
||||
|
||||
def put_vdis(session, args):
|
||||
params = pickle.loads(exists(args, 'params'))
|
||||
vdi_uuids = params["vdi_uuids"]
|
||||
@@ -129,4 +156,5 @@ def find_sr(session):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
XenAPIPlugin.dispatch({'put_vdis': put_vdis})
|
||||
XenAPIPlugin.dispatch({'put_vdis': put_vdis,
|
||||
'copy_kernel_vdi': copy_kernel_vdi})
|
||||
|
||||
@@ -154,7 +154,7 @@ def create_vdi(session, sr_ref, name_label, virtual_size, read_only):
|
||||
return vdi_ref
|
||||
|
||||
|
||||
def with_vdi_in_dom0(session, vdi, read_only, f):
|
||||
def with_vdi_in_dom0(session, vdi, read_only, f,args=None):
|
||||
dom0 = get_domain_0(session)
|
||||
vbd_rec = {}
|
||||
vbd_rec['VM'] = dom0
|
||||
@@ -176,7 +176,7 @@ def with_vdi_in_dom0(session, vdi, read_only, f):
|
||||
logging.debug('Plugging VBD %s ... ', vbd)
|
||||
session.xenapi.VBD.plug(vbd)
|
||||
logging.debug('Plugging VBD %s done.', vbd)
|
||||
return f(session.xenapi.VBD.get_device(vbd))
|
||||
return f(session.xenapi.VBD.get_device(vbd),args)
|
||||
finally:
|
||||
logging.debug('Destroying VBD for VDI %s ... ', vdi)
|
||||
vbd_unplug_with_retry(session, vbd)
|
||||
|
||||
Reference in New Issue
Block a user