]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orch: include addr (and labels) in 'host ls'
authorSage Weil <sage@redhat.com>
Thu, 6 Feb 2020 03:33:34 +0000 (21:33 -0600)
committerSage Weil <sage@redhat.com>
Fri, 7 Feb 2020 19:36:45 +0000 (13:36 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/dashboard/tests/test_orchestrator.py
src/pybind/mgr/orchestrator.py
src/pybind/mgr/orchestrator_cli/module.py
src/pybind/mgr/tests/test_orchestrator.py

index a882d026f365d3f7c89f837305406bd9ac59cb56..67414a2b0381ba997bdc9d64e4beab6295b1f7a7 100644 (file)
@@ -1184,7 +1184,15 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
         TODO:
           - InventoryNode probably needs to be able to report labels
         """
-        return [orchestrator.InventoryNode(host_name) for host_name in self.inventory_cache]
+        r = []
+        for hostname, info in self.inventory.items():
+            self.log.debug('host %s info %s' % (hostname, info))
+            r.append(orchestrator.InventoryNode(
+                hostname,
+                addr=info.get('addr', hostname),
+                labels=info.get('labels', []),
+            ))
+        return r
 
     @async_completion
     def add_host_label(self, host, label):
index 2817a69168095dd00c154d39a0d99ded520af535..1a5ff9d373933ca2af2fce6d047eafa135be1cd3 100644 (file)
@@ -71,6 +71,7 @@ class OrchestratorControllerTest(ControllerTestCase):
         inventory = [
             {
                 'name': 'host-0',
+                'addr': '1.2.3.4',
                 'devices': [
                     {'path': 'nvme0n1'},
                     {'path': '/dev/sdb'},
@@ -79,6 +80,7 @@ class OrchestratorControllerTest(ControllerTestCase):
             },
             {
                 'name': 'host-1',
+                'addr': '1.2.3.5',
                 'devices': [
                     {'path': '/dev/sda'},
                     {'path': 'sdb'},
@@ -97,11 +99,13 @@ class OrchestratorControllerTest(ControllerTestCase):
         self.assertEqual(len(resp), 2)
         host0 = resp[0]
         self.assertEqual(host0['name'], 'host-0')
+        self.assertEqual(host0['addr'], '1.2.3.4')
         self.assertEqual(host0['devices'][0]['osd_ids'], [1, 2])
         self.assertEqual(host0['devices'][1]['osd_ids'], [1])
         self.assertEqual(host0['devices'][2]['osd_ids'], [2])
         host1 = resp[1]
         self.assertEqual(host1['name'], 'host-1')
+        self.assertEqual(host1['addr'], '1.2.3.5')
         self.assertEqual(host1['devices'][0]['osd_ids'], [])
         self.assertEqual(host1['devices'][1]['osd_ids'], [3])
 
index f926fee1868e06bdb5196b375dcb48eaddd041fb..78214b6296c48ce123e66360c7e360cea1412ba0 100644 (file)
@@ -1360,8 +1360,8 @@ class InventoryNode(object):
     When fetching inventory, all Devices are groups inside of an
     InventoryNode.
     """
-    def __init__(self, name, devices=None, labels=None):
-        # type: (str, Optional[inventory.Devices], Optional[List[str]]) -> None
+    def __init__(self, name, devices=None, labels=None, addr=None):
+        # type: (str, Optional[inventory.Devices], Optional[List[str]], Optional[str]) -> None
         if devices is None:
             devices = inventory.Devices([])
         if labels is None:
@@ -1369,12 +1369,14 @@ class InventoryNode(object):
         assert isinstance(devices, inventory.Devices)
 
         self.name = name  # unique within cluster.  For example a hostname.
+        self.addr = addr or name
         self.devices = devices
         self.labels = labels
 
     def to_json(self):
         return {
             'name': self.name,
+            'addr': self.addr,
             'devices': self.devices.to_json(),
             'labels': self.labels,
         }
@@ -1384,12 +1386,13 @@ class InventoryNode(object):
         try:
             _data = copy.deepcopy(data)
             name = _data.pop('name')
+            addr = _data.pop('addr') or name
             devices = inventory.Devices.from_json(_data.pop('devices'))
             if _data:
                 error_msg = 'Unknown key(s) in Inventory: {}'.format(','.join(_data.keys()))
                 raise OrchestratorValidationError(error_msg)
             labels = _data.get('labels', list())
-            return cls(name, devices, labels)
+            return cls(name, devices, labels, addr)
         except KeyError as e:
             error_msg = '{} is required for {}'.format(e, cls.__name__)
             raise OrchestratorValidationError(error_msg)
index 94c2dd2984938cab21fa739f7679e5c1dd4c89ed..5c5946a6c96ddf167dfd704ef194535bdcae8948 100644 (file)
@@ -192,13 +192,13 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule):
             output = json.dumps(hosts, sort_keys=True)
         else:
             table = PrettyTable(
-                ['HOST', 'LABELS'],
+                ['HOST', 'ADDR', 'LABELS'],
                 border=False)
             table.align = 'l'
             table.left_padding_width = 0
             table.right_padding_width = 1
             for node in completion.result:
-                table.add_row((node.name, ' '.join(node.labels)))
+                table.add_row((node.name, node.addr, ' '.join(node.labels)))
             output = table.get_string()
         return HandleCommandResult(stdout=output)
 
index b86e8cb5fe759e4018959fd25cb6e00fca2e25b4..a1b6dae3b8f59ef63a776c5140f890cd030f675d 100644 (file)
@@ -57,6 +57,7 @@ def _test_resource(data, resource_class, extra=None):
 def test_inventory():
     json_data = {
         'name': 'host0',
+        'addr': '1.2.3.4',
         'devices': [
             {
                 'sys_api': {
@@ -74,7 +75,7 @@ def test_inventory():
     for devices in json_data['devices']:
         _test_resource(devices, inventory.Device)
 
-    json_data = [{}, {'name': 'host0'}, {'devices': []}]
+    json_data = [{}, {'name': 'host0', 'addr': '1.2.3.4'}, {'devices': []}]
     for data in json_data:
         with pytest.raises(OrchestratorValidationError):
             InventoryNode.from_json(data)