~rohitk/nova/network-unittests

« back to all changes in this revision

Viewing changes to nova/virt/xenapi/vm_utils.py

  • Committer: Tarmac
  • Author(s): kevin.mitchell at rackspace
  • Date: 2011-08-02 21:45:57 UTC
  • mfrom: (1309.1.19 glance-private-images)
  • Revision ID: tarmac-20110802214557-yh58mrpp3uuhrinu
Glance has been updated for integration with keystone.  That means that nova needs to forward the user's credentials (the auth token) when it uses the glance API.  This patch, combined with a forth-coming patch for nova_auth_token.py in keystone, establishes that for nova itself and for xenapi; other hypervisors will need to set up the appropriate hooks for their use of glance.

Show diffs side-by-side

added added

removed removed

Lines of Context:
342
342
        return os.path.join(FLAGS.xenapi_sr_base_path, sr_uuid)
343
343
 
344
344
    @classmethod
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.
348
348
        """
360
360
                  'glance_host': glance_host,
361
361
                  'glance_port': glance_port,
362
362
                  'sr_path': cls.get_sr_path(session),
363
 
                  'os_type': os_type}
 
363
                  'os_type': os_type,
 
364
                  'auth_token': getattr(context, 'auth_token', None)}
364
365
 
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)
368
369
 
369
370
    @classmethod
370
 
    def fetch_image(cls, session, instance_id, image, user_id, project_id,
371
 
                    image_type):
 
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.
373
374
 
374
375
        Returns: A single filename if image_type is KERNEL or RAMDISK
375
376
                 A list of dictionaries that describe VDIs, otherwise
376
377
        """
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)
380
381
        else:
381
 
            return cls._fetch_image_glance_disk(
 
382
            return cls._fetch_image_glance_disk(context,
382
383
                session, instance_id, image, image_type)
383
384
 
384
385
    @classmethod
385
 
    def _fetch_image_glance_vhd(cls, session, instance_id, image,
 
386
    def _fetch_image_glance_vhd(cls, context, session, instance_id, image,
386
387
                                image_type):
387
388
        """Tell glance to download an image and put the VHDs into the SR
388
389
 
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)}
408
410
 
409
411
        kwargs = {'params': pickle.dumps(params)}
410
412
        task = session.async_call_plugin('glance', 'download_vhd', kwargs)
430
432
        return vdis
431
433
 
432
434
    @classmethod
433
 
    def _fetch_image_glance_disk(cls, session, instance_id, image,
 
435
    def _fetch_image_glance_disk(cls, context, session, instance_id, image,
434
436
                                 image_type):
435
437
        """Fetch the image from Glance
436
438
 
450
452
        sr_ref = safe_find_sr(session)
451
453
 
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