diff options
| author | Chris Behrens <cbehrens@codestud.com> | 2013-01-16 18:49:56 +0000 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2013-02-07 07:16:50 +0000 |
| commit | a019a9007d09d190ebd3005b4c13ba78e1ec0536 (patch) | |
| tree | ffd09077be6d40a1171f9855495252dd8bd930fe /nova/api | |
| parent | be992f7b9a1b02a238b3a0c15c3de67e8aedd4ba (diff) | |
Cells: Add cells support to hypervisors extension
This removes the DB calls from the extension and moves them into
HostAPI(). The cells version of HostAPI() proxies them to the
appropriate cell or cells.
Change-Id: I17ff10e62d2f10b85a557edcc1509ca3b0d15a29
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/hypervisors.py | 39 |
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) |
