-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 OpenStack Foundation.
from neutron import wsgi
-LOG = logging.getLogger('neutron.api.extensions')
+LOG = logging.getLogger(__name__)
class PluginInterface(object):
Note that you don't have to derive from this class to have a valid
extension; it is purely a convenience.
-
"""
def get_name(self):
"""The name of the extension.
e.g. 'Fox In Socks'
-
"""
raise NotImplementedError()
"""The alias for the extension.
e.g. 'FOXNSOX'
-
"""
raise NotImplementedError()
"""Friendly description for the extension.
e.g. 'The Fox In Socks Extension'
-
"""
raise NotImplementedError()
"""The XML namespace for the extension.
e.g. 'http://www.fox.in.socks/api/ext/pie/v1.0'
-
"""
raise NotImplementedError()
"""The timestamp when the extension was last updated.
e.g. '2011-01-22T13:25:27-06:00'
-
"""
# NOTE(justinsb): Not sure of the purpose of this is, vs the XML NS
raise NotImplementedError()
"""List of extensions.ResourceExtension extension objects.
Resources define new nouns, and are accessible through URLs.
-
"""
resources = []
return resources
"""List of extensions.ActionExtension extension objects.
Actions are verbs callable from the API.
-
"""
actions = []
return actions
"""List of extensions.RequestException extension objects.
Request extensions are used to handle custom request data.
-
"""
request_exts = []
return request_exts
class ActionExtensionController(wsgi.Controller):
def __init__(self, application):
-
self.application = application
self.action_handlers = {}
self.action_handlers[action_name] = handler
def action(self, request, id):
-
input_dict = self._deserialize(request.body,
request.get_content_type())
for action_name, handler in self.action_handlers.iteritems():
class ExtensionMiddleware(wsgi.Middleware):
"""Extensions middleware for WSGI."""
+
def __init__(self, application,
ext_mgr=None):
-
self.ext_mgr = (ext_mgr
or ExtensionManager(
get_extensions_path()))
Returns the routed WSGI app's response or defers to the extended
application.
-
"""
match = req.environ['wsgiorg.routing_args'][1]
if not match:
See tests/unit/extensions/foxinsocks.py for an
example extension implementation.
-
"""
+
def __init__(self, path):
LOG.info(_('Initializing extension manager.'))
self.path = path
# Exit loop as no progress was made
break
if exts_to_process:
- # NOTE(salv-orlando): Consider wheter this error should be fatal
+ # NOTE(salv-orlando): Consider whether this error should be fatal
LOG.error(_("It was impossible to process the following "
"extensions: %s because of missing requirements."),
','.join(exts_to_process.keys()))
- """Extending extensions' attributes map."""
+ # Extending extensions' attributes map.
for ext in update_exts:
ext.update_attributes_map(attr_map)
def _load_all_extensions(self):
"""Load extensions from the configured path.
- Load extensions from the configured path. The extension name is
- constructed from the module_name. If your extension module was named
- widgets.py the extension class within that module should be
- 'Widgets'.
-
- See tests/unit/extensions/foxinsocks.py for an example
- extension implementation.
+ The extension name is constructed from the module_name. If your
+ extension module is named widgets.py, the extension class within that
+ module should be 'Widgets'.
+ See tests/unit/extensions/foxinsocks.py for an example extension
+ implementation.
"""
for path in self.path.split(':'):
if os.path.exists(path):
super(PluginAwareExtensionManager, self).__init__(path)
def _check_extension(self, extension):
- """Checks if any of plugins supports extension and implements the
- extension contract.
- """
+ """Check if an extension is supported by any plugin."""
extension_is_valid = super(PluginAwareExtensionManager,
self)._check_extension(extension)
return (extension_is_valid and
Provide a way to add data to responses and handle custom request data
that is sent to core Neutron OpenStack API controllers.
-
"""
+
def __init__(self, method, url_route, handler):
self.url_route = url_route
self.handler = handler