Catch quota reserve exception to avoid function break

Catch quota reserve exception to avoid function break,
and catch get_info() excption to avoid startup break.

Change-Id: If2f8f535caeef81264f323df73927f0cfb4ecfb2
Closes-bug: #1493726
This commit is contained in:
Jerry Cai 2015-09-09 17:38:59 +08:00
parent 50d97fd983
commit 276880ece8
2 changed files with 21 additions and 13 deletions

View File

@ -501,10 +501,19 @@ class PowerVCCloudManager(manager.Manager):
inst_obj.save()
# Update quota
quotas = objects.Quotas(ctx)
quotas.reserve(instances=1,
cores=ins.get("vcpus"), ram=ins.get("memory_mb"))
quotas.commit()
try:
dis_name = ins.get("display_name")
vcpus = ins.get("vcpus")
memory_mb = ins.get("memory_mb")
quotas = objects.Quotas(ctx)
quotas.reserve(instances=1, cores=vcpus, ram=memory_mb)
LOG.info(_("Start to deduct quota of vm: %s, cores: %s, ram: %s") %
(dis_name, vcpus, memory_mb))
quotas.commit()
except Exception as e:
LOG.debug(_("Quota exceeded for instance: %s. Exception: %s")
% (dis_name, str(e)))
LOG.debug('created local db instance: %s for '
'powervc instance: %s' % (inst_obj, pvc_instance))
self.sync_volume_attachment(ctx,

View File

@ -113,7 +113,7 @@ class PowerVCDriver(driver.ComputeDriver):
:num_cpu: (int) the number of virtual CPUs for the domain
:cpu_time: (int) the CPU time used in nanoseconds
"""
LOG.debug(_("get_info() Enter: %s" % str(instance)))
LOG.debug(_("get_info() Enter: %s") % str(instance))
lpar_instance = None
try:
pvc_id = self._get_pvcid_from_metadata(instance)
@ -125,22 +125,21 @@ class PowerVCDriver(driver.ComputeDriver):
pvc_id = self._get_pvcid_from_metadata(db_instances[0])
LOG.debug(_("pvc_id: %s" % str(pvc_id)))
lpar_instance = self.get_instance(pvc_id)
LOG.debug(_("Found instance: %s" % str(lpar_instance)))
LOG.debug(_("Found instance: %s") % str(lpar_instance))
except Exception:
if pvc_id is None:
LOG.info(_("Can not get the pvc_id from the"
" instance %s." % instance['name']))
" instance %s.") % instance['name'])
else:
LOG.info(_("Can not get the PowerVC"
" instance %s." % pvc_id))
raise exception.NotFound
" instance %s.") % pvc_id)
return pvc_vm_states.InstanceInfo(state=0)
if(lpar_instance is None):
LOG.info(_("Can not get the PowerVC"
" instance %s." % pvc_id))
raise exception.NotFound
LOG.debug(_("Can not get the PowerVC instance %s, will delete it"
" in the next sync.") % pvc_id)
return pvc_vm_states.InstanceInfo(state=0)
LOG.debug(_("get_info() Exit"))
max_mem = self._int_or_none(lpar_instance._info.get('max_memory_mb'))
mem = self._int_or_none(lpar_instance._info.get('memory_mb'))
num_cpu = self._int_or_none(lpar_instance._info.get('cpus'))