summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-02-18 01:43:18 +0000
committerGerrit Code Review <review@openstack.org>2012-02-18 01:43:18 +0000
commit77558a1cc2796f4d5e390c55e6d67f6cb92a7af4 (patch)
treefeb75ffa8eb39ca9c40b96f13c480de61d627049 /nova/api
parent1e60fa261e61b9651f7bc981033ed9d476bd6225 (diff)
parentb6b563938740269f8538748d48f7441f8e09aa37 (diff)
Merge "Add ephemeral storage to flavors api."
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/flavorextradata.py101
-rw-r--r--nova/api/openstack/compute/contrib/flavormanage.py2
2 files changed, 98 insertions, 5 deletions
diff --git a/nova/api/openstack/compute/contrib/flavorextradata.py b/nova/api/openstack/compute/contrib/flavorextradata.py
index bf6fa8040..5c86bef90 100644
--- a/nova/api/openstack/compute/contrib/flavorextradata.py
+++ b/nova/api/openstack/compute/contrib/flavorextradata.py
@@ -1,5 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
+# Copyright 2012 OpenStack, LLC
# Copyright 2011 Canonical Ltd.
# All Rights Reserved.
#
@@ -19,19 +20,111 @@
The Flavor extra data extension
Openstack API version 1.1 lists "name", "ram", "disk", "vcpus" as flavor
attributes. This extension adds to that list:
- rxtx_cap
- rxtx_quota
- swap
+ OS-FLV-EXT-DATA:ephemeral
"""
+from nova import exception
from nova.api.openstack import extensions
+from nova.api.openstack import wsgi
+from nova.api.openstack import xmlutil
+from nova.compute import instance_types
+
+
+authorize = extensions.soft_extension_authorizer('compute', 'flavorextradata')
+
+
+class FlavorextradataController(wsgi.Controller):
+ def _get_flavor_refs(self):
+ """Return a dictionary mapping flavorid to flavor_ref."""
+ flavor_refs = instance_types.get_all_types(True)
+ rval = {}
+ for name, obj in flavor_refs.iteritems():
+ rval[obj['flavorid']] = obj
+ return rval
+
+ def _extend_flavor(self, flavor_rval, flavor_ref):
+ key = "%s:ephemeral" % (Flavorextradata.alias)
+ flavor_rval[key] = flavor_ref['ephemeral_gb']
+
+ @wsgi.extends
+ def show(self, req, resp_obj, id):
+ context = req.environ['nova.context']
+ if authorize(context):
+ # Attach our slave template to the response object
+ resp_obj.attach(xml=FlavorextradatumTemplate())
+
+ try:
+ flavor_ref = instance_types.\
+ get_instance_type_by_flavor_id(id)
+ except exception.FlavorNotFound:
+ explanation = _("Flavor not found.")
+ raise exception.HTTPNotFound(explanation=explanation)
+
+ self._extend_flavor(resp_obj.obj['flavor'], flavor_ref)
+
+ @wsgi.extends
+ def detail(self, req, resp_obj):
+ context = req.environ['nova.context']
+ if authorize(context):
+ # Attach our slave template to the response object
+ resp_obj.attach(xml=FlavorextradataTemplate())
+
+ flavors = list(resp_obj.obj['flavors'])
+ flavor_refs = self._get_flavor_refs()
+
+ for flavor_rval in flavors:
+ flavor_ref = flavor_refs[flavor_rval['id']]
+ self._extend_flavor(flavor_rval, flavor_ref)
+
+ @wsgi.extends(action='create')
+ def create(self, req, body, resp_obj):
+ context = req.environ['nova.context']
+ if authorize(context):
+ # Attach our slave template to the response object
+ resp_obj.attach(xml=FlavorextradatumTemplate())
+
+ try:
+ flavor_ref = instance_types.\
+ get_instance_type_by_flavor_id(id)
+ except exception.FlavorNotFound:
+ explanation = _("Flavor not found.")
+ raise exception.HTTPNotFound(explanation=explanation)
+
+ self._extend_flavor(resp_obj.obj['flavor'], flavor_ref)
class Flavorextradata(extensions.ExtensionDescriptor):
"""Provide additional data for flavors"""
name = "FlavorExtraData"
- alias = "os-flavor-extra-data"
+ alias = "OS-FLV-EXT-DATA"
namespace = "http://docs.openstack.org/compute/ext/" \
"flavor_extra_data/api/v1.1"
updated = "2011-09-14T00:00:00+00:00"
+
+ def get_controller_extensions(self):
+ controller = FlavorextradataController()
+ extension = extensions.ControllerExtension(self, 'flavors', controller)
+ return [extension]
+
+
+def make_flavor(elem):
+ elem.set('{%s}ephemeral' % Flavorextradata.namespace,
+ '%s:ephemeral' % Flavorextradata.alias)
+
+
+class FlavorextradatumTemplate(xmlutil.TemplateBuilder):
+ def construct(self):
+ root = xmlutil.TemplateElement('flavor', selector='flavor')
+ make_flavor(root)
+ return xmlutil.SlaveTemplate(root, 1, nsmap={
+ Flavorextradata.alias: Flavorextradata.namespace})
+
+
+class FlavorextradataTemplate(xmlutil.TemplateBuilder):
+ def construct(self):
+ root = xmlutil.TemplateElement('flavors')
+ elem = xmlutil.SubTemplateElement(root, 'flavor', selector='flavors')
+ make_flavor(elem)
+ return xmlutil.SlaveTemplate(root, 1, nsmap={
+ Flavorextradata.alias: Flavorextradata.namespace})
diff --git a/nova/api/openstack/compute/contrib/flavormanage.py b/nova/api/openstack/compute/contrib/flavormanage.py
index 9aa86a8e0..3fe9bc669 100644
--- a/nova/api/openstack/compute/contrib/flavormanage.py
+++ b/nova/api/openstack/compute/contrib/flavormanage.py
@@ -62,7 +62,7 @@ class FlavorManageController(wsgi.Controller):
memory_mb = vals.get('ram')
vcpus = vals.get('vcpus')
root_gb = vals.get('disk')
- ephemeral_gb = vals.get('disk')
+ ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral')
swap = vals.get('swap')
rxtx_factor = vals.get('rxtx_factor')