diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-01-24 20:52:57 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-01-24 20:52:57 +0000 |
| commit | ef50dd412b3e0ab569c85abc1b3637ff0f3f819d (patch) | |
| tree | 44c8ce804c5f16a8f21feb0efbe6a63b21bc1eed /nova/api | |
| parent | 8dfd968e83cbcdc0796caa44289144d38a6a5ce8 (diff) | |
| parent | 35b3c08a463dd35a41f3c44f3fa8273b915cb378 (diff) | |
| download | nova-ef50dd412b3e0ab569c85abc1b3637ff0f3f819d.tar.gz nova-ef50dd412b3e0ab569c85abc1b3637ff0f3f819d.tar.xz nova-ef50dd412b3e0ab569c85abc1b3637ff0f3f819d.zip | |
Merge "Add an API extension for creating+deleting flavors"
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/flavormanage.py | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/contrib/flavormanage.py b/nova/api/openstack/compute/contrib/flavormanage.py new file mode 100644 index 000000000..604f40766 --- /dev/null +++ b/nova/api/openstack/compute/contrib/flavormanage.py @@ -0,0 +1,95 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# 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 + +import urlparse + +import webob + +from nova.api.openstack import extensions +from nova.api.openstack import wsgi +from nova.api.openstack.compute import flavors as flavors_api +from nova.api.openstack.compute.views import flavors as flavors_view +from nova.compute import instance_types +from nova import log as logging +from nova import exception + + +LOG = logging.getLogger('nova.api.openstack.compute.contrib.flavormanage') + + +class FlavorManageController(wsgi.Controller): + """ + The Flavor Lifecycle API controller for the OpenStack API. + """ + _view_builder_class = flavors_view.ViewBuilder + + def __init__(self): + super(FlavorManageController, self).__init__() + + @wsgi.action("delete") + def _delete(self, req, id): + context = req.environ['nova.context'] + + if not context.is_admin: + return webob.Response(status_int=403) + + try: + flavor = instance_types.get_instance_type_by_flavor_id(id) + except exception.NotFound, e: + raise webob.exc.HTTPNotFound(explanation=str(e)) + + instance_types.destroy(flavor['name']) + + return webob.Response(status_int=202) + + @wsgi.action("create") + @wsgi.serializers(xml=flavors_api.FlavorTemplate) + def _create(self, req, body): + context = req.environ['nova.context'] + + if not context.is_admin: + return webob.Response(status_int=403) + + vals = body['flavor'] + name = vals['name'] + flavorid = vals['id'] + memory_mb = vals.get('ram') + vcpus = vals.get('vcpus') + root_gb = vals.get('disk') + ephemeral_gb = vals.get('disk') + swap = vals.get('swap') + rxtx_factor = vals.get('rxtx_factor') + + flavor = instance_types.create(name, memory_mb, vcpus, + root_gb, ephemeral_gb, flavorid, + swap, rxtx_factor) + + return self._view_builder.show(req, flavor) + + +class Flavormanage(extensions.ExtensionDescriptor): + """ + Flavor create/delete API support + """ + + name = "FlavorManage" + alias = "os-flavor-manage" + namespace = ("http://docs.openstack.org/compute/ext/" + "flavor_manage/api/v1.1") + updated = "2012-01-19T00:00:00+00:00" + + def get_controller_extensions(self): + controller = FlavorManageController() + extension = extensions.ControllerExtension(self, 'flavors', controller) + return [extension] |
