Skip to content

Commit

Permalink
Refactor platform target retrieval
Browse files Browse the repository at this point in the history
Refactors minion pool platform target branching into `_get_platform_target`
method.
  • Loading branch information
Dany9966 committed Nov 22, 2023
1 parent 1cd1c5f commit c6bda86
Showing 1 changed file with 19 additions and 34 deletions.
53 changes: 19 additions & 34 deletions coriolis/tasks/minion_pool_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from coriolis.providers import factory as providers_factory
from coriolis.tasks import base


LOG = logging.getLogger(__name__)


Expand Down Expand Up @@ -40,6 +39,19 @@ def _get_required_minion_pool_provider_types_for_platform(
platform_type: [provider_type]}


def _get_platform_to_target(required_platform, origin, destination):
platform_to_target = None
if required_platform == constants.TASK_PLATFORM_SOURCE:
platform_to_target = origin
elif required_platform == constants.TASK_PLATFORM_DESTINATION:
platform_to_target = destination
else:
raise NotImplementedError(
"Unknown minion pool disk operation platform '%s'" % (
required_platform))
return platform_to_target


class _BaseValidateMinionPoolOptionsTask(base.TaskRunner):

@classmethod
Expand Down Expand Up @@ -395,17 +407,8 @@ def _get_minion_task_info_field_mappings(cls):
def _run(self, ctxt, instance, origin, destination,
task_info, event_handler):

platform_to_target = None
required_platform = self.get_required_platform()
if required_platform == constants.TASK_PLATFORM_SOURCE:
platform_to_target = origin
elif required_platform == constants.TASK_PLATFORM_DESTINATION:
platform_to_target = destination
else:
raise NotImplementedError(
"Unknown minion pool disk operation platform '%s'" % (
required_platform))

platform_to_target = _get_platform_to_target(
self.get_required_platform(), origin, destination)
connection_info = base.get_connection_info(ctxt, platform_to_target)
provider_type = self.get_required_provider_types()[
self.get_required_platform()][0]
Expand Down Expand Up @@ -675,17 +678,8 @@ def _get_minion_task_info_field_mappings(cls):
def _run(self, ctxt, instance, origin, destination,
task_info, event_handler):

platform_to_target = None
required_platform = self.get_required_platform()
if required_platform == constants.TASK_PLATFORM_SOURCE:
platform_to_target = origin
elif required_platform == constants.TASK_PLATFORM_DESTINATION:
platform_to_target = destination
else:
raise NotImplementedError(
"Unknown minion pool validation operation platform '%s'" % (
required_platform))

platform_to_target = _get_platform_to_target(
self.get_required_platform(), origin, destination)
connection_info = base.get_connection_info(ctxt, platform_to_target)
provider_type = self.get_required_provider_types()[
self.get_required_platform()][0]
Expand Down Expand Up @@ -976,17 +970,8 @@ def _get_minion_power_cycle_op(cls, provider):
def _run(self, ctxt, instance, origin, destination,
task_info, event_handler):

platform_to_target = None
required_platform = self.get_required_platform()
if required_platform == constants.TASK_PLATFORM_SOURCE:
platform_to_target = origin
elif required_platform == constants.TASK_PLATFORM_DESTINATION:
platform_to_target = destination
else:
raise NotImplementedError(
"Unknown minion healthcheck platform '%s'" % (
required_platform))

platform_to_target = _get_platform_to_target(
self.get_required_platform(), origin, destination)
connection_info = base.get_connection_info(ctxt, platform_to_target)
provider_type = self.get_required_provider_types()[
self.get_required_platform()][0]
Expand Down

0 comments on commit c6bda86

Please sign in to comment.