def stub_cast_to_cells(context, instance, method, *args, **kwargs): fn = getattr(ORIG_COMPUTE_API, method) original_instance = kwargs.pop('original_instance', None) if original_instance: instance = original_instance # Restore this in 'child cell DB' db.instance_update( context, instance['uuid'], dict(vm_state=instance['vm_state'], task_state=instance['task_state'])) # Use NoopQuotaDriver in child cells. saved_quotas = quota.QUOTAS quota.QUOTAS = quota.QuotaEngine(quota_driver=quota.NoopQuotaDriver()) compute_api.QUOTAS = quota.QUOTAS try: fn(context, instance, *args, **kwargs) finally: quota.QUOTAS = saved_quotas compute_api.QUOTAS = saved_quotas
def stub_cast_to_cells(context, instance, method, *args, **kwargs): fn = getattr(ORIG_COMPUTE_API, method) original_instance = kwargs.pop('original_instance', None) if original_instance: instance = original_instance # Restore this in 'child cell DB' db.instance_update(context, instance['uuid'], dict(vm_state=instance['vm_state'], task_state=instance['task_state'])) # Use NoopQuotaDriver in child cells. saved_quotas = quota.QUOTAS quota.QUOTAS = quota.QuotaEngine( quota_driver=quota.NoopQuotaDriver()) compute_api.QUOTAS = quota.QUOTAS try: fn(context, instance, *args, **kwargs) finally: quota.QUOTAS = saved_quotas compute_api.QUOTAS = saved_quotas
def instance_update(context, instance_uuid, values, session=None): """Updates an existing VM instance in the Database""" values = copy.deepcopy(values) power_specs = values.pop('power_specs', None) #Merge in the existing MetaData if they asked for Partial Updates _instance_merge_metadata(context, instance_uuid, values) #Delegate to the OpenStack method to actually update the Instance inst_ref = db_api.instance_update(context, instance_uuid, values) #If there were PowerSpecs provided, then insert them now if power_specs is not None and inst_ref is not None: instance_power_specs_update( context, instance_uuid, power_specs, session) #Query the Instance again to make sure the PowerSpecs is populated inst_ref = db_api.instance_get_by_uuid(context, inst_ref['uuid']) return inst_ref