342
342
return os.path.join(FLAGS.xenapi_sr_base_path, sr_uuid)
345
def upload_image(cls, session, instance, vdi_uuids, image_id):
345
def upload_image(cls, context, session, instance, vdi_uuids, image_id):
346
346
""" Requests that the Glance plugin bundle the specified VDIs and
347
347
push them into Glance using the specified human-friendly name.
360
360
'glance_host': glance_host,
361
361
'glance_port': glance_port,
362
362
'sr_path': cls.get_sr_path(session),
364
'auth_token': getattr(context, 'auth_token', None)}
365
366
kwargs = {'params': pickle.dumps(params)}
366
367
task = session.async_call_plugin('glance', 'upload_vhd', kwargs)
367
368
session.wait_for_task(task, instance.id)
370
def fetch_image(cls, session, instance_id, image, user_id, project_id,
371
def fetch_image(cls, context, session, instance_id, image, user_id,
372
project_id, image_type):
372
373
"""Fetch image from glance based on image type.
374
375
Returns: A single filename if image_type is KERNEL or RAMDISK
375
376
A list of dictionaries that describe VDIs, otherwise
377
378
if image_type == ImageType.DISK_VHD:
378
return cls._fetch_image_glance_vhd(
379
return cls._fetch_image_glance_vhd(context,
379
380
session, instance_id, image, image_type)
381
return cls._fetch_image_glance_disk(
382
return cls._fetch_image_glance_disk(context,
382
383
session, instance_id, image, image_type)
385
def _fetch_image_glance_vhd(cls, session, instance_id, image,
386
def _fetch_image_glance_vhd(cls, context, session, instance_id, image,
387
388
"""Tell glance to download an image and put the VHDs into the SR
404
405
'glance_host': glance_host,
405
406
'glance_port': glance_port,
406
407
'uuid_stack': uuid_stack,
407
'sr_path': cls.get_sr_path(session)}
408
'sr_path': cls.get_sr_path(session),
409
'auth_token': getattr(context, 'auth_token', None)}
409
411
kwargs = {'params': pickle.dumps(params)}
410
412
task = session.async_call_plugin('glance', 'download_vhd', kwargs)
433
def _fetch_image_glance_disk(cls, session, instance_id, image,
435
def _fetch_image_glance_disk(cls, context, session, instance_id, image,
435
437
"""Fetch the image from Glance
450
452
sr_ref = safe_find_sr(session)
452
454
glance_client, image_id = nova.image.get_glance_client(image)
455
glance_client.set_auth_token(getattr(context, 'auth_token', None))
453
456
meta, image_file = glance_client.get_image(image_id)
454
457
virtual_size = int(meta['size'])
455
458
vdi_size = virtual_size