De-duplicate two delete_allocation_for_* methods

delete_allocation_for_migrated_instance and
delete_allocation_for_evacuated_instance are only different
in their log messages, so extract their guts to a shared
private method.

This same method could also be used at the end of drop_move_claim, but
the extent of change to the logging there made me pause. Perhaps another
time.

Change-Id: Ifad17e08aa3ddbd95f25b6133564ea1a1a1bb87c
This commit is contained in:
Chris Dent 2017-08-23 22:32:29 +01:00 committed by Matt Riedemann
parent 1080506f16
commit 5a0aa09737
1 changed files with 9 additions and 14 deletions

View File

@ -1211,6 +1211,13 @@ class ResourceTracker(object):
instance_uuid, instance.host, instance.node, alloc)
def delete_allocation_for_evacuated_instance(self, instance, node):
self._delete_allocation_for_moved_instance(instance, node, 'evacuated')
def delete_allocation_for_migrated_instance(self, instance, node):
self._delete_allocation_for_moved_instance(instance, node, 'migrated')
def _delete_allocation_for_moved_instance(
self, instance, node, move_type):
# Clean up the instance allocation from this node in placement
my_resources = scheduler_utils.resources_from_flavor(
instance, instance.flavor)
@ -1221,21 +1228,9 @@ class ResourceTracker(object):
instance.uuid, cn_uuid, instance.user_id,
instance.project_id, my_resources)
if not res:
LOG.error("Failed to clean allocation of an evacuated "
LOG.error("Failed to clean allocation of %s "
"instance on the source node %s",
cn_uuid, instance=instance)
def delete_allocation_for_migrated_instance(self, instance, node):
my_resources = scheduler_utils.resources_from_flavor(instance,
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,
my_resources)
if not res:
LOG.error('Failed to clean allocation of a migrated instance '
'on the source node %s', cn.uuid,
instance=instance)
move_type, cn_uuid, instance=instance)
def delete_allocation_for_failed_resize(self, instance, node, flavor):
"""Delete instance allocations for the node during a failed resize