Merge "Adds API parameters to quantum.api.extension.ResourceExtension"

This commit is contained in:
Jenkins 2013-02-11 17:33:31 +00:00 committed by Gerrit Code Review
commit bfd66653c9
7 changed files with 41 additions and 8 deletions

View File

@ -590,13 +590,14 @@ class ResourceExtension(object):
"""Add top level resources to the OpenStack API in Quantum.""" """Add top level resources to the OpenStack API in Quantum."""
def __init__(self, collection, controller, parent=None, path_prefix="", def __init__(self, collection, controller, parent=None, path_prefix="",
collection_actions={}, member_actions={}): collection_actions={}, member_actions={}, attr_map={}):
self.collection = collection self.collection = collection
self.controller = controller self.controller = controller
self.parent = parent self.parent = parent
self.collection_actions = collection_actions self.collection_actions = collection_actions
self.member_actions = member_actions self.member_actions = member_actions
self.path_prefix = path_prefix self.path_prefix = path_prefix
self.attr_map = attr_map
# Returns the extention paths from a config entry and the __path__ # Returns the extention paths from a config entry and the __path__

View File

@ -207,7 +207,8 @@ class L3(extensions.ExtensionDescriptor):
ex = extensions.ResourceExtension(collection_name, ex = extensions.ResourceExtension(collection_name,
controller, controller,
member_actions=member_actions) member_actions=member_actions,
attr_map=params)
exts.append(ex) exts.append(ex)
return exts return exts

View File

@ -281,7 +281,8 @@ class Loadbalancer(extensions.ExtensionDescriptor):
collection_name, collection_name,
controller, controller,
path_prefix=constants.COMMON_PREFIXES[constants.LOADBALANCER], path_prefix=constants.COMMON_PREFIXES[constants.LOADBALANCER],
member_actions=member_actions) member_actions=member_actions,
attr_map=params)
resources.append(resource) resources.append(resource)
for collection_name in SUB_RESOURCE_ATTRIBUTE_MAP: for collection_name in SUB_RESOURCE_ATTRIBUTE_MAP:
@ -300,7 +301,8 @@ class Loadbalancer(extensions.ExtensionDescriptor):
resource = extensions.ResourceExtension( resource = extensions.ResourceExtension(
collection_name, collection_name,
controller, parent, controller, parent,
path_prefix=constants.COMMON_PREFIXES[constants.LOADBALANCER]) path_prefix=constants.COMMON_PREFIXES[constants.LOADBALANCER],
attr_map=params)
resources.append(resource) resources.append(resource)
return resources return resources

View File

@ -302,7 +302,8 @@ class Securitygroup(extensions.ExtensionDescriptor):
plugin, params, allow_bulk=True) plugin, params, allow_bulk=True)
ex = extensions.ResourceExtension(collection_name, ex = extensions.ResourceExtension(collection_name,
controller) controller,
attr_map=params)
exts.append(ex) exts.append(ex)
return exts return exts

View File

@ -188,9 +188,12 @@ class Servicetype(extensions.ExtensionDescriptor):
key in RESOURCE_ATTRIBUTE_MAP.keys()] key in RESOURCE_ATTRIBUTE_MAP.keys()]
my_plurals.append(('service_definitions', 'service_definition')) my_plurals.append(('service_definitions', 'service_definition'))
attributes.PLURALS.update(dict(my_plurals)) attributes.PLURALS.update(dict(my_plurals))
attr_map = RESOURCE_ATTRIBUTE_MAP[COLLECTION_NAME]
controller = base.create_resource( controller = base.create_resource(
COLLECTION_NAME, COLLECTION_NAME,
RESOURCE_NAME, RESOURCE_NAME,
servicetype_db.ServiceTypeManager.get_instance(), servicetype_db.ServiceTypeManager.get_instance(),
RESOURCE_ATTRIBUTE_MAP[COLLECTION_NAME]) attr_map)
return [extensions.ResourceExtension(COLLECTION_NAME, controller)] return [extensions.ResourceExtension(COLLECTION_NAME,
controller,
attr_map=attr_map)]

View File

@ -127,4 +127,6 @@ class Packetfilter(extensions.ExtensionDescriptor):
quota._count_resource, quota._count_resource,
'quota_packet_filter') 'quota_packet_filter')
quota.QUOTAS.register_resource(qresource) quota.QUOTAS.register_resource(qresource)
return [extensions.ResourceExtension('packet_filters', resource)] return [extensions.ResourceExtension('packet_filters',
resource,
attr_map=PACKET_FILTER_ATTR_MAP)]

View File

@ -277,6 +277,29 @@ class ResourceExtensionTest(unittest.TestCase):
self.assertEqual(200, response.status_int) self.assertEqual(200, response.status_int)
self.assertEqual(jsonutils.loads(response.body)['collection'], "value") self.assertEqual(jsonutils.loads(response.body)['collection'], "value")
def test_resource_extension_with_custom_member_action_and_attr_map(self):
controller = self.ResourceExtensionController()
member = {'custom_member_action': "GET"}
params = {
'tweedles': {
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True},
'name': {'allow_post': True, 'allow_put': True,
'validate': {'type:string': None},
'default': '', 'is_visible': True},
}
}
res_ext = extensions.ResourceExtension('tweedles', controller,
member_actions=member,
attr_map=params)
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
response = test_app.get("/tweedles/some_id/custom_member_action")
self.assertEqual(200, response.status_int)
self.assertEqual(jsonutils.loads(response.body)['member_action'],
"value")
def test_returns_404_for_non_existent_extension(self): def test_returns_404_for_non_existent_extension(self):
test_app = _setup_extensions_test_app(SimpleExtensionManager(None)) test_app = _setup_extensions_test_app(SimpleExtensionManager(None))