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')
+ if not force and label == SpecialHostLabels.ADMIN:
+ p = PlacementSpec(label=SpecialHostLabels.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"
+ raise OrchestratorValidationError(f"Host {host} is the last host with the '{SpecialHostLabels.ADMIN}'"
+ f" label.\nRemoving the {SpecialHostLabels.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"
+ f"It is recommended to add the {SpecialHostLabels.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))
+ if self.inventory.has_label(host, label):
+ self.inventory.rm_label(host, label)
+ msg = f'Removed label {label} from host {host}'
+ else:
+ msg = f"Host {host} does not have label '{label}'. Please use 'ceph orch host ls' to list all the labels."
+ self.log.info(msg)
self._kick_serve_loop()
- return 'Removed label %s from host %s' % (label, host)
+ return msg
def _host_ok_to_stop(self, hostname: str, force: bool = False) -> Tuple[int, str]:
self.log.debug("running host-ok-to-stop checks")