def _create_osd(self, svc_arg=None, inbuf=None): # type: (str, str) -> HandleCommandResult """Create one or more OSDs""" usage = """ Usage: ceph orchestrator osd create -i <json_file> ceph orchestrator osd create host:device1,device2,... """ if inbuf: try: drive_group = orchestrator.DriveGroupSpec.from_json( json.loads(inbuf)) except ValueError as e: msg = 'Failed to read JSON input: {}'.format(str(e)) + usage return HandleCommandResult(-errno.EINVAL, stderr=msg) elif svc_arg: try: node_name, block_device = svc_arg.split(":") block_devices = block_device.split(',') except (TypeError, KeyError, ValueError): msg = "Invalid host:device spec: '{}'".format(svc_arg) + usage return HandleCommandResult(-errno.EINVAL, stderr=msg) devs = orchestrator.DeviceSelection(paths=block_devices) drive_group = orchestrator.DriveGroupSpec(node_name, data_devices=devs) else: return HandleCommandResult(-errno.EINVAL, stderr=usage) # TODO: Remove this and make the orchestrator composable # Like a future or so. host_completion = self.get_hosts() self._orchestrator_wait([host_completion]) orchestrator.raise_if_exception(host_completion) all_hosts = [h.name for h in host_completion.result] try: drive_group.validate(all_hosts) except orchestrator.DriveGroupValidationError as e: return HandleCommandResult(-errno.EINVAL, stderr=str(e)) completion = self.create_osds(drive_group, all_hosts) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) self.log.warning(str(completion.result)) return HandleCommandResult(stdout=str(completion.result))
def _osd_add(self, cmd): device_spec = cmd['svc_arg'] try: node_name, block_device = device_spec.split(":") except TypeError: return HandleCommandResult(-errno.EINVAL, stderr="Invalid device spec, should be <node>:<device>") devs = orchestrator.DeviceSelection(paths=block_device) spec = orchestrator.DriveGroupSpec(node_name, data_devices=devs) # TODO: Remove this and make the orchestrator composable # or # Probably this should be moved to each of the orchestrators, # then we wouldn't need the "all_hosts" parameter at all. host_completion = self.get_hosts() self.wait([host_completion]) all_hosts = [h.name for h in host_completion.result] completion = self.create_osds(spec, all_hosts=all_hosts) self._orchestrator_wait([completion]) return HandleCommandResult()