import enum
import errno
import json
-from typing import List, Set, Optional, Iterator, cast, Dict, Any, Union
+from typing import List, Set, Optional, Iterator, cast, Dict, Any, Union, Sequence
import re
import datetime
raise_if_exception, _cli_write_command, TrivialReadCompletion, OrchestratorError, \
NoOrchestrator, OrchestratorValidationError, NFSServiceSpec, \
RGWSpec, InventoryFilter, InventoryHost, HostSpec, CLICommandMeta, \
- ServiceDescription, DaemonDescription, IscsiServiceSpec, json_to_generic_spec
+ ServiceDescription, DaemonDescription, IscsiServiceSpec, json_to_generic_spec, \
+ GenericSpec
def nice_delta(now: datetime.datetime, t: Optional[datetime.datetime], suffix: str = '') -> str:
"""Add a host"""
_status = 'maintenance' if maintenance else ''
s = HostSpec(hostname=hostname, addr=addr, labels=labels, status=_status)
- completion = self.add_host(s)
- self._orchestrator_wait([completion])
- raise_if_exception(completion)
- return HandleCommandResult(stdout=completion.result_str())
+
+ return self._apply_misc([s], False, Format.plain)
@_cli_write_command('orch host rm')
def _remove_host(self, hostname: str) -> HandleCommandResult:
spec.preview_only = True
dg_specs.append(spec)
- completion = self.apply(dg_specs)
- self._orchestrator_wait([completion])
- raise_if_exception(completion)
- out = completion.result_str()
- if dry_run:
- completion = self.plan(dg_specs)
- self._orchestrator_wait([completion])
- raise_if_exception(completion)
- data = completion.result
- if format == Format.plain:
- out = generate_preview_tables(data, True)
- else:
- out = to_format(data, format, many=True, cls=None)
- return HandleCommandResult(stdout=out)
+ return self._apply_misc(dg_specs, dry_run, format)
if all_available_devices:
if unmanaged is None:
preview_only=dry_run
)
]
- # This acts weird when abstracted to a function
- completion = self.apply(dg_specs)
- self._orchestrator_wait([completion])
- raise_if_exception(completion)
- out = completion.result_str()
- if dry_run:
- completion = self.plan(dg_specs)
- self._orchestrator_wait([completion])
- data = completion.result
- if format == Format.plain:
- out = generate_preview_tables(data, True)
- else:
- out = to_format(data, format, many=True, cls=None)
- return HandleCommandResult(stdout=out)
+ return self._apply_misc(dg_specs, dry_run, format)
return HandleCommandResult(-errno.EINVAL, stderr=usage)
return HandleCommandResult(stdout=completion.result_str())
@_cli_write_command('orch apply')
- def _apply_misc(self,
- service_type: Optional[ServiceType] = None,
- placement: Optional[str] = None,
- dry_run: bool = False,
- format: Format = Format.plain,
- unmanaged: bool = False,
- inbuf: Optional[str] = None) -> HandleCommandResult:
+ def apply_misc(self,
+ service_type: Optional[ServiceType] = None,
+ placement: Optional[str] = None,
+ dry_run: bool = False,
+ format: Format = Format.plain,
+ unmanaged: bool = False,
+ inbuf: Optional[str] = None) -> HandleCommandResult:
"""Update the size or placement for a service or apply a large yaml spec"""
usage = """Usage:
ceph orch apply -i <yaml spec> [--dry-run]
raise OrchestratorValidationError(usage)
specs = [ServiceSpec(service_type.value, placement=placementspec,
unmanaged=unmanaged, preview_only=dry_run)]
+ return self._apply_misc(specs, dry_run, format)
+ def _apply_misc(self, specs: Sequence[GenericSpec], dry_run: bool, format: Format) -> HandleCommandResult:
completion = self.apply(specs)
self._orchestrator_wait([completion])
raise_if_exception(completion)
placement=PlacementSpec.from_string(placement),
unmanaged=unmanaged,
preview_only=dry_run)
-
- completion = self.apply_mds(spec)
- self._orchestrator_wait([completion])
- raise_if_exception(completion)
- out = completion.result_str()
- if dry_run:
- completion_plan = self.plan([spec])
- self._orchestrator_wait([completion_plan])
- raise_if_exception(completion_plan)
- data = completion_plan.result
- if format == Format.plain:
- out = preview_table_services(data)
- else:
- out = to_format(data, format, many=True, cls=None)
- return HandleCommandResult(stdout=out)
+ return self._apply_misc([spec], dry_run, format)
@_cli_write_command('orch apply rgw')
def _apply_rgw(self,
preview_only=dry_run
)
- completion = self.apply_rgw(spec)
- self._orchestrator_wait([completion])
- raise_if_exception(completion)
- out = completion.result_str()
- if dry_run:
- completion_plan = self.plan([spec])
- self._orchestrator_wait([completion_plan])
- raise_if_exception(completion_plan)
- data = completion_plan.result
- if format == Format.plain:
- out = preview_table_services(data)
- else:
- out = to_format(data, format, many=True, cls=None)
- return HandleCommandResult(stdout=out)
+ return self._apply_misc([spec], dry_run, format)
@_cli_write_command('orch apply nfs')
def _apply_nfs(self,
preview_only=dry_run
)
- completion = self.apply_nfs(spec)
- self._orchestrator_wait([completion])
- raise_if_exception(completion)
- out = completion.result_str()
- if dry_run:
- completion_plan = self.plan([spec])
- self._orchestrator_wait([completion_plan])
- raise_if_exception(completion_plan)
- data = completion_plan.result
- if format == Format.plain:
- out = preview_table_services(data)
- else:
- out = to_format(data, format, many=True, cls=None)
- return HandleCommandResult(stdout=out)
+ return self._apply_misc([spec], dry_run, format)
@_cli_write_command('orch apply iscsi')
def _apply_iscsi(self,
preview_only=dry_run
)
- completion = self.apply_iscsi(spec)
- self._orchestrator_wait([completion])
- raise_if_exception(completion)
- out = completion.result_str()
- if dry_run:
- completion_plan = self.plan([spec])
- self._orchestrator_wait([completion_plan])
- raise_if_exception(completion_plan)
- data = completion_plan.result
- if format == Format.plain:
- out = preview_table_services(data)
- else:
- out = to_format(data, format, many=True, cls=None)
- return HandleCommandResult(stdout=out)
+ return self._apply_misc([spec], dry_run, format)
@_cli_write_command('orch set backend')
def _set_backend(self, module_name: Optional[str] = None) -> HandleCommandResult: