Merge "Extract instance allocation removal code"
This commit is contained in:
commit
7325eead05
|
@ -694,12 +694,8 @@ class ComputeManager(manager.Manager):
|
|||
continue
|
||||
cn_uuid = compute_nodes[migration.source_node]
|
||||
|
||||
my_resources = scheduler_utils.resources_from_flavor(
|
||||
instance, instance.flavor)
|
||||
res = self.reportclient.remove_provider_from_instance_allocation(
|
||||
instance.uuid, cn_uuid, instance.user_id,
|
||||
instance.project_id, my_resources)
|
||||
if not res:
|
||||
if not scheduler_utils.remove_allocation_from_compute(
|
||||
instance, cn_uuid, self.reportclient):
|
||||
LOG.error("Failed to clean allocation of evacuated instance "
|
||||
"on the source node %s",
|
||||
cn_uuid, instance=instance)
|
||||
|
@ -3816,11 +3812,8 @@ class ComputeManager(manager.Manager):
|
|||
# PUT'd back to placement will only include the destination host and
|
||||
# any shared providers in the case of a confirm_resize operation and
|
||||
# the source host and shared providers for a revert_resize operation..
|
||||
my_resources = scheduler_utils.resources_from_flavor(instance, flavor)
|
||||
res = self.reportclient.remove_provider_from_instance_allocation(
|
||||
instance.uuid, cn_uuid, instance.user_id,
|
||||
instance.project_id, my_resources)
|
||||
if not res:
|
||||
if not scheduler_utils.remove_allocation_from_compute(
|
||||
instance, cn_uuid, self.reportclient, flavor):
|
||||
LOG.error("Failed to save manipulated allocation",
|
||||
instance=instance)
|
||||
|
||||
|
|
|
@ -1313,15 +1313,9 @@ class ResourceTracker(object):
|
|||
def _delete_allocation_for_moved_instance(
|
||||
self, instance, node, move_type, node_type='source'):
|
||||
# Clean up the instance allocation from this node in placement
|
||||
my_resources = scheduler_utils.resources_from_flavor(
|
||||
instance, instance.flavor)
|
||||
|
||||
cn_uuid = self.compute_nodes[node].uuid
|
||||
|
||||
res = self.reportclient.remove_provider_from_instance_allocation(
|
||||
instance.uuid, cn_uuid, instance.user_id,
|
||||
instance.project_id, my_resources)
|
||||
if not res:
|
||||
if not scheduler_utils.remove_allocation_from_compute(
|
||||
instance, cn_uuid, self.reportclient):
|
||||
LOG.error("Failed to clean allocation of %s "
|
||||
"instance on the %s node %s",
|
||||
move_type, node_type, cn_uuid, instance=instance)
|
||||
|
@ -1335,12 +1329,9 @@ class ResourceTracker(object):
|
|||
the new_flavor resources are subtracted from the single allocation.
|
||||
:param flavor: This is the new_flavor during a resize.
|
||||
"""
|
||||
resources = scheduler_utils.resources_from_flavor(instance, flavor)
|
||||
cn = self.compute_nodes[node]
|
||||
res = self.reportclient.remove_provider_from_instance_allocation(
|
||||
instance.uuid, cn.uuid, instance.user_id, instance.project_id,
|
||||
resources)
|
||||
if not res:
|
||||
if not scheduler_utils.remove_allocation_from_compute(
|
||||
instance, cn.uuid, self.reportclient, flavor):
|
||||
if instance.instance_type_id == flavor.id:
|
||||
operation = 'migration'
|
||||
else:
|
||||
|
|
|
@ -798,3 +798,27 @@ def claim_resources(ctx, client, spec_obj, instance_uuid, alloc_req,
|
|||
|
||||
return client.claim_resources(instance_uuid, alloc_req, project_id,
|
||||
user_id, allocation_request_version=allocation_request_version)
|
||||
|
||||
|
||||
def remove_allocation_from_compute(instance, compute_node_uuid, reportclient,
|
||||
flavor=None):
|
||||
"""Removes the instance allocation from the compute host.
|
||||
|
||||
:param instance: the instance object owning the allocation
|
||||
:param compute_node_uuid: the UUID of the compute node where the allocation
|
||||
needs to be removed
|
||||
:param reportclient: the SchedulerReportClient instances to be used to
|
||||
communicate with Placement
|
||||
:param flavor: If provided then it is used to calculate the amount of
|
||||
resource that needs to be removed. If not provided then
|
||||
instance.flavor will be used
|
||||
:return: True if the removal was successful, False otherwise
|
||||
"""
|
||||
|
||||
if not flavor:
|
||||
flavor = instance.flavor
|
||||
|
||||
my_resources = resources_from_flavor(instance, flavor)
|
||||
return reportclient.remove_provider_from_instance_allocation(
|
||||
instance.uuid, compute_node_uuid, instance.user_id,
|
||||
instance.project_id, my_resources)
|
||||
|
|
Loading…
Reference in New Issue