Merge "Refactor MigrationTask._execute"
This commit is contained in:
commit
c34b783749
@ -237,6 +237,40 @@ class MigrationTask(base.TaskBase):
|
|||||||
# pop the first alternate from the list to use for the destination, and
|
# pop the first alternate from the list to use for the destination, and
|
||||||
# pass the remaining alternates to the compute.
|
# pass the remaining alternates to the compute.
|
||||||
if self.host_list is None:
|
if self.host_list is None:
|
||||||
|
selection = self._schedule()
|
||||||
|
|
||||||
|
else:
|
||||||
|
# This is a reschedule that will use the supplied alternate hosts
|
||||||
|
# in the host_list as destinations.
|
||||||
|
selection = self._reschedule()
|
||||||
|
|
||||||
|
scheduler_utils.populate_filter_properties(legacy_props, selection)
|
||||||
|
# context is not serializable
|
||||||
|
legacy_props.pop('context', None)
|
||||||
|
|
||||||
|
(host, node) = (selection.service_host, selection.nodename)
|
||||||
|
|
||||||
|
self.instance.availability_zone = (
|
||||||
|
availability_zones.get_host_availability_zone(
|
||||||
|
self.context, host))
|
||||||
|
|
||||||
|
LOG.debug("Calling prep_resize with selected host: %s; "
|
||||||
|
"Selected node: %s; Alternates: %s", host, node,
|
||||||
|
self.host_list, instance=self.instance)
|
||||||
|
# RPC cast to the destination host to start the migration process.
|
||||||
|
self.compute_rpcapi.prep_resize(
|
||||||
|
# NOTE(mriedem): Using request_spec.image here is potentially
|
||||||
|
# dangerous if it is not kept up to date (i.e. rebuild/unshelve);
|
||||||
|
# seems like the sane thing to do would be to pass the current
|
||||||
|
# instance.image_meta since that is what MoveClaim will use for
|
||||||
|
# any NUMA topology claims on the destination host...
|
||||||
|
self.context, self.instance, self.request_spec.image,
|
||||||
|
self.flavor, host, migration,
|
||||||
|
request_spec=self.request_spec, filter_properties=legacy_props,
|
||||||
|
node=node, clean_shutdown=self.clean_shutdown,
|
||||||
|
host_list=self.host_list)
|
||||||
|
|
||||||
|
def _schedule(self):
|
||||||
selection_lists = self.query_client.select_destinations(
|
selection_lists = self.query_client.select_destinations(
|
||||||
self.context, self.request_spec, [self.instance.uuid],
|
self.context, self.request_spec, [self.instance.uuid],
|
||||||
return_objects=True, return_alternates=True)
|
return_objects=True, return_alternates=True)
|
||||||
@ -249,16 +283,16 @@ class MigrationTask(base.TaskBase):
|
|||||||
|
|
||||||
scheduler_utils.fill_provider_mapping(
|
scheduler_utils.fill_provider_mapping(
|
||||||
self.context, self.reportclient, self.request_spec, selection)
|
self.context, self.reportclient, self.request_spec, selection)
|
||||||
|
return selection
|
||||||
|
|
||||||
else:
|
def _reschedule(self):
|
||||||
# This is a reschedule that will use the supplied alternate hosts
|
# Since the resources on these alternates may have been consumed and
|
||||||
# in the host_list as destinations. Since the resources on these
|
# might not be able to support the migrated instance, we need to first
|
||||||
# alternates may have been consumed and might not be able to
|
# claim the resources to verify the host still has sufficient
|
||||||
# support the migrated instance, we need to first claim the
|
# available resources.
|
||||||
# resources to verify the host still has sufficient availabile
|
|
||||||
# resources.
|
|
||||||
elevated = self.context.elevated()
|
elevated = self.context.elevated()
|
||||||
host_available = False
|
host_available = False
|
||||||
|
selection = None
|
||||||
while self.host_list and not host_available:
|
while self.host_list and not host_available:
|
||||||
selection = self.host_list.pop(0)
|
selection = self.host_list.pop(0)
|
||||||
if selection.allocation_request:
|
if selection.allocation_request:
|
||||||
@ -290,32 +324,7 @@ class MigrationTask(base.TaskBase):
|
|||||||
"failures for instance %(instance_uuid)s." %
|
"failures for instance %(instance_uuid)s." %
|
||||||
{"instance_uuid": self.instance.uuid})
|
{"instance_uuid": self.instance.uuid})
|
||||||
raise exception.MaxRetriesExceeded(reason=reason)
|
raise exception.MaxRetriesExceeded(reason=reason)
|
||||||
|
return selection
|
||||||
scheduler_utils.populate_filter_properties(legacy_props, selection)
|
|
||||||
# context is not serializable
|
|
||||||
legacy_props.pop('context', None)
|
|
||||||
|
|
||||||
(host, node) = (selection.service_host, selection.nodename)
|
|
||||||
|
|
||||||
self.instance.availability_zone = (
|
|
||||||
availability_zones.get_host_availability_zone(
|
|
||||||
self.context, host))
|
|
||||||
|
|
||||||
LOG.debug("Calling prep_resize with selected host: %s; "
|
|
||||||
"Selected node: %s; Alternates: %s", host, node,
|
|
||||||
self.host_list, instance=self.instance)
|
|
||||||
# RPC cast to the destination host to start the migration process.
|
|
||||||
self.compute_rpcapi.prep_resize(
|
|
||||||
# NOTE(mriedem): Using request_spec.image here is potentially
|
|
||||||
# dangerous if it is not kept up to date (i.e. rebuild/unshelve);
|
|
||||||
# seems like the sane thing to do would be to pass the current
|
|
||||||
# instance.image_meta since that is what MoveClaim will use for
|
|
||||||
# any NUMA topology claims on the destination host...
|
|
||||||
self.context, self.instance, self.request_spec.image,
|
|
||||||
self.flavor, host, migration,
|
|
||||||
request_spec=self.request_spec, filter_properties=legacy_props,
|
|
||||||
node=node, clean_shutdown=self.clean_shutdown,
|
|
||||||
host_list=self.host_list)
|
|
||||||
|
|
||||||
def rollback(self):
|
def rollback(self):
|
||||||
if self._migration:
|
if self._migration:
|
||||||
|
Loading…
Reference in New Issue
Block a user