return 'Added label %s to host %s' % (label, host)
@handle_orch_error
- def remove_host_label(self, host: str, label: str) -> str:
+ def remove_host_label(self, host: str, label: str, force: bool = False) -> str:
+ # if we remove the _admin label from the only host that has it we could end up
+ # removing the only instance of the config and keyring and cause issues
+ if not force and label == '_admin':
+ p = PlacementSpec(label='_admin')
+ admin_hosts = p.filter_matching_hostspecs(self.inventory.all_specs())
+ if len(admin_hosts) == 1 and admin_hosts[0] == host:
+ raise OrchestratorValidationError(f"Host {host} is the last host with the '_admin'"
+ " label.\nRemoving the _admin label from this host could cause the removal"
+ " of the last cluster config/keyring managed by cephadm.\n"
+ "It is recommended to add the _admin label to another host"
+ " before completing this operation.\nIf you're certain this is"
+ " what you want rerun this command with --force.")
self.inventory.rm_label(host, label)
self.log.info('Removed label %s to host %s' % (label, host))
self._kick_serve_loop()
"""
raise NotImplementedError()
- def remove_host_label(self, host: str, label: str) -> OrchResult[str]:
+ def remove_host_label(self, host: str, label: str, force: bool = False) -> OrchResult[str]:
"""
Remove a host label
"""
return HandleCommandResult(stdout=completion.result_str())
@_cli_write_command('orch host label rm')
- def _host_label_rm(self, hostname: str, label: str) -> HandleCommandResult:
+ def _host_label_rm(self, hostname: str, label: str, force: bool = False) -> HandleCommandResult:
"""Remove a host label"""
- completion = self.remove_host_label(hostname, label)
+ completion = self.remove_host_label(hostname, label, force)
raise_if_exception(completion)
return HandleCommandResult(stdout=completion.result_str())
def add_host_label(self, host: str, label: str) -> OrchResult[str]:
return self.rook_cluster.add_host_label(host, label)
- def remove_host_label(self, host: str, label: str) -> OrchResult[str]:
+ def remove_host_label(self, host: str, label: str, force: bool = False) -> OrchResult[str]:
return self.rook_cluster.remove_host_label(host, label)
"""
@handle_orch_error