summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/flavor_rxtx.py87
-rw-r--r--nova/api/openstack/compute/contrib/flavor_swap.py87
-rw-r--r--nova/api/openstack/compute/flavors.py4
-rw-r--r--nova/api/openstack/compute/schemas/v1.1/flavor.rng2
-rw-r--r--nova/api/openstack/compute/views/flavors.py2
5 files changed, 175 insertions, 7 deletions
diff --git a/nova/api/openstack/compute/contrib/flavor_rxtx.py b/nova/api/openstack/compute/contrib/flavor_rxtx.py
new file mode 100644
index 000000000..6dce1bee1
--- /dev/null
+++ b/nova/api/openstack/compute/contrib/flavor_rxtx.py
@@ -0,0 +1,87 @@
+# Copyright 2012 Nebula, Inc.
+#
+# 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.
+
+"""The Flavor Rxtx API extension."""
+
+from nova.api.openstack import extensions
+from nova.api.openstack import wsgi
+from nova.api.openstack import xmlutil
+
+
+authorize = extensions.soft_extension_authorizer('compute', 'flavor_rxtx')
+
+
+class FlavorRxtxController(wsgi.Controller):
+ def _extend_flavors(self, req, flavors):
+ for flavor in flavors:
+ db_flavor = req.get_db_flavor(flavor['id'])
+ key = 'rxtx_factor'
+ flavor[key] = db_flavor['rxtx_factor'] or ""
+
+ def _show(self, req, resp_obj):
+ if not authorize(req.environ['nova.context']):
+ return
+ if 'flavor' in resp_obj.obj:
+ resp_obj.attach(xml=FlavorRxtxTemplate())
+ self._extend_flavors(req, [resp_obj.obj['flavor']])
+
+ @wsgi.extends
+ def show(self, req, resp_obj, id):
+ return self._show(req, resp_obj)
+
+ @wsgi.extends(action='create')
+ def create(self, req, resp_obj, body):
+ return self._show(req, resp_obj)
+
+ @wsgi.extends
+ def detail(self, req, resp_obj):
+ if not authorize(req.environ['nova.context']):
+ return
+ resp_obj.attach(xml=FlavorsRxtxTemplate())
+ self._extend_flavors(req, list(resp_obj.obj['flavors']))
+
+
+class Flavor_rxtx(extensions.ExtensionDescriptor):
+ """Support to show the rxtx status of a flavor"""
+
+ name = "FlavorRxtx"
+ alias = "os-flavor-rxtx"
+ namespace = ("http://docs.openstack.org/compute/ext/"
+ "flavor_rxtx/api/v1.1")
+ updated = "2012-08-29T00:00:00+00:00"
+
+ def get_controller_extensions(self):
+ controller = FlavorRxtxController()
+ extension = extensions.ControllerExtension(self, 'flavors', controller)
+ return [extension]
+
+
+def make_flavor(elem):
+ # NOTE(vish): this was originally added without a namespace
+ elem.set('rxtx_factor', xmlutil.EmptyStringSelector('rxtx_factor'))
+
+
+class FlavorRxtxTemplate(xmlutil.TemplateBuilder):
+ def construct(self):
+ root = xmlutil.TemplateElement('flavor', selector='flavor')
+ make_flavor(root)
+ return xmlutil.SlaveTemplate(root, 1)
+
+
+class FlavorsRxtxTemplate(xmlutil.TemplateBuilder):
+ def construct(self):
+ root = xmlutil.TemplateElement('flavors')
+ elem = xmlutil.SubTemplateElement(root, 'flavor', selector='flavors')
+ make_flavor(elem)
+ return xmlutil.SlaveTemplate(root, 1)
diff --git a/nova/api/openstack/compute/contrib/flavor_swap.py b/nova/api/openstack/compute/contrib/flavor_swap.py
new file mode 100644
index 000000000..8e0277979
--- /dev/null
+++ b/nova/api/openstack/compute/contrib/flavor_swap.py
@@ -0,0 +1,87 @@
+# Copyright 2012 Nebula, Inc.
+#
+# 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.
+
+"""The Flavor Swap API extension."""
+
+from nova.api.openstack import extensions
+from nova.api.openstack import wsgi
+from nova.api.openstack import xmlutil
+
+
+authorize = extensions.soft_extension_authorizer('compute', 'flavor_swap')
+
+
+class FlavorSwapController(wsgi.Controller):
+ def _extend_flavors(self, req, flavors):
+ for flavor in flavors:
+ db_flavor = req.get_db_flavor(flavor['id'])
+ key = 'swap'
+ flavor[key] = db_flavor['swap'] or ""
+
+ def _show(self, req, resp_obj):
+ if not authorize(req.environ['nova.context']):
+ return
+ if 'flavor' in resp_obj.obj:
+ resp_obj.attach(xml=FlavorSwapTemplate())
+ self._extend_flavors(req, [resp_obj.obj['flavor']])
+
+ @wsgi.extends
+ def show(self, req, resp_obj, id):
+ return self._show(req, resp_obj)
+
+ @wsgi.extends(action='create')
+ def create(self, req, resp_obj, body):
+ return self._show(req, resp_obj)
+
+ @wsgi.extends
+ def detail(self, req, resp_obj):
+ if not authorize(req.environ['nova.context']):
+ return
+ resp_obj.attach(xml=FlavorsSwapTemplate())
+ self._extend_flavors(req, list(resp_obj.obj['flavors']))
+
+
+class Flavor_swap(extensions.ExtensionDescriptor):
+ """Support to show the swap status of a flavor"""
+
+ name = "FlavorSwap"
+ alias = "os-flavor-swap"
+ namespace = ("http://docs.openstack.org/compute/ext/"
+ "flavor_swap/api/v1.1")
+ updated = "2012-08-29T00:00:00+00:00"
+
+ def get_controller_extensions(self):
+ controller = FlavorSwapController()
+ extension = extensions.ControllerExtension(self, 'flavors', controller)
+ return [extension]
+
+
+def make_flavor(elem):
+ # NOTE(vish): this was originally added without a namespace
+ elem.set('swap', xmlutil.EmptyStringSelector('swap'))
+
+
+class FlavorSwapTemplate(xmlutil.TemplateBuilder):
+ def construct(self):
+ root = xmlutil.TemplateElement('flavor', selector='flavor')
+ make_flavor(root)
+ return xmlutil.SlaveTemplate(root, 1)
+
+
+class FlavorsSwapTemplate(xmlutil.TemplateBuilder):
+ def construct(self):
+ root = xmlutil.TemplateElement('flavors')
+ elem = xmlutil.SubTemplateElement(root, 'flavor', selector='flavors')
+ make_flavor(elem)
+ return xmlutil.SlaveTemplate(root, 1)
diff --git a/nova/api/openstack/compute/flavors.py b/nova/api/openstack/compute/flavors.py
index e04ade437..8aa57a2b1 100644
--- a/nova/api/openstack/compute/flavors.py
+++ b/nova/api/openstack/compute/flavors.py
@@ -31,9 +31,7 @@ def make_flavor(elem, detailed=False):
if detailed:
elem.set('ram')
elem.set('disk')
-
- for attr in ("vcpus", "swap", "rxtx_factor"):
- elem.set(attr, xmlutil.EmptyStringSelector(attr))
+ elem.set('vcpus', xmlutil.EmptyStringSelector('vcpus'))
xmlutil.make_links(elem, 'links')
diff --git a/nova/api/openstack/compute/schemas/v1.1/flavor.rng b/nova/api/openstack/compute/schemas/v1.1/flavor.rng
index 08746ce3d..a97a3a972 100644
--- a/nova/api/openstack/compute/schemas/v1.1/flavor.rng
+++ b/nova/api/openstack/compute/schemas/v1.1/flavor.rng
@@ -4,8 +4,6 @@
<attribute name="id"> <text/> </attribute>
<attribute name="ram"> <text/> </attribute>
<attribute name="disk"> <text/> </attribute>
- <attribute name="rxtx_factor"> <text/> </attribute>
- <attribute name="swap"> <text/> </attribute>
<attribute name="vcpus"> <text/> </attribute>
<zeroOrMore>
<externalRef href="../atom-link.rng"/>
diff --git a/nova/api/openstack/compute/views/flavors.py b/nova/api/openstack/compute/views/flavors.py
index 2900ccf64..fbbe5c45e 100644
--- a/nova/api/openstack/compute/views/flavors.py
+++ b/nova/api/openstack/compute/views/flavors.py
@@ -41,8 +41,6 @@ class ViewBuilder(common.ViewBuilder):
"ram": flavor["memory_mb"],
"disk": flavor["root_gb"],
"vcpus": flavor.get("vcpus") or "",
- "swap": flavor.get("swap") or "",
- "rxtx_factor": flavor.get("rxtx_factor") or "",
"links": self._get_links(request,
flavor["flavorid"],
self._collection_name),