Browse Source

Display hostname in the default formatter

Change-Id: If6021ee5449cf74159640fdcc3f248c9f99a4105
Dmitry Tantsur 1 month ago
parent
commit
2aeb60434e

+ 3
- 0
metalsmith/_format.py View File

@@ -60,6 +60,9 @@ class DefaultFormat(object):
60 60
                    node=_utils.log_res(instance.node),
61 61
                    state=instance.state.name)
62 62
 
63
+            if instance.hostname:
64
+                _print('* Hostname: %(hostname)s', hostname=instance.hostname)
65
+
63 66
             if instance.is_deployed:
64 67
                 ips = instance.ip_addresses()
65 68
                 if ips:

+ 26
- 0
metalsmith/test/test_cmd.py View File

@@ -79,6 +79,7 @@ class TestDeploy(testtools.TestCase):
79 79
         instance.state = _instance.InstanceState.ACTIVE
80 80
         instance.is_deployed = True
81 81
         instance.ip_addresses.return_value = {'private': ['1.2.3.4']}
82
+        instance.hostname = None
82 83
 
83 84
         args = ['deploy', '--network', 'mynet', '--image', 'myimg',
84 85
                 '--resource-class', 'compute']
@@ -133,6 +134,7 @@ class TestDeploy(testtools.TestCase):
133 134
         instance.node.name = None
134 135
         instance.node.id = '123'
135 136
         instance.state = _instance.InstanceState.ACTIVE
137
+        instance.hostname = None
136 138
 
137 139
         args = ['deploy', '--network', 'mynet', '--image', 'myimg',
138 140
                 '--resource-class', 'compute']
@@ -148,6 +150,7 @@ class TestDeploy(testtools.TestCase):
148 150
         instance.node.name = None
149 151
         instance.node.id = '123'
150 152
         instance.state = _instance.InstanceState.DEPLOYING
153
+        instance.hostname = None
151 154
 
152 155
         args = ['deploy', '--network', 'mynet', '--image', 'myimg',
153 156
                 '--resource-class', 'compute']
@@ -355,10 +358,25 @@ class TestDeploy(testtools.TestCase):
355 358
         self.assertFalse(mock_pr.return_value.provision_node.called)
356 359
 
357 360
     def test_args_hostname(self, mock_pr):
361
+        instance = mock_pr.return_value.provision_node.return_value
362
+        instance.create_autospec(_instance.Instance)
363
+        instance.is_deployed = True
364
+        instance.node.name = None
365
+        instance.node.id = '123'
366
+        instance.state = _instance.InstanceState.ACTIVE
367
+        instance.hostname = 'host'
368
+        instance.ip_addresses.return_value = {'private': ['1.2.3.4']}
369
+
358 370
         args = ['deploy', '--network', 'mynet', '--image', 'myimg',
359 371
                 '--hostname', 'host', '--resource-class', 'compute']
360 372
         self._check(mock_pr, args, {}, {'hostname': 'host'})
361 373
 
374
+        self.mock_print.assert_has_calls([
375
+            mock.call(mock.ANY, node='123', state='ACTIVE'),
376
+            mock.call(mock.ANY, hostname='host'),
377
+            mock.call(mock.ANY, ips='private=1.2.3.4')
378
+        ])
379
+
362 380
     def test_args_with_candidates(self, mock_pr):
363 381
         args = ['deploy', '--network', 'mynet', '--image', 'myimg',
364 382
                 '--candidate', 'node1', '--candidate', 'node2',
@@ -601,8 +619,10 @@ class TestShowWait(testtools.TestCase):
601 619
 
602 620
         self.mock_print.assert_has_calls([
603 621
             mock.call(mock.ANY, node='name-1 (UUID 1)', state='ACTIVE'),
622
+            mock.call(mock.ANY, hostname='hostname1'),
604 623
             mock.call(mock.ANY, ips='private=1.2.3.4'),
605 624
             mock.call(mock.ANY, node='name-2 (UUID 2)', state='DEPLOYING'),
625
+            mock.call(mock.ANY, hostname='hostname2'),
606 626
         ])
607 627
         mock_pr.return_value.show_instances.assert_called_once_with(
608 628
             ['uuid1', 'hostname2'])
@@ -614,8 +634,10 @@ class TestShowWait(testtools.TestCase):
614 634
 
615 635
         self.mock_print.assert_has_calls([
616 636
             mock.call(mock.ANY, node='name-1 (UUID 1)', state='ACTIVE'),
637
+            mock.call(mock.ANY, hostname='hostname1'),
617 638
             mock.call(mock.ANY, ips='private=1.2.3.4'),
618 639
             mock.call(mock.ANY, node='name-2 (UUID 2)', state='DEPLOYING'),
640
+            mock.call(mock.ANY, hostname='hostname2'),
619 641
         ])
620 642
         mock_pr.return_value.list_instances.assert_called_once_with()
621 643
 
@@ -627,8 +649,10 @@ class TestShowWait(testtools.TestCase):
627 649
 
628 650
         self.mock_print.assert_has_calls([
629 651
             mock.call(mock.ANY, node='name-1 (UUID 1)', state='ACTIVE'),
652
+            mock.call(mock.ANY, hostname='hostname1'),
630 653
             mock.call(mock.ANY, ips='private=1.2.3.4'),
631 654
             mock.call(mock.ANY, node='name-2 (UUID 2)', state='DEPLOYING'),
655
+            mock.call(mock.ANY, hostname='hostname2'),
632 656
         ])
633 657
         mock_pr.return_value.wait_for_provisioning.assert_called_once_with(
634 658
             ['uuid1', 'hostname2'], timeout=None)
@@ -641,8 +665,10 @@ class TestShowWait(testtools.TestCase):
641 665
 
642 666
         self.mock_print.assert_has_calls([
643 667
             mock.call(mock.ANY, node='name-1 (UUID 1)', state='ACTIVE'),
668
+            mock.call(mock.ANY, hostname='hostname1'),
644 669
             mock.call(mock.ANY, ips='private=1.2.3.4'),
645 670
             mock.call(mock.ANY, node='name-2 (UUID 2)', state='DEPLOYING'),
671
+            mock.call(mock.ANY, hostname='hostname2'),
646 672
         ])
647 673
         mock_pr.return_value.wait_for_provisioning.assert_called_once_with(
648 674
             ['uuid1', 'hostname2'], timeout=42)

+ 4
- 0
releasenotes/notes/format-hostname-634a412ea933a966.yaml View File

@@ -0,0 +1,4 @@
1
+---
2
+features:
3
+  - |
4
+    Hostname is now displayed in the default format when displaying instances.

Loading…
Cancel
Save