From: Volker Theile Date: Thu, 4 Jun 2020 08:58:08 +0000 (+0200) Subject: mgr/dashboard: Show labels in hosts page X-Git-Tag: v16.1.0~2115^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F35379%2Fhead;p=ceph.git mgr/dashboard: Show labels in hosts page Fixes: https://tracker.ceph.com/issues/45856 Signed-off-by: Volker Theile --- diff --git a/src/pybind/mgr/dashboard/controllers/host.py b/src/pybind/mgr/dashboard/controllers/host.py index 3a90389bba57..5995161bee10 100644 --- a/src/pybind/mgr/dashboard/controllers/host.py +++ b/src/pybind/mgr/dashboard/controllers/host.py @@ -30,29 +30,52 @@ def merge_hosts_by_hostname(ceph_hosts, orch_hosts): :type orch_hosts: list of HostSpec :return list of dict """ - _ceph_hosts = copy.deepcopy(ceph_hosts) - orch_hostnames = {host.hostname for host in orch_hosts} - - # hosts in both Ceph and Orchestrator - for ceph_host in _ceph_hosts: - if ceph_host['hostname'] in orch_hostnames: - ceph_host['sources']['orchestrator'] = True - orch_hostnames.remove(ceph_host['hostname']) + hosts = copy.deepcopy(ceph_hosts) + orch_hosts_map = { + host.hostname: { + 'labels': host.labels + } + for host in orch_hosts + } + + # Hosts in both Ceph and Orchestrator + for host in hosts: + hostname = host['hostname'] + if hostname in orch_hosts_map: + host['labels'] = orch_hosts_map[hostname]['labels'] + host['sources']['orchestrator'] = True + orch_hosts_map.pop(hostname) # Hosts only in Orchestrator - orch_sources = {'ceph': False, 'orchestrator': True} - _orch_hosts = [dict(hostname=hostname, ceph_version='', services=[], sources=orch_sources) - for hostname in orch_hostnames] - _ceph_hosts.extend(_orch_hosts) - return _ceph_hosts + orch_hosts_only = [ + dict(hostname=hostname, + ceph_version='', + labels=orch_hosts_map[hostname]['labels'], + services=[], + sources={ + 'ceph': False, + 'orchestrator': True + }) for hostname in orch_hosts_map + ] + hosts.extend(orch_hosts_only) + return hosts def get_hosts(from_ceph=True, from_orchestrator=True): - """get hosts from various sources""" + """ + Get hosts from various sources. + """ ceph_hosts = [] if from_ceph: - ceph_hosts = [merge_dicts(server, {'sources': {'ceph': True, 'orchestrator': False}}) - for server in mgr.list_servers()] + ceph_hosts = [ + merge_dicts(server, { + 'labels': [], + 'sources': { + 'ceph': True, + 'orchestrator': False + } + }) for server in mgr.list_servers() + ] if from_orchestrator: orch = OrchClient.instance() if orch.available(): @@ -62,7 +85,6 @@ def get_hosts(from_ceph=True, from_orchestrator=True): @ApiController('/host', Scope.HOSTS) class Host(RESTController): - def list(self, sources=None): if sources is None: return get_hosts() diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts index 18d720e41d7f..9fff78b96938 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts @@ -74,7 +74,8 @@ describe('HostsComponent', () => { } ], hostname: hostname, - ceph_version: 'ceph version Development' + ceph_version: 'ceph version Development', + labels: ['foo', 'bar'] } ]; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts index de4a7069faba..91e9faa7f2cb 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts @@ -16,6 +16,7 @@ import { CdTableSelection } from '../../../shared/models/cd-table-selection'; import { FinishedTask } from '../../../shared/models/finished-task'; import { Permissions } from '../../../shared/models/permissions'; import { CephShortVersionPipe } from '../../../shared/pipes/ceph-short-version.pipe'; +import { JoinPipe } from '../../../shared/pipes/join.pipe'; import { AuthStorageService } from '../../../shared/services/auth-storage.service'; import { DepCheckerService } from '../../../shared/services/dep-checker.service'; import { TaskWrapperService } from '../../../shared/services/task-wrapper.service'; @@ -46,6 +47,7 @@ export class HostsComponent extends ListWithDetails implements OnInit { private authStorageService: AuthStorageService, private hostService: HostService, private cephShortVersionPipe: CephShortVersionPipe, + private joinPipe: JoinPipe, private i18n: I18n, private urlBuilder: URLBuilderService, private actionLabels: ActionLabelsI18n, @@ -100,6 +102,12 @@ export class HostsComponent extends ListWithDetails implements OnInit { flexGrow: 3, cellTemplate: this.servicesTpl }, + { + name: this.i18n('Labels'), + prop: 'labels', + flexGrow: 1, + pipe: this.joinPipe + }, { name: this.i18n('Version'), prop: 'ceph_version',