From d9c95e4c8bb0a2d9d7f73600d82bfd32318c37a6 Mon Sep 17 00:00:00 2001 From: ivan-zhu Date: Wed, 24 Oct 2012 16:13:01 +0800 Subject: Support for nova client list hosts with specific zone Implements one workitem of blueprint apis-for-nova-manage This add an optional QUEY_STRING(zone=xxx) in /v1.1/{tenant_id}/os-hosts. So we can also send /v1.1/{tenant_id}/os-hosts?zone=xxx now. It will only return the hosts that availability_zone=xxx. Change-Id: I89f2c0bf50f8ea1ef9f06da664f5c4b24098e5df --- nova/api/openstack/compute/contrib/hosts.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'nova/api') 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 -- cgit