From ed6aeed0fd7fb0d66a58795dca4c618fed81381c Mon Sep 17 00:00:00 2001 From: Armando Migliaccio Date: Tue, 9 Aug 2016 15:10:14 -0700 Subject: [PATCH] Migrate to neutron-lib released API definition for trunk APIs This patch shows how to use a neutron-lib released API definition for the trunk/trunk-details extensions. This is a baby step towards a consolidated set of Neutron APIs. Change-Id: Iba73f079c48c3efe89db49d1ac32c8105db100e9 --- neutron/extensions/trunk.py | 68 ++++++++--------------------- neutron/extensions/trunk_details.py | 24 +++++----- 2 files changed, 28 insertions(+), 64 deletions(-) diff --git a/neutron/extensions/trunk.py b/neutron/extensions/trunk.py index 3624e7b51eb..5a92ec4774c 100644 --- a/neutron/extensions/trunk.py +++ b/neutron/extensions/trunk.py @@ -13,89 +13,57 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron_lib.api import converters +from neutron_lib.api.definitions import trunk from neutron.api import extensions from neutron.api.v2 import attributes as attr from neutron.api.v2 import resource_helper -RESOURCE_ATTRIBUTE_MAP = { - 'trunks': { - 'admin_state_up': {'allow_post': True, 'allow_put': True, - 'default': True, - 'convert_to': converters.convert_to_boolean, - 'is_visible': True}, - 'id': {'allow_post': False, 'allow_put': False, - 'validate': {'type:uuid': None}, - 'is_visible': True, 'primary_key': True}, - 'name': {'allow_post': True, 'allow_put': True, - 'validate': {'type:string': attr.NAME_MAX_LEN}, - 'default': '', 'is_visible': True}, - 'tenant_id': {'allow_post': True, 'allow_put': False, - 'required_by_policy': True, - 'validate': - {'type:string': attr.TENANT_ID_MAX_LEN}, - 'is_visible': True}, - 'port_id': {'allow_post': True, 'allow_put': False, - 'required_by_policy': True, - 'validate': {'type:uuid': None}, - 'is_visible': True}, - 'status': {'allow_post': False, 'allow_put': False, - 'is_visible': True}, - 'sub_ports': {'allow_post': True, 'allow_put': False, - 'default': [], - 'convert_list_to': converters.convert_kvp_list_to_dict, - 'validate': {'type:subports': None}, - 'enforce_policy': True, - 'is_visible': True}, - }, -} - - class Trunk(extensions.ExtensionDescriptor): """Trunk API extension.""" @classmethod def get_name(cls): - return "Trunk Extension" + return trunk.NAME @classmethod def get_alias(cls): - return "trunk" + return trunk.ALIAS @classmethod def get_description(cls): - return "Provides support for trunk ports" + return trunk.DESCRIPTION @classmethod def get_updated(cls): - return "2016-01-01T10:00:00-00:00" + return trunk.UPDATED_TIMESTAMP @classmethod def get_resources(cls): """Returns Ext Resources.""" plural_mappings = resource_helper.build_plural_mappings( - {}, RESOURCE_ATTRIBUTE_MAP) + {}, trunk.RESOURCE_ATTRIBUTE_MAP) attr.PLURALS.update(plural_mappings) - action_map = {'trunk': {'add_subports': 'PUT', - 'remove_subports': 'PUT', - 'get_subports': 'GET'}} - return resource_helper.build_resource_info(plural_mappings, - RESOURCE_ATTRIBUTE_MAP, - 'trunk', - action_map=action_map, - register_quota=True) + return resource_helper.build_resource_info( + plural_mappings, + trunk.RESOURCE_ATTRIBUTE_MAP, + trunk.ALIAS, + action_map=trunk.ACTION_MAP, + register_quota=True) def update_attributes_map(self, attributes, extension_attrs_map=None): super(Trunk, self).update_attributes_map( - attributes, extension_attrs_map=RESOURCE_ATTRIBUTE_MAP) + attributes, extension_attrs_map=trunk.RESOURCE_ATTRIBUTE_MAP) def get_required_extensions(self): - return ["binding"] + return trunk.REQUIRED_EXTENSIONS or [] + + def get_optional_extensions(self): + return trunk.OPTIONAL_EXTENSIONS or [] def get_extended_resources(self, version): if version == "2.0": - return RESOURCE_ATTRIBUTE_MAP + return trunk.RESOURCE_ATTRIBUTE_MAP else: return {} diff --git a/neutron/extensions/trunk_details.py b/neutron/extensions/trunk_details.py index 8071a80e3c1..9a9459ae7e9 100644 --- a/neutron/extensions/trunk_details.py +++ b/neutron/extensions/trunk_details.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron_lib import constants +from neutron_lib.api.definitions import trunk_details from neutron.api import extensions @@ -22,38 +22,34 @@ from neutron.api import extensions # are parent in a trunk so that consumers of the Neutron API, like Nova # can efficiently access trunk information for things like metadata or # config-drive configuration. -EXTENDED_ATTRIBUTES_2_0 = { - 'ports': {'trunk_details': {'allow_post': False, 'allow_put': False, - 'default': constants.ATTR_NOT_SPECIFIED, - 'is_visible': True, - 'enforce_policy': True, - 'required_by_policy': True}}, -} class Trunk_details(extensions.ExtensionDescriptor): @classmethod def get_name(cls): - return "Trunk port details" + return trunk_details.NAME @classmethod def get_alias(cls): - return "trunk-details" + return trunk_details.ALIAS @classmethod def get_description(cls): - return "Expose trunk port details" + return trunk_details.DESCRIPTION @classmethod def get_updated(cls): - return "2016-01-01T10:00:00-00:00" + return trunk_details.TIMESTAMP def get_required_extensions(self): - return ["trunk"] + return trunk_details.REQUIRED_EXTENSIONS or [] + + def get_optional_extensions(self): + return trunk_details.OPTIONAL_EXTENSIONS or [] def get_extended_resources(self, version): if version == "2.0": - return EXTENDED_ATTRIBUTES_2_0 + return trunk_details.RESOURCE_ATTRIBUTE_MAP else: return {}