]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Show labels in hosts page
authorVolker Theile <vtheile@suse.com>
Thu, 4 Jun 2020 08:58:08 +0000 (10:58 +0200)
committerVolker Theile <vtheile@suse.com>
Thu, 4 Jun 2020 13:41:27 +0000 (15:41 +0200)
Fixes: https://tracker.ceph.com/issues/45856
Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/controllers/host.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts

index 3a90389bba578851e1a7fcbdb0095b99a9507165..5995161bee1098d5e5eb4e929203b167db2ed636 100644 (file)
@@ -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()
index 18d720e41d7f5c3724d5184c77a46014b0db4020..9fff78b96938df350b7c25f204ab50d9be75386e 100644 (file)
@@ -74,7 +74,8 @@ describe('HostsComponent', () => {
           }
         ],
         hostname: hostname,
-        ceph_version: 'ceph version Development'
+        ceph_version: 'ceph version Development',
+        labels: ['foo', 'bar']
       }
     ];
 
index de4a7069fabacabeed0bba930326f49208f1a425..91e9faa7f2cbe67c45d07d5d6b9a808f9f2686e7 100644 (file)
@@ -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',