~mdragon/nova/multi-tenant-accounting

« back to all changes in this revision

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

  • Committer: Monsyne Dragon
  • Date: 2011-03-03 15:50:34 UTC
  • mfrom: (752.2.6 nova)
  • Revision ID: mdragon@rackspace.com-20110303155034-seiumq0o74hynh6i
Remerged trunk, fixed a few conflicts. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
        the pv_kernel flag indicates whether the guest is HVM or PV
87
87
        """
88
88
 
89
 
        instance_type = instance_types.INSTANCE_TYPES[instance.instance_type]
 
89
        instance_type = instance_types.\
 
90
                                get_instance_type(instance.instance_type)
90
91
        mem = str(long(instance_type['memory_mb']) * 1024 * 1024)
91
92
        vcpus = str(instance_type['vcpus'])
92
93
        rec = {
144
145
 
145
146
    @classmethod
146
147
    def ensure_free_mem(cls, session, instance):
147
 
        instance_type = instance_types.INSTANCE_TYPES[instance.instance_type]
 
148
        instance_type = instance_types.get_instance_type(
 
149
            instance.instance_type)
148
150
        mem = long(instance_type['memory_mb']) * 1024 * 1024
149
151
        #get free memory from host
150
152
        host = session.get_xenapi_host()
205
207
        """Destroy VBD from host database"""
206
208
        try:
207
209
            task = session.call_xenapi('Async.VBD.destroy', vbd_ref)
208
 
            #FIXME(armando): find a solution to missing instance_id
209
 
            #with Josh Kearney
210
 
            session.wait_for_task(0, task)
 
210
            session.wait_for_task(task)
211
211
        except cls.XenAPI.Failure, exc:
212
212
            LOG.exception(exc)
213
213
            raise StorageError(_('Unable to destroy VBD %s') % vbd_ref)
214
214
 
215
215
    @classmethod
216
 
    def create_vif(cls, session, vm_ref, network_ref, mac_address):
 
216
    def create_vif(cls, session, vm_ref, network_ref, mac_address, dev="0"):
217
217
        """Create a VIF record.  Returns a Deferred that gives the new
218
218
        VIF reference."""
219
219
        vif_rec = {}
220
 
        vif_rec['device'] = '0'
 
220
        vif_rec['device'] = dev
221
221
        vif_rec['network'] = network_ref
222
222
        vif_rec['VM'] = vm_ref
223
223
        vif_rec['MAC'] = mac_address
269
269
        original_parent_uuid = get_vhd_parent_uuid(session, vm_vdi_ref)
270
270
 
271
271
        task = session.call_xenapi('Async.VM.snapshot', vm_ref, label)
272
 
        template_vm_ref = session.wait_for_task(instance_id, task)
 
272
        template_vm_ref = session.wait_for_task(task, instance_id)
273
273
        template_vdi_rec = get_vdi_for_vm_safely(session, template_vm_ref)[1]
274
274
        template_vdi_uuid = template_vdi_rec["uuid"]
275
275
 
302
302
 
303
303
        kwargs = {'params': pickle.dumps(params)}
304
304
        task = session.async_call_plugin('glance', 'upload_vhd', kwargs)
305
 
        session.wait_for_task(instance_id, task)
 
305
        session.wait_for_task(task, instance_id)
306
306
 
307
307
    @classmethod
308
308
    def fetch_image(cls, session, instance_id, image, user, project,
345
345
 
346
346
        kwargs = {'params': pickle.dumps(params)}
347
347
        task = session.async_call_plugin('glance', 'download_vhd', kwargs)
348
 
        vdi_uuid = session.wait_for_task(instance_id, task)
 
348
        vdi_uuid = session.wait_for_task(task, instance_id)
349
349
 
350
350
        scan_sr(session, instance_id, sr_ref)
351
351
 
401
401
            #let the plugin copy the correct number of bytes
402
402
            args['image-size'] = str(vdi_size)
403
403
            task = session.async_call_plugin('glance', fn, args)
404
 
            filename = session.wait_for_task(instance_id, task)
 
404
            filename = session.wait_for_task(task, instance_id)
405
405
            #remove the VDI as it is not needed anymore
406
406
            session.get_xenapi().VDI.destroy(vdi)
407
407
            LOG.debug(_("Kernel/Ramdisk VDI %s destroyed"), vdi)
493
493
            if image_type == ImageType.DISK_RAW:
494
494
                args['raw'] = 'true'
495
495
        task = session.async_call_plugin('objectstore', fn, args)
496
 
        uuid = session.wait_for_task(instance_id, task)
 
496
        uuid = session.wait_for_task(task, instance_id)
497
497
        return uuid
498
498
 
499
499
    @classmethod
513
513
        args = {}
514
514
        args['vdi-ref'] = vdi_ref
515
515
        task = session.async_call_plugin('objectstore', fn, args)
516
 
        pv_str = session.wait_for_task(instance_id, task)
 
516
        pv_str = session.wait_for_task(task, instance_id)
517
517
        pv = None
518
518
        if pv_str.lower() == 'true':
519
519
            pv = True
654
654
def scan_sr(session, instance_id, sr_ref):
655
655
    LOG.debug(_("Re-scanning SR %s"), sr_ref)
656
656
    task = session.call_xenapi('Async.SR.scan', sr_ref)
657
 
    session.wait_for_task(instance_id, task)
 
657
    session.wait_for_task(task, instance_id)
658
658
 
659
659
 
660
660
def wait_for_vhd_coalesce(session, instance_id, sr_ref, vdi_ref,