from ceph.deployment import inventory
from ceph.deployment.drive_group import DriveGroupSpec
from ceph.deployment.service_spec import \
- ServiceSpec, PlacementSpec, assert_valid_host, \
+ ServiceSpec, PlacementSpec, \
HostPlacementSpec, IngressSpec
from ceph.utils import str_to_datetime, datetime_to_str, datetime_now
from cephadm.serve import CephadmServe
:param host: host name
"""
- assert_valid_host(spec.hostname)
+ spec.validate()
ip_addr = self._check_valid_addr(spec.hostname, spec.addr)
if spec.addr == spec.hostname and ip_addr:
spec.addr = ip_addr
from collections import OrderedDict
import errno
-try:
- from typing import Optional, List, Any, Dict
-except ImportError:
- pass # just for type checking
+import re
+from typing import Optional, List, Any, Dict
+
+
+def assert_valid_host(name: str) -> None:
+ 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 SpecValidationError(str(e))
class SpecValidationError(Exception):
self.location = location
+ def validate(self) -> None:
+ assert_valid_host(self.hostname)
+
def to_json(self) -> Dict[str, Any]:
r: Dict[str, Any] = {
'hostname': self.hostname,
import yaml
-from ceph.deployment.hostspec import HostSpec, SpecValidationError
+from ceph.deployment.hostspec import HostSpec, SpecValidationError, assert_valid_host
from ceph.deployment.utils import unwrap_ipv6
ServiceSpecT = TypeVar('ServiceSpecT', bound='ServiceSpec')
FuncT = TypeVar('FuncT', bound=Callable)
-def assert_valid_host(name: str) -> None:
- 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 SpecValidationError(str(e))
-
-
def handle_type_error(method: FuncT) -> FuncT:
@wraps(method)
def inner(cls: Any, *args: Any, **kwargs: Any) -> Any: