Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up non-spec output in flavor extensions
Adds option to cache flavors in the request object like instances. Modifies the flavorextradata extension to use the cache and optimizes tests. Adds flavor_disabled extension to control the extra data and includes tests. Fixes api samples to show the new extension. Fixes bug 1043585 Change-Id: Ie89df24a2891e3869d3fb604e07c79e8c913f290
- Loading branch information
1 parent
4a6193b
commit f9fa7a6
Showing
17 changed files
with
294 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# 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 Disabled 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_disabled') | ||
|
||
|
||
class FlavorDisabledController(wsgi.Controller): | ||
def _extend_flavors(self, req, flavors): | ||
for flavor in flavors: | ||
db_flavor = req.get_db_flavor(flavor['id']) | ||
key = "%s:disabled" % Flavor_disabled.alias | ||
flavor[key] = db_flavor['disabled'] | ||
|
||
def _show(self, req, resp_obj): | ||
if not authorize(req.environ['nova.context']): | ||
return | ||
if 'flavor' in resp_obj.obj: | ||
resp_obj.attach(xml=FlavorDisabledTemplate()) | ||
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=FlavorsDisabledTemplate()) | ||
self._extend_flavors(req, list(resp_obj.obj['flavors'])) | ||
|
||
|
||
class Flavor_disabled(extensions.ExtensionDescriptor): | ||
"""Support to show the disabled status of a flavor""" | ||
|
||
name = "FlavorDisabled" | ||
alias = "OS-FLV-DISABLED" | ||
namespace = ("http://docs.openstack.org/compute/ext/" | ||
"flavor_disabled/api/v1.1") | ||
updated = "2012-08-29T00:00:00+00:00" | ||
|
||
def get_controller_extensions(self): | ||
controller = FlavorDisabledController() | ||
extension = extensions.ControllerExtension(self, 'flavors', controller) | ||
return [extension] | ||
|
||
|
||
def make_flavor(elem): | ||
elem.set('{%s}disabled' % Flavor_disabled.namespace, | ||
'%s:disabled' % Flavor_disabled.alias) | ||
|
||
|
||
class FlavorDisabledTemplate(xmlutil.TemplateBuilder): | ||
def construct(self): | ||
root = xmlutil.TemplateElement('flavor', selector='flavor') | ||
make_flavor(root) | ||
return xmlutil.SlaveTemplate(root, 1, nsmap={ | ||
Flavor_disabled.alias: Flavor_disabled.namespace}) | ||
|
||
|
||
class FlavorsDisabledTemplate(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={ | ||
Flavor_disabled.alias: Flavor_disabled.namespace}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.