diff --git a/novaclient/tests/unit/fixture_data/hosts.py b/novaclient/tests/unit/fixture_data/hosts.py index 28ff17ef1..160eb3989 100644 --- a/novaclient/tests/unit/fixture_data/hosts.py +++ b/novaclient/tests/unit/fixture_data/hosts.py @@ -62,12 +62,12 @@ class BaseFixture(base.Fixture): return { 'hosts': [ { - 'host': 'host1', + 'host_name': 'host1', 'service': service or 'nova-compute', 'zone': zone }, { - 'host': 'host1', + 'host_name': 'host1', 'service': service or 'nova-cert', 'zone': zone } diff --git a/novaclient/tests/unit/v2/test_hosts.py b/novaclient/tests/unit/v2/test_hosts.py index d99627b09..8f77e01b4 100644 --- a/novaclient/tests/unit/v2/test_hosts.py +++ b/novaclient/tests/unit/v2/test_hosts.py @@ -85,3 +85,8 @@ class HostsTest(utils.FixturedTestCase): def test_hosts_repr(self): hs = self.cs.hosts.get('host') self.assertEqual('', repr(hs[0])) + + def test_hosts_list_repr(self): + hs = self.cs.hosts.list() + for h in hs: + self.assertEqual('' % h.host_name, repr(h)) diff --git a/novaclient/v2/hosts.py b/novaclient/v2/hosts.py index af1756ad2..0f979973b 100644 --- a/novaclient/v2/hosts.py +++ b/novaclient/v2/hosts.py @@ -40,6 +40,18 @@ class Host(base.Resource): def reboot(self): return self.manager.host_action(self.host, 'reboot') + @property + def host_name(self): + return self.host + + @host_name.setter + def host_name(self, value): + # A host from hosts.list() has the attribute "host_name" instead of + # "host." This sets "host" if that's the case. Even though it doesn't + # exactly mirror the response format, it enables users to work with + # host objects from list and non-list operations interchangeably. + self.host = value + class HostManager(base.ManagerWithFind): resource_class = Host