|
|
|
@ -14,7 +14,6 @@
|
|
|
|
|
|
|
|
|
|
from glanceclient import exc as glance_exception
|
|
|
|
|
from novaclient import exceptions as nova_exception
|
|
|
|
|
from oslo_serialization import jsonutils
|
|
|
|
|
|
|
|
|
|
from magnum.api import utils as api_utils
|
|
|
|
|
from magnum.common import clients
|
|
|
|
@ -113,64 +112,6 @@ def validate_labels(labels):
|
|
|
|
|
validate_method(labels)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_labels_isolation(labels):
|
|
|
|
|
"""Validate mesos_slave_isolation"""
|
|
|
|
|
mesos_slave_isolation = labels.get('mesos_slave_isolation')
|
|
|
|
|
mesos_slave_isolation_list = mesos_slave_isolation.split(',')
|
|
|
|
|
unsupported_isolations = set(mesos_slave_isolation_list) - set(
|
|
|
|
|
SUPPORTED_ISOLATION)
|
|
|
|
|
if (len(unsupported_isolations) > 0):
|
|
|
|
|
raise exception.InvalidParameterValue(_(
|
|
|
|
|
'property "labels/mesos_slave_isolation" with value '
|
|
|
|
|
'"%(isolation_val)s" is not supported, supported values are: '
|
|
|
|
|
'%(supported_isolation)s') % {
|
|
|
|
|
'isolation_val': ', '.join(list(unsupported_isolations)),
|
|
|
|
|
'supported_isolation': ', '.join(
|
|
|
|
|
SUPPORTED_ISOLATION + ['unspecified'])})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_labels_image_providers(labels):
|
|
|
|
|
"""Validate mesos_slave_image_providers"""
|
|
|
|
|
mesos_slave_image_providers = labels.get('mesos_slave_image_providers')
|
|
|
|
|
mesos_slave_image_providers_list = mesos_slave_image_providers.split(',')
|
|
|
|
|
isolation_with_valid_data = False
|
|
|
|
|
for image_providers_val in mesos_slave_image_providers_list:
|
|
|
|
|
image_providers_val = image_providers_val.lower()
|
|
|
|
|
if image_providers_val not in SUPPORTED_IMAGE_PROVIDERS:
|
|
|
|
|
raise exception.InvalidParameterValue(_(
|
|
|
|
|
'property "labels/mesos_slave_image_providers" with value '
|
|
|
|
|
'"%(image_providers)s" is not supported, supported values '
|
|
|
|
|
'are: %(supported_image_providers)s') % {
|
|
|
|
|
'image_providers': image_providers_val,
|
|
|
|
|
'supported_image_providers': ', '.join(
|
|
|
|
|
SUPPORTED_IMAGE_PROVIDERS + ['unspecified'])})
|
|
|
|
|
|
|
|
|
|
if image_providers_val == 'docker':
|
|
|
|
|
mesos_slave_isolation = labels.get('mesos_slave_isolation')
|
|
|
|
|
if mesos_slave_isolation is not None:
|
|
|
|
|
mesos_slave_isolation_list = mesos_slave_isolation.split(',')
|
|
|
|
|
for isolations_val in mesos_slave_isolation_list:
|
|
|
|
|
if isolations_val == 'docker/runtime':
|
|
|
|
|
isolation_with_valid_data = True
|
|
|
|
|
if mesos_slave_isolation is None or not isolation_with_valid_data:
|
|
|
|
|
raise exception.RequiredParameterNotProvided(_(
|
|
|
|
|
"Docker runtime isolator has to be specified if 'docker' "
|
|
|
|
|
"is included in 'mesos_slave_image_providers' Please add "
|
|
|
|
|
"'docker/runtime' to 'mesos_slave_isolation' labels "
|
|
|
|
|
"flags"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_labels_executor_env_variables(labels):
|
|
|
|
|
"""Validate executor_environment_variables"""
|
|
|
|
|
mesos_slave_executor_env_val = labels.get(
|
|
|
|
|
'mesos_slave_executor_env_variables')
|
|
|
|
|
try:
|
|
|
|
|
jsonutils.loads(mesos_slave_executor_env_val)
|
|
|
|
|
except ValueError:
|
|
|
|
|
err = (_("Json format error"))
|
|
|
|
|
raise exception.InvalidParameterValue(err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_labels_strategy(labels):
|
|
|
|
|
"""Validate swarm_strategy"""
|
|
|
|
|
swarm_strategy = list(labels.get('swarm_strategy', "").split())
|
|
|
|
@ -249,9 +190,4 @@ validators = {'image_id': validate_image,
|
|
|
|
|
'fixed_network': validate_fixed_network,
|
|
|
|
|
'labels': validate_labels}
|
|
|
|
|
|
|
|
|
|
labels_validators = {'mesos_slave_isolation': validate_labels_isolation,
|
|
|
|
|
'mesos_slave_image_providers':
|
|
|
|
|
validate_labels_image_providers,
|
|
|
|
|
'mesos_slave_executor_env_variables':
|
|
|
|
|
validate_labels_executor_env_variables,
|
|
|
|
|
'swarm_strategy': validate_labels_strategy}
|
|
|
|
|
labels_validators = {'swarm_strategy': validate_labels_strategy}
|
|
|
|
|