import yaml
from ceph.deployment.inventory import Device
-from ceph.deployment.service_spec import ServiceSpecValidationError, ServiceSpec, PlacementSpec
+from ceph.deployment.service_spec import ServiceSpec, PlacementSpec
+from ceph.deployment.hostspec import SpecValidationError
try:
from typing import Optional, List, Dict, Any, Union
except ImportError:
pass
-import six
class DeviceSelection(object):
return ret
- def __repr__(self):
+ def __repr__(self) -> str:
keys = [
key for key in self._supported_filters + ['limit'] if getattr(self, key) is not None
]
', '.join('{}={}'.format(key, repr(getattr(self, key))) for key in keys)
)
- def __eq__(self, other):
+ def __eq__(self, other: Any) -> bool:
return repr(self) == repr(other)
-class DriveGroupValidationError(ServiceSpecValidationError):
+class DriveGroupValidationError(SpecValidationError):
"""
Defining an exception here is a bit problematic, cause you cannot properly catch it,
if it was raised in a different mgr module.
"""
- def __init__(self, msg):
+ def __init__(self, msg: str):
super(DriveGroupValidationError, self).__init__('Failed to validate Drive Group: ' + msg)
def __init__(self,
placement=None, # type: Optional[PlacementSpec]
- service_id=None, # type: str
+ service_id=None, # type: Optional[str]
data_devices=None, # type: Optional[DeviceSelection]
db_devices=None, # type: Optional[DeviceSelection]
wal_devices=None, # type: Optional[DeviceSelection]
:param json_drive_group: A valid json string with a Drive Group
specification
"""
- args = {}
+ args: Dict[str, Any] = {}
# legacy json (pre Octopus)
if 'host_pattern' in json_drive_group and 'placement' not in json_drive_group:
json_drive_group['placement'] = {'host_pattern': json_drive_group['host_pattern']}
else:
args.update(cls._drive_group_spec_from_json(json_drive_group))
+ args['unmanaged'] = json_drive_group.pop('unmanaged', False)
+
return cls(**args)
@classmethod
if not self.service_id:
raise DriveGroupValidationError('service_id is required')
- if not isinstance(self.placement.host_pattern, six.string_types) and \
+ if not isinstance(self.placement.host_pattern, str) and \
self.placement.host_pattern is not None:
raise DriveGroupValidationError('host_pattern must be of type string')
+ if self.data_devices is None:
+ raise DriveGroupValidationError("`data_devices` element is required.")
+
specs = [self.data_devices, self.db_devices, self.wal_devices, self.journal_devices]
for s in filter(None, specs):
s.validate()
for s in filter(None, [self.db_devices, self.wal_devices, self.journal_devices]):
- if s.paths:
- raise DriveGroupValidationError("`paths` is only allowed for data_devices")
if s.all:
raise DriveGroupValidationError("`all` is only allowed for data_devices")
if self.filter_logic not in ['AND', 'OR']:
raise DriveGroupValidationError('filter_logic must be either <AND> or <OR>')
- def __repr__(self):
+ def __repr__(self) -> str:
keys = [
key for key in self._supported_features if getattr(self, key) is not None
]
', '.join('{}={}'.format(key, repr(getattr(self, key))) for key in keys)
)
- def __eq__(self, other):
+ def __eq__(self, other: Any) -> bool:
return repr(self) == repr(other)