]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/python-common/ceph/deployment/drive_group.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / python-common / ceph / deployment / drive_group.py
index f2636c7f838ab97ed408e38c72409d1056e8c088..93d7aaef1779fab982622eacb3a7b18a03d1f0eb 100644 (file)
@@ -1,13 +1,13 @@
 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):
@@ -108,7 +108,7 @@ 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
         ]
@@ -118,17 +118,17 @@ class DeviceSelection(object):
             ', '.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)
 
 
@@ -148,7 +148,7 @@ class DriveGroupSpec(ServiceSpec):
 
     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]
@@ -234,7 +234,7 @@ class DriveGroupSpec(ServiceSpec):
         :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']}
@@ -256,6 +256,8 @@ class DriveGroupSpec(ServiceSpec):
         else:
             args.update(cls._drive_group_spec_from_json(json_drive_group))
 
+        args['unmanaged'] = json_drive_group.pop('unmanaged', False)
+
         return cls(**args)
 
     @classmethod
@@ -281,16 +283,17 @@ class DriveGroupSpec(ServiceSpec):
         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")
 
@@ -308,7 +311,7 @@ class DriveGroupSpec(ServiceSpec):
         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
         ]
@@ -321,7 +324,7 @@ class DriveGroupSpec(ServiceSpec):
             ', '.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)