summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/api/openstack/compute/contrib/hosts.py11
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_hosts.py30
2 files changed, 30 insertions, 11 deletions
diff --git a/nova/api/openstack/compute/contrib/hosts.py b/nova/api/openstack/compute/contrib/hosts.py
index 95a80f3f6..67fc897fb 100644
--- a/nova/api/openstack/compute/contrib/hosts.py
+++ b/nova/api/openstack/compute/contrib/hosts.py
@@ -98,13 +98,18 @@ def _list_hosts(req, service=None):
"""
context = req.environ['nova.context']
services = db.service_get_all(context, False)
-
+ zone = ''
+ if 'zone' in req.GET:
+ zone = req.GET['zone']
+ if zone:
+ services = [s for s in services if s['availability_zone'] == zone]
hosts = []
for host in services:
- hosts.append({"host_name": host['host'], 'service': host['topic']})
+ hosts.append({"host_name": host['host'], 'service': host['topic'],
+ 'zone': host['availability_zone']})
if service:
hosts = [host for host in hosts
- if host["service"] == service]
+ if host["service"] == service]
return hosts
diff --git a/nova/tests/api/openstack/compute/contrib/test_hosts.py b/nova/tests/api/openstack/compute/contrib/test_hosts.py
index 570b13473..b2b5407f5 100644
--- a/nova/tests/api/openstack/compute/contrib/test_hosts.py
+++ b/nova/tests/api/openstack/compute/contrib/test_hosts.py
@@ -29,15 +29,18 @@ from nova import test
FLAGS = flags.FLAGS
LOG = logging.getLogger(__name__)
HOST_LIST = [
- {"host_name": "host_c1", "service": "compute"},
- {"host_name": "host_c2", "service": "compute"},
- {"host_name": "host_v1", "service": "volume"},
- {"host_name": "host_v2", "service": "volume"}]
+ {"host_name": "host_c1", "service": "compute", "zone": "nova"},
+ {"host_name": "host_c2", "service": "compute", "zone": "nonova"},
+ {"host_name": "host_v1", "service": "volume", "zone": "nova"},
+ {"host_name": "host_v2", "service": "volume", "zone": "nonova"}]
+HOST_LIST_NOVA_ZONE = [
+ {"host_name": "host_c1", "service": "compute", "zone": "nova"},
+ {"host_name": "host_v1", "service": "volume", "zone": "nova"}]
SERVICES_LIST = [
- {"host": "host_c1", "topic": "compute"},
- {"host": "host_c2", "topic": "compute"},
- {"host": "host_v1", "topic": "volume"},
- {"host": "host_v2", "topic": "volume"}]
+ {"host": "host_c1", "topic": "compute", "availability_zone": "nova"},
+ {"host": "host_c2", "topic": "compute", "availability_zone": "nonova"},
+ {"host": "host_v1", "topic": "volume", "availability_zone": "nova"},
+ {"host": "host_v2", "topic": "volume", "availability_zone": "nonova"}]
def stub_service_get_all(self, req):
@@ -97,6 +100,12 @@ def _create_instance_dict(**kwargs):
class FakeRequest(object):
environ = {"nova.context": context.get_admin_context()}
+ GET = {}
+
+
+class FakeRequestWithNovaZone(object):
+ environ = {"nova.context": context.get_admin_context()}
+ GET = {"zone": "nova"}
class HostTestCase(test.TestCase):
@@ -130,6 +139,11 @@ class HostTestCase(test.TestCase):
if host["service"] == "compute"]
self.assertEqual(compute_hosts, expected)
+ def test_list_hosts_with_zone(self):
+ req = FakeRequestWithNovaZone()
+ hosts = os_hosts._list_hosts(req)
+ self.assertEqual(hosts, HOST_LIST_NOVA_ZONE)
+
def test_disable_host(self):
self._test_host_update('host_c1', 'status', 'disable', 'disabled')
self._test_host_update('host_c2', 'status', 'disable', 'enabled')