def from_json(cls: Type, data: dict) -> 'ClientKeyringSpec': c = data.copy() if 'placement' in c: c['placement'] = PlacementSpec.from_json(c['placement']) _cls = cls(**c) _cls.validate() return _cls
def _from_json_impl(cls, json_drive_group): # type: (dict) -> DriveGroupSpec """ Initialize 'Drive group' structure :param json_drive_group: A valid json string with a Drive Group specification """ args = {} # 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']} del json_drive_group['host_pattern'] try: args['placement'] = PlacementSpec.from_json(json_drive_group.pop('placement')) except KeyError: raise DriveGroupValidationError('OSD spec needs a `placement` key.') args['service_type'] = json_drive_group.pop('service_type', 'osd') # service_id was not required in early octopus. args['service_id'] = json_drive_group.pop('service_id', '') # spec: was not mandatory in octopus if 'spec' in json_drive_group: args.update(cls._drive_group_spec_from_json(json_drive_group.pop('spec'))) else: args.update(cls._drive_group_spec_from_json(json_drive_group)) return cls(**args)
def _from_json_impl(cls, json_drive_group): # type: (dict) -> DriveGroupSpec """ Initialize 'Drive group' structure :param json_drive_group: A valid json string with a Drive Group specification """ # 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']} del json_drive_group['host_pattern'] for applied_filter in list(json_drive_group.keys()): if applied_filter not in cls._supported_features: raise DriveGroupValidationError( "Feature <{}> is not supported".format(applied_filter)) for key in ('block_wal_size', 'block_db_size', 'journal_size'): if key in json_drive_group: if isinstance(json_drive_group[key], six.string_types): from ceph.deployment.drive_selection import SizeMatcher json_drive_group[key] = SizeMatcher.str_to_byte(json_drive_group[key]) if 'placement' in json_drive_group: json_drive_group['placement'] = PlacementSpec.from_json(json_drive_group['placement']) try: args = {k: (DeviceSelection.from_json(v) if k.endswith('_devices') else v) for k, v in json_drive_group.items()} if not args: raise DriveGroupValidationError("Didn't find Drivegroup specs") return DriveGroupSpec(**args) except (KeyError, TypeError) as e: raise DriveGroupValidationError(str(e))