# The following is a short reference for understanding attribute info:
# default: default value of the attribute (if missing, the attribute
# becomes mandatory.
# allow_post: the attribute can be used on POST requests.
# allow_put: the attribute can be used on PUT requests.
# validate: specifies rules for validating data in the attribute.
# convert_to: transformation to apply to the value before it is returned
# is_visible: the attribute is returned in GET responses.
# required_by_policy: the attribute is required by the policy engine and
# should therefore be filled by the API layer even if not present in
# request body.
# enforce_policy: the attribute is actively part of the policy enforcing
# mechanism, ie: there might be rules which refer to this attribute.
from neutron.api import extensions
from neutron import manager from neutron.api.v2 import base
class Myextension(extensions.ExtensionDescriptor):
# The name of this class should be the same as the file name
# The first letter must be changed from lower case to upper case
# There are a couple of methods and their properties defined in the
# parent class of this class, ExtensionDescriptor you can check them
@classmethod
def get_name(cls):
# You can coin a name for this extension
return "My Extension"
@classmethod
def get_alias(cls):
# This alias will be used by your core_plugin class to load
# the extension
return "my-extensions"
@classmethod
def get_description(cls):
# A small description about this extension
return "An extension defined by myself. Haha!"
@classmethod
def get_namespace(cls):
# The XML namespace for this extension
return "http://docs.openstack.org/ext/myextension/api/v1.0"
@classmethod
def get_updated(cls):
# Specify when was this extension last updated,
# good for management when there are changes in the design
return "2014-08-07T00:00:00-00:00"
@classmethod
def get_resources(cls):
# This method registers the URL and the dictionary of
# attributes on the neutron-server.
exts = []
plugin = manager.NeutronManager.get_plugin()
resource_name = 'myextension'
collection_name = '%ss' % resource_name
params = RESOURCE_ATTRIBUTE_MAP.get(collection_name, dict())
controller = base.create_resource(collection_name, resource_name,
plugin, params, allow_bulk=False)
ex = extensions.ResourceExtension(collection_name, controller)
exts.append(ex)
return exts