from ceph.deployment import inventory, translate
from ceph.deployment.drive_group import DriveGroupSpec
from ceph.deployment.drive_selection import selector
-from ceph.deployment.service_spec import HostPlacementSpec, ServiceSpec, PlacementSpec
+from ceph.deployment.service_spec import HostPlacementSpec, ServiceSpec, PlacementSpec, \
+ assert_valid_host
from mgr_module import MgrModule
import orchestrator
else:
return 'mon'
-def assert_valid_host(name):
- p = re.compile('^[a-zA-Z0-9-]+$')
- try:
- assert len(name) <= 250, 'name is too long (max 250 chars)'
- parts = name.split('.')
- for part in name.split('.'):
- assert len(part) > 0, '.-delimited name component must not be empty'
- assert len(part) <= 63, '.-delimited name component must not be more than 63 chars'
- assert p.match(part), 'name component must include only a-z, 0-9, and -'
- except AssertionError as e:
- raise OrchestratorError(e)
-
class SpecStore():
def __init__(self, mgr):
('1 *'),
('* label:foo'),
('* host1 host2'),
+ ('hostname12hostname12hostname12hostname12hostname12hostname12hostname12'), # > 63 chars
])
def test_bad_placements(placement):
try:
super(ServiceSpecValidationError, self).__init__(msg)
+def assert_valid_host(name):
+ p = re.compile('^[a-zA-Z0-9-]+$')
+ try:
+ assert len(name) <= 250, 'name is too long (max 250 chars)'
+ for part in name.split('.'):
+ assert len(part) > 0, '.-delimited name component must not be empty'
+ assert len(part) <= 63, '.-delimited name component must not be more than 63 chars'
+ assert p.match(part), 'name component must include only a-z, 0-9, and -'
+ except AssertionError as e:
+ raise ServiceSpecValidationError(e)
+
+
class HostPlacementSpec(namedtuple('HostPlacementSpec', ['hostname', 'network', 'name'])):
def __str__(self):
res = ''
except ValueError as e:
# logging?
raise e
-
+ host_spec.validate()
return host_spec
+ def validate(self):
+ assert_valid_host(self.hostname)
+
class PlacementSpec(object):
"""
raise ServiceSpecValidationError("num/count must be > 1")
if self.host_pattern and self.hosts:
raise ServiceSpecValidationError('cannot combine host patterns and hosts')
+ for h in self.hosts:
+ h.validate()
@classmethod
def from_string(cls, arg):