summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-02-07 19:32:47 +0000
committerGerrit Code Review <review@openstack.org>2013-02-07 19:32:47 +0000
commitf8518387c01e1395ff1aae2e896e7fd9ebaf5e4a (patch)
treeaf517389cbc3f6d8d01d3fdc72b27d07bc540b21 /nova/api
parent4853996036717989542ef988deefab4b67322c55 (diff)
parenta019a9007d09d190ebd3005b4c13ba78e1ec0536 (diff)
Merge "Cells: Add cells support to hypervisors extension"
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/hypervisors.py39
1 files changed, 22 insertions, 17 deletions
diff --git a/nova/api/openstack/compute/contrib/hypervisors.py b/nova/api/openstack/compute/contrib/hypervisors.py
index 6580212a9..7e477bbf3 100644
--- a/nova/api/openstack/compute/contrib/hypervisors.py
+++ b/nova/api/openstack/compute/contrib/hypervisors.py
@@ -20,8 +20,7 @@ import webob.exc
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
-from nova.compute import api as compute_api
-from nova import db
+from nova import compute
from nova import exception
from nova.openstack.common import log as logging
@@ -128,7 +127,7 @@ class HypervisorsController(object):
"""The Hypervisors API controller for the OpenStack API."""
def __init__(self):
- self.api = compute_api.HostAPI()
+ self.host_api = compute.HostAPI()
super(HypervisorsController, self).__init__()
def _view_hypervisor(self, hypervisor, detail, servers=None, **kwargs):
@@ -164,22 +163,24 @@ class HypervisorsController(object):
def index(self, req):
context = req.environ['nova.context']
authorize(context)
+ compute_nodes = self.host_api.compute_node_get_all(context)
return dict(hypervisors=[self._view_hypervisor(hyp, False)
- for hyp in db.compute_node_get_all(context)])
+ for hyp in compute_nodes])
@wsgi.serializers(xml=HypervisorDetailTemplate)
def detail(self, req):
context = req.environ['nova.context']
authorize(context)
+ compute_nodes = self.host_api.compute_node_get_all(context)
return dict(hypervisors=[self._view_hypervisor(hyp, True)
- for hyp in db.compute_node_get_all(context)])
+ for hyp in compute_nodes])
@wsgi.serializers(xml=HypervisorTemplate)
def show(self, req, id):
context = req.environ['nova.context']
authorize(context)
try:
- hyp = db.compute_node_get(context, int(id))
+ hyp = self.host_api.compute_node_get(context, id)
except (ValueError, exception.ComputeHostNotFound):
msg = _("Hypervisor with ID '%s' could not be found.") % id
raise webob.exc.HTTPNotFound(explanation=msg)
@@ -190,7 +191,7 @@ class HypervisorsController(object):
context = req.environ['nova.context']
authorize(context)
try:
- hyp = db.compute_node_get(context, int(id))
+ hyp = self.host_api.compute_node_get(context, id)
except (ValueError, exception.ComputeHostNotFound):
msg = _("Hypervisor with ID '%s' could not be found.") % id
raise webob.exc.HTTPNotFound(explanation=msg)
@@ -198,7 +199,7 @@ class HypervisorsController(object):
# Get the uptime
try:
host = hyp['service']['host']
- uptime = self.api.get_host_uptime(context, host)
+ uptime = self.host_api.get_host_uptime(context, host)
except NotImplementedError:
msg = _("Virt driver does not implement uptime function.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
@@ -210,7 +211,8 @@ class HypervisorsController(object):
def search(self, req, id):
context = req.environ['nova.context']
authorize(context)
- hypervisors = db.compute_node_search_by_hypervisor(context, id)
+ hypervisors = self.host_api.compute_node_search_by_hypervisor(
+ context, id)
if hypervisors:
return dict(hypervisors=[self._view_hypervisor(hyp, False)
for hyp in hypervisors])
@@ -222,21 +224,24 @@ class HypervisorsController(object):
def servers(self, req, id):
context = req.environ['nova.context']
authorize(context)
- hypervisors = db.compute_node_search_by_hypervisor(context, id)
- if hypervisors:
- return dict(hypervisors=[self._view_hypervisor(hyp, False,
- db.instance_get_all_by_host(context,
- hyp['service']['host']))
- for hyp in hypervisors])
- else:
+ compute_nodes = self.host_api.compute_node_search_by_hypervisor(
+ context, id)
+ if not compute_nodes:
msg = _("No hypervisor matching '%s' could be found.") % id
raise webob.exc.HTTPNotFound(explanation=msg)
+ hypervisors = []
+ for compute_node in compute_nodes:
+ instances = self.host_api.instance_get_all_by_host(context,
+ compute_node['service']['host'])
+ hyp = self._view_hypervisor(compute_node, False, instances)
+ hypervisors.append(hyp)
+ return dict(hypervisors=hypervisors)
@wsgi.serializers(xml=HypervisorStatisticsTemplate)
def statistics(self, req):
context = req.environ['nova.context']
authorize(context)
- stats = db.compute_node_statistics(context)
+ stats = self.host_api.compute_node_statistics(context)
return dict(hypervisor_statistics=stats)