summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-06-05 22:59:11 +0000
committerGerrit Code Review <review@openstack.org>2013-06-05 22:59:11 +0000
commitfc5137d764b3768f713b87dfe55133ae51b41edf (patch)
treeddfa5c87f0fdc3dec4d28738ebcbd7cecfa24a9e /nova/api
parent7f082255d47090c6bb0f8f89dcf13c2c206a4de2 (diff)
parentb27a6cb39968ebd7a1d55322779dc862682d1364 (diff)
Merge "API to get the Cell Capacity"
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/cell_capacities.py27
-rw-r--r--nova/api/openstack/compute/contrib/cells.py58
2 files changed, 81 insertions, 4 deletions
diff --git a/nova/api/openstack/compute/contrib/cell_capacities.py b/nova/api/openstack/compute/contrib/cell_capacities.py
new file mode 100644
index 000000000..ae8b42336
--- /dev/null
+++ b/nova/api/openstack/compute/contrib/cell_capacities.py
@@ -0,0 +1,27 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+# Copyright 2013 Rackspace Hosting
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License
+
+from nova.api.openstack import extensions
+
+
+class Cell_capacities(extensions.ExtensionDescriptor):
+ """Adding functionality to get cell capacities."""
+
+ name = "CellCapacities"
+ alias = "os-cell-capacities"
+ namespace = ("http://docs.openstack.org/compute/ext/"
+ "cell_capacities/api/v1.1")
+ updated = "2013-05-27T00:00:00+00:00"
diff --git a/nova/api/openstack/compute/contrib/cells.py b/nova/api/openstack/compute/contrib/cells.py
index 03597ff0e..4e809d70e 100644
--- a/nova/api/openstack/compute/contrib/cells.py
+++ b/nova/api/openstack/compute/contrib/cells.py
@@ -52,8 +52,33 @@ def make_cell(elem):
cap = xmlutil.SubTemplateElement(caps, xmlutil.Selector(0),
selector=xmlutil.get_items)
cap.text = 1
+ make_capacity(elem)
+def make_capacity(cell):
+
+ def get_units_by_mb(capacity_info):
+ return capacity_info['units_by_mb'].items()
+
+ capacity = xmlutil.SubTemplateElement(cell, 'capacities',
+ selector='capacities')
+
+ ram_free = xmlutil.SubTemplateElement(capacity, 'ram_free',
+ selector='ram_free')
+ ram_free.set('total_mb', 'total_mb')
+ unit_by_mb = xmlutil.SubTemplateElement(ram_free, 'unit_by_mb',
+ selector=get_units_by_mb)
+ unit_by_mb.set('mb', 0)
+ unit_by_mb.set('unit', 1)
+
+ disk_free = xmlutil.SubTemplateElement(capacity, 'disk_free',
+ selector='disk_free')
+ disk_free.set('total_mb', 'total_mb')
+ unit_by_mb = xmlutil.SubTemplateElement(disk_free, 'unit_by_mb',
+ selector=get_units_by_mb)
+ unit_by_mb.set('mb', 0)
+ unit_by_mb.set('unit', 1)
+
cell_nsmap = {None: wsgi.XMLNS_V10}
@@ -123,9 +148,10 @@ def _scrub_cell(cell, detail=False):
class Controller(object):
"""Controller for Cell resources."""
- def __init__(self):
+ def __init__(self, ext_mgr):
self.compute_api = compute.API()
self.cells_rpcapi = cells_rpcapi.CellsAPI()
+ self.ext_mgr = ext_mgr
def _get_cells(self, ctxt, req, detail=False):
"""Return all cells."""
@@ -168,6 +194,25 @@ class Controller(object):
return dict(cell=cell)
@wsgi.serializers(xml=CellTemplate)
+ def capacities(self, req, id=None):
+ """Return capacities for a given cell or all cells."""
+ # TODO(kaushikc): return capacities as a part of cell info and
+ # cells detail calls in v3, along with capabilities
+ if not self.ext_mgr.is_loaded('os-cell-capacities'):
+ raise exc.HTTPNotFound()
+
+ context = req.environ['nova.context']
+ authorize(context)
+ try:
+ capacities = self.cells_rpcapi.get_capacities(context,
+ cell_name=id)
+ except exception.CellNotFound:
+ msg = (_("Cell %(id)s not found.") % {'id': id})
+ raise exc.HTTPNotFound(explanation=msg)
+
+ return dict(cell={"capacities": capacities})
+
+ @wsgi.serializers(xml=CellTemplate)
def show(self, req, id):
"""Return data about the given cell name. 'id' is a cell name."""
context = req.environ['nova.context']
@@ -283,15 +328,20 @@ class Cells(extensions.ExtensionDescriptor):
name = "Cells"
alias = "os-cells"
namespace = "http://docs.openstack.org/compute/ext/cells/api/v1.1"
- updated = "2011-09-21T00:00:00+00:00"
+ updated = "2013-05-14T00:00:00+00:00"
def get_resources(self):
coll_actions = {
'detail': 'GET',
'info': 'GET',
'sync_instances': 'POST',
- }
+ 'capacities': 'GET',
+ }
+ memb_actions = {
+ 'capacities': 'GET',
+ }
res = extensions.ResourceExtension('os-cells',
- Controller(), collection_actions=coll_actions)
+ Controller(self.ext_mgr), collection_actions=coll_actions,
+ member_actions=memb_actions)
return [res]