|
|
@@ -7,7 +7,7 @@ from webob import exc
|
|
|
from coriolis import constants
|
|
|
from coriolis import exception
|
|
|
from coriolis.api.v1.views import minion_pool_view
|
|
|
-from coriolis.api.v1.views import minion_pool_tasks_execution_view
|
|
|
+from coriolis.api.v1 import utils as api_utils
|
|
|
from coriolis.api import wsgi as api_wsgi
|
|
|
from coriolis.endpoints import api as endpoints_api
|
|
|
from coriolis.policies import minion_pools as pools_policies
|
|
|
@@ -73,64 +73,57 @@ class MinionPoolController(api_wsgi.Controller):
|
|
|
"'minion_max_idle_time' must be a strictly positive "
|
|
|
"integer. Got: %s" % maximum_minions)
|
|
|
|
|
|
+ @api_utils.format_keyerror_message(resource='minion_pool', method='create')
|
|
|
def _validate_create_body(self, ctxt, body):
|
|
|
- try:
|
|
|
- minion_pool = body["minion_pool"]
|
|
|
- name = minion_pool["pool_name"]
|
|
|
- endpoint_id = minion_pool["endpoint_id"]
|
|
|
- pool_os_type = minion_pool["pool_os_type"]
|
|
|
- if pool_os_type not in constants.VALID_OS_TYPES:
|
|
|
- raise Exception(
|
|
|
- "The provided pool OS type '%s' is invalid. Must be one "
|
|
|
- "of the following: %s" % (
|
|
|
- pool_os_type, constants.VALID_OS_TYPES))
|
|
|
- pool_platform = minion_pool["pool_platform"]
|
|
|
- supported_pool_platforms = [
|
|
|
- constants.PROVIDER_PLATFORM_SOURCE,
|
|
|
- constants.PROVIDER_PLATFORM_DESTINATION]
|
|
|
- if pool_platform not in supported_pool_platforms:
|
|
|
- raise Exception(
|
|
|
- "The provided pool platform ('%s') is invalid. Must be one"
|
|
|
- " of the following: %s" % (
|
|
|
- pool_platform, supported_pool_platforms))
|
|
|
- if pool_platform == constants.PROVIDER_PLATFORM_SOURCE and (
|
|
|
- pool_os_type != constants.OS_TYPE_LINUX):
|
|
|
- raise Exception(
|
|
|
- "Source Minion Pools are required to be of OS type "
|
|
|
- "'%s', not '%s'." % (
|
|
|
- constants.OS_TYPE_LINUX, pool_os_type))
|
|
|
- environment_options = minion_pool["environment_options"]
|
|
|
- if pool_platform == constants.PROVIDER_PLATFORM_SOURCE:
|
|
|
- self._endpoints_api.validate_endpoint_source_minion_pool_options(
|
|
|
- ctxt, endpoint_id, environment_options)
|
|
|
- elif pool_platform == constants.PROVIDER_PLATFORM_DESTINATION:
|
|
|
- self._endpoints_api.validate_endpoint_destination_minion_pool_options(
|
|
|
- ctxt, endpoint_id, environment_options)
|
|
|
-
|
|
|
- minimum_minions = minion_pool.get("minimum_minions", 1)
|
|
|
- maximum_minions = minion_pool.get(
|
|
|
- "maximum_minions", minimum_minions)
|
|
|
- minion_max_idle_time = minion_pool.get(
|
|
|
- "minion_max_idle_time", 1)
|
|
|
- self._check_pool_numeric_values(
|
|
|
- minimum_minions, maximum_minions, minion_max_idle_time)
|
|
|
- minion_retention_strategy = minion_pool.get(
|
|
|
- "minion_retention_strategy",
|
|
|
- constants.MINION_POOL_MACHINE_RETENTION_STRATEGY_DELETE)
|
|
|
- self._check_pool_retention_strategy(
|
|
|
- minion_retention_strategy)
|
|
|
- notes = minion_pool.get("notes")
|
|
|
- return (
|
|
|
- name, endpoint_id, pool_platform, pool_os_type,
|
|
|
- environment_options, minimum_minions, maximum_minions,
|
|
|
- minion_max_idle_time, minion_retention_strategy, notes)
|
|
|
- except Exception as ex:
|
|
|
- LOG.exception(ex)
|
|
|
- if hasattr(ex, "message"):
|
|
|
- msg = ex.message
|
|
|
- else:
|
|
|
- msg = str(ex)
|
|
|
- raise exception.InvalidInput(msg)
|
|
|
+ minion_pool = body["minion_pool"]
|
|
|
+ name = minion_pool["pool_name"]
|
|
|
+ endpoint_id = minion_pool["endpoint_id"]
|
|
|
+ pool_os_type = minion_pool["pool_os_type"]
|
|
|
+ if pool_os_type not in constants.VALID_OS_TYPES:
|
|
|
+ raise Exception(
|
|
|
+ "The provided pool OS type '%s' is invalid. Must be one "
|
|
|
+ "of the following: %s" % (
|
|
|
+ pool_os_type, constants.VALID_OS_TYPES))
|
|
|
+ pool_platform = minion_pool["pool_platform"]
|
|
|
+ supported_pool_platforms = [
|
|
|
+ constants.PROVIDER_PLATFORM_SOURCE,
|
|
|
+ constants.PROVIDER_PLATFORM_DESTINATION]
|
|
|
+ if pool_platform not in supported_pool_platforms:
|
|
|
+ raise Exception(
|
|
|
+ "The provided pool platform ('%s') is invalid. Must be one"
|
|
|
+ " of the following: %s" % (
|
|
|
+ pool_platform, supported_pool_platforms))
|
|
|
+ if pool_platform == constants.PROVIDER_PLATFORM_SOURCE and (
|
|
|
+ pool_os_type != constants.OS_TYPE_LINUX):
|
|
|
+ raise Exception(
|
|
|
+ "Source Minion Pools are required to be of OS type "
|
|
|
+ "'%s', not '%s'." % (
|
|
|
+ constants.OS_TYPE_LINUX, pool_os_type))
|
|
|
+ environment_options = minion_pool["environment_options"]
|
|
|
+ if pool_platform == constants.PROVIDER_PLATFORM_SOURCE:
|
|
|
+ self._endpoints_api.validate_endpoint_source_minion_pool_options(
|
|
|
+ ctxt, endpoint_id, environment_options)
|
|
|
+ elif pool_platform == constants.PROVIDER_PLATFORM_DESTINATION:
|
|
|
+ self._endpoints_api.validate_endpoint_destination_minion_pool_options(
|
|
|
+ ctxt, endpoint_id, environment_options)
|
|
|
+
|
|
|
+ minimum_minions = minion_pool.get("minimum_minions", 1)
|
|
|
+ maximum_minions = minion_pool.get(
|
|
|
+ "maximum_minions", minimum_minions)
|
|
|
+ minion_max_idle_time = minion_pool.get(
|
|
|
+ "minion_max_idle_time", 1)
|
|
|
+ self._check_pool_numeric_values(
|
|
|
+ minimum_minions, maximum_minions, minion_max_idle_time)
|
|
|
+ minion_retention_strategy = minion_pool.get(
|
|
|
+ "minion_retention_strategy",
|
|
|
+ constants.MINION_POOL_MACHINE_RETENTION_STRATEGY_DELETE)
|
|
|
+ self._check_pool_retention_strategy(
|
|
|
+ minion_retention_strategy)
|
|
|
+ notes = minion_pool.get("notes")
|
|
|
+ return (
|
|
|
+ name, endpoint_id, pool_platform, pool_os_type,
|
|
|
+ environment_options, minimum_minions, maximum_minions,
|
|
|
+ minion_max_idle_time, minion_retention_strategy, notes)
|
|
|
|
|
|
def create(self, req, body):
|
|
|
context = req.environ["coriolis.context"]
|
|
|
@@ -144,62 +137,55 @@ class MinionPoolController(api_wsgi.Controller):
|
|
|
environment_options, minimum_minions, maximum_minions,
|
|
|
minion_max_idle_time, minion_retention_strategy, notes=notes))
|
|
|
|
|
|
+ @api_utils.format_keyerror_message(resource='minion_pool', method='update')
|
|
|
def _validate_update_body(self, id, context, body):
|
|
|
- try:
|
|
|
- minion_pool = body["minion_pool"]
|
|
|
- if 'endpoint_id' in minion_pool:
|
|
|
- raise Exception(
|
|
|
- "The 'endpoint_id' of a minion pool cannot be updated.")
|
|
|
- if 'pool_platform' in minion_pool:
|
|
|
- raise Exception(
|
|
|
- "The 'pool_platform' of a minion pool cannot be updated.")
|
|
|
- vals = {k: minion_pool[k] for k in minion_pool.keys() &
|
|
|
- {"name", "environment_options", "minimum_minions",
|
|
|
- "maximum_minions", "minion_max_idle_time",
|
|
|
- "minion_retention_strategy", "notes", "pool_os_type"}}
|
|
|
- if 'minion_retention_strategy' in vals:
|
|
|
- self._check_pool_retention_strategy(
|
|
|
- vals['minion_retention_strategy'])
|
|
|
- if any([
|
|
|
- f in vals for f in [
|
|
|
- 'environment_options', 'minimum_minions',
|
|
|
- 'maximum_minions', 'minion_max_idle_time']]):
|
|
|
- minion_pool = self._minion_pool_api.get_minion_pool(
|
|
|
- context, id)
|
|
|
- self._check_pool_numeric_values(
|
|
|
- vals.get(
|
|
|
- 'minimum_minions', minion_pool['minimum_minions']),
|
|
|
- vals.get(
|
|
|
- 'maximum_minions', minion_pool['maximum_minions']),
|
|
|
- vals.get('minion_max_idle_time'))
|
|
|
-
|
|
|
- if 'environment_options' in vals:
|
|
|
- if minion_pool['pool_platform'] == (
|
|
|
- constants.PROVIDER_PLATFORM_SOURCE):
|
|
|
- self._endpoints_api.validate_endpoint_source_minion_pool_options(
|
|
|
- # TODO(aznashwan): remove endpoint ID fields redundancy
|
|
|
- # once DB models are overhauled:
|
|
|
- context, minion_pool['origin_endpoint_id'],
|
|
|
- vals['environment_options'])
|
|
|
- elif minion_pool['pool_platform'] == (
|
|
|
- constants.PROVIDER_PLATFORM_DESTINATION):
|
|
|
- self._endpoints_api.validate_endpoint_destination_minion_pool_options(
|
|
|
- # TODO(aznashwan): remove endpoint ID fields redundancy
|
|
|
- # once DB models are overhauled:
|
|
|
- context, minion_pool['origin_endpoint_id'],
|
|
|
- vals['environment_options'])
|
|
|
- else:
|
|
|
- raise Exception(
|
|
|
- "Unknown pool platform: %s" % minion_pool[
|
|
|
- 'pool_platform'])
|
|
|
- return vals
|
|
|
- except Exception as ex:
|
|
|
- LOG.exception(ex)
|
|
|
- if hasattr(ex, "message"):
|
|
|
- msg = ex.message
|
|
|
- else:
|
|
|
- msg = str(ex)
|
|
|
- raise exception.InvalidInput(msg)
|
|
|
+ minion_pool = body["minion_pool"]
|
|
|
+ if 'endpoint_id' in minion_pool:
|
|
|
+ raise Exception(
|
|
|
+ "The 'endpoint_id' of a minion pool cannot be updated.")
|
|
|
+ if 'pool_platform' in minion_pool:
|
|
|
+ raise Exception(
|
|
|
+ "The 'pool_platform' of a minion pool cannot be updated.")
|
|
|
+ vals = {k: minion_pool[k] for k in minion_pool.keys() &
|
|
|
+ {"pool_name", "environment_options", "minimum_minions",
|
|
|
+ "maximum_minions", "minion_max_idle_time",
|
|
|
+ "minion_retention_strategy", "notes", "pool_os_type"}}
|
|
|
+ if 'minion_retention_strategy' in vals:
|
|
|
+ self._check_pool_retention_strategy(
|
|
|
+ vals['minion_retention_strategy'])
|
|
|
+ if any([
|
|
|
+ f in vals for f in [
|
|
|
+ 'environment_options', 'minimum_minions',
|
|
|
+ 'maximum_minions', 'minion_max_idle_time']]):
|
|
|
+ minion_pool = self._minion_pool_api.get_minion_pool(
|
|
|
+ context, id)
|
|
|
+ self._check_pool_numeric_values(
|
|
|
+ vals.get(
|
|
|
+ 'minimum_minions', minion_pool['minimum_minions']),
|
|
|
+ vals.get(
|
|
|
+ 'maximum_minions', minion_pool['maximum_minions']),
|
|
|
+ vals.get('minion_max_idle_time'))
|
|
|
+
|
|
|
+ if 'environment_options' in vals:
|
|
|
+ if minion_pool['pool_platform'] == (
|
|
|
+ constants.PROVIDER_PLATFORM_SOURCE):
|
|
|
+ self._endpoints_api.validate_endpoint_source_minion_pool_options(
|
|
|
+ # TODO(aznashwan): remove endpoint ID fields redundancy
|
|
|
+ # once DB models are overhauled:
|
|
|
+ context, minion_pool['origin_endpoint_id'],
|
|
|
+ vals['environment_options'])
|
|
|
+ elif minion_pool['pool_platform'] == (
|
|
|
+ constants.PROVIDER_PLATFORM_DESTINATION):
|
|
|
+ self._endpoints_api.validate_endpoint_destination_minion_pool_options(
|
|
|
+ # TODO(aznashwan): remove endpoint ID fields redundancy
|
|
|
+ # once DB models are overhauled:
|
|
|
+ context, minion_pool['origin_endpoint_id'],
|
|
|
+ vals['environment_options'])
|
|
|
+ else:
|
|
|
+ raise Exception(
|
|
|
+ "Unknown pool platform: %s" % minion_pool[
|
|
|
+ 'pool_platform'])
|
|
|
+ return vals
|
|
|
|
|
|
def update(self, req, id, body):
|
|
|
context = req.environ["coriolis.context"]
|