From 43cb25545b2e983e45c6c2b524758e5b89b74a03 Mon Sep 17 00:00:00 2001 From: Boden R Date: Thu, 4 May 2017 06:30:18 -0600 Subject: [PATCH] use constants rather than static strings A number of the existing API defs use static strings rather than using existing constants. This patch replaces those static strings with their respective constants where applicable. Change-Id: I505f10b58a454bd7c90725abbc62cc8a7fd46d94 --- .../api/definitions/data_plane_status.py | 5 +++-- neutron_lib/api/definitions/extra_dhcp_opt.py | 5 +++-- neutron_lib/api/definitions/firewall_v2.py | 19 +++++++++++-------- .../definitions/firewallrouterinsertion.py | 3 ++- neutron_lib/api/definitions/network.py | 7 ++++--- neutron_lib/api/definitions/port_security.py | 6 ++++-- neutron_lib/api/definitions/portbindings.py | 5 +++-- neutron_lib/api/definitions/provider_net.py | 5 +++-- neutron_lib/api/definitions/trunk_details.py | 5 +++-- 9 files changed, 36 insertions(+), 24 deletions(-) diff --git a/neutron_lib/api/definitions/data_plane_status.py b/neutron_lib/api/definitions/data_plane_status.py index f102e10..2c6a1ba 100644 --- a/neutron_lib/api/definitions/data_plane_status.py +++ b/neutron_lib/api/definitions/data_plane_status.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.api.definitions import port from neutron_lib import constants @@ -42,10 +43,10 @@ DESCRIPTION = "Expose status of underlying data plane" UPDATED_TIMESTAMP = "2017-01-24T10:00:00-00:00" # The name of the resource introduced or being extended. -RESOURCE_NAME = 'port' +RESOURCE_NAME = port.RESOURCE_NAME # The plural for the resource introduced or being extended. -COLLECTION_NAME = 'ports' +COLLECTION_NAME = port.COLLECTION_NAME # The specific resources and/or attributes for the extension (optional). DATA_PLANE_STATUS = 'data_plane_status' diff --git a/neutron_lib/api/definitions/extra_dhcp_opt.py b/neutron_lib/api/definitions/extra_dhcp_opt.py index 95d2e49..c98b866 100644 --- a/neutron_lib/api/definitions/extra_dhcp_opt.py +++ b/neutron_lib/api/definitions/extra_dhcp_opt.py @@ -13,6 +13,7 @@ # under the License. from neutron_lib.api import converters +from neutron_lib.api.definitions import port # Common definitions for maximum string field length @@ -89,12 +90,12 @@ UPDATED_TIMESTAMP = "2013-03-17T12:00:00-00:00" # The name of the resource introduced or being extended # (in case it is defined by another extension, or it is # a core resource). -RESOURCE_NAME = 'port' +RESOURCE_NAME = port.RESOURCE_NAME # The plural for the resource introduced or being extended # (in case it is defined by another extension, or it is a # core resource). -COLLECTION_NAME = 'ports' +COLLECTION_NAME = port.COLLECTION_NAME # The resource attribute map for the extension. It is effectively the # bulk of the API contract alongside ACTION_MAP (mandatory). diff --git a/neutron_lib/api/definitions/firewall_v2.py b/neutron_lib/api/definitions/firewall_v2.py index 60ed405..bdb1e3d 100644 --- a/neutron_lib/api/definitions/firewall_v2.py +++ b/neutron_lib/api/definitions/firewall_v2.py @@ -12,6 +12,7 @@ from neutron_lib.api import converters from neutron_lib.api.definitions import constants as api_const +from neutron_lib.api.definitions import port from neutron_lib.db import constants as db_const # The alias of the extension. @@ -119,10 +120,11 @@ RESOURCE_ATTRIBUTE_MAP = { 'convert_to': converters.convert_to_boolean, 'is_visible': True, 'required_by_policy': True, 'enforce_policy': True}, - 'ports': {'allow_post': True, 'allow_put': True, - 'validate': {'type:uuid_list': None}, - 'convert_to': converters.convert_none_to_empty_list, - 'default': None, 'is_visible': True}, + port.COLLECTION_NAME: {'allow_post': True, 'allow_put': True, + 'validate': {'type:uuid_list': None}, + 'convert_to': + converters.convert_none_to_empty_list, + 'default': None, 'is_visible': True}, 'tenant_id': {'allow_post': True, 'allow_put': False, 'required_by_policy': True, 'validate': {'type:string': @@ -160,10 +162,11 @@ RESOURCE_ATTRIBUTE_MAP = { 'convert_to': converters.convert_to_boolean, 'is_visible': True, 'required_by_policy': True, 'enforce_policy': True}, - 'firewall_rules': {'allow_post': True, 'allow_put': True, - 'validate': {'type:uuid_list': None}, - 'convert_to': converters.convert_none_to_empty_list, - 'default': None, 'is_visible': True}, + api_const.FIREWALL_RULES: {'allow_post': True, 'allow_put': True, + 'validate': {'type:uuid_list': None}, + 'convert_to': + converters.convert_none_to_empty_list, + 'default': None, 'is_visible': True}, 'audited': {'allow_post': True, 'allow_put': True, 'default': False, 'convert_to': converters.convert_to_boolean, 'is_visible': True}, diff --git a/neutron_lib/api/definitions/firewallrouterinsertion.py b/neutron_lib/api/definitions/firewallrouterinsertion.py index d4264f6..2b1e9f4 100644 --- a/neutron_lib/api/definitions/firewallrouterinsertion.py +++ b/neutron_lib/api/definitions/firewallrouterinsertion.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.api.definitions import constants as api_const from neutron_lib import constants # The alias of the extension. @@ -40,7 +41,7 @@ UPDATED_TIMESTAMP = "2016-01-01T10:00:00-00:00" RESOURCE_NAME = "firewall" # The plural for the resource -COLLECTION_NAME = "firewalls" +COLLECTION_NAME = api_const.FIREWALLS RESOURCE_ATTRIBUTE_MAP = { COLLECTION_NAME: { diff --git a/neutron_lib/api/definitions/network.py b/neutron_lib/api/definitions/network.py index 9d55f53..1f2949a 100644 --- a/neutron_lib/api/definitions/network.py +++ b/neutron_lib/api/definitions/network.py @@ -11,6 +11,7 @@ # under the License. from neutron_lib.api import converters +from neutron_lib.api.definitions import subnet from neutron_lib.db import constants as db_const @@ -39,9 +40,9 @@ RESOURCE_ATTRIBUTE_MAP = { 'validate': { 'type:string': db_const.NAME_FIELD_SIZE}, 'default': '', 'is_visible': True}, - 'subnets': {'allow_post': False, 'allow_put': False, - 'default': [], - 'is_visible': True}, + subnet.COLLECTION_NAME: {'allow_post': False, 'allow_put': False, + 'default': [], + 'is_visible': True}, 'admin_state_up': {'allow_post': True, 'allow_put': True, 'default': True, 'convert_to': converters.convert_to_boolean, diff --git a/neutron_lib/api/definitions/port_security.py b/neutron_lib/api/definitions/port_security.py index c077f6e..b58495b 100644 --- a/neutron_lib/api/definitions/port_security.py +++ b/neutron_lib/api/definitions/port_security.py @@ -13,6 +13,8 @@ # under the License. from neutron_lib.api import converters +from neutron_lib.api.definitions import network +from neutron_lib.api.definitions import port from neutron_lib import constants @@ -54,14 +56,14 @@ UPDATED_TIMESTAMP = "2012-07-23T10:00:00-00:00" RESOURCE_ATTRIBUTE_MAP = { - 'networks': { + network.COLLECTION_NAME: { PORTSECURITY: {'allow_post': True, 'allow_put': True, 'convert_to': converters.convert_to_boolean, 'enforce_policy': True, 'default': DEFAULT_PORT_SECURITY, 'is_visible': True}, }, - 'ports': { + port.COLLECTION_NAME: { PORTSECURITY: {'allow_post': True, 'allow_put': True, 'convert_to': converters.convert_to_boolean, 'default': constants.ATTR_NOT_SPECIFIED, diff --git a/neutron_lib/api/definitions/portbindings.py b/neutron_lib/api/definitions/portbindings.py index af39c47..98f3b9e 100644 --- a/neutron_lib/api/definitions/portbindings.py +++ b/neutron_lib/api/definitions/portbindings.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.api.definitions import port from neutron_lib import constants @@ -137,10 +138,10 @@ DESCRIPTION = "Expose port bindings of a virtual port to external application" UPDATED_TIMESTAMP = "2014-02-03T10:00:00-00:00" # The name of the resource. -RESOURCE_NAME = 'port' +RESOURCE_NAME = port.RESOURCE_NAME # The plural for the resource. -COLLECTION_NAME = 'ports' +COLLECTION_NAME = port.COLLECTION_NAME RESOURCE_ATTRIBUTE_MAP = { COLLECTION_NAME: { diff --git a/neutron_lib/api/definitions/provider_net.py b/neutron_lib/api/definitions/provider_net.py index 8ff8437..80112c4 100644 --- a/neutron_lib/api/definitions/provider_net.py +++ b/neutron_lib/api/definitions/provider_net.py @@ -13,6 +13,7 @@ # under the License. from neutron_lib.api import converters +from neutron_lib.api.definitions import network from neutron_lib import constants # The alias of the extension. @@ -44,10 +45,10 @@ DESCRIPTION = "Expose mapping of virtual networks to physical networks" UPDATED_TIMESTAMP = "2012-09-07T10:00:00-00:00" # The name of the resource. -RESOURCE_NAME = 'network' +RESOURCE_NAME = network.RESOURCE_NAME # The plural for the resource. -COLLECTION_NAME = 'networks' +COLLECTION_NAME = network.COLLECTION_NAME NETWORK_TYPE = 'provider:network_type' PHYSICAL_NETWORK = 'provider:physical_network' diff --git a/neutron_lib/api/definitions/trunk_details.py b/neutron_lib/api/definitions/trunk_details.py index f77559d..e3c9af2 100644 --- a/neutron_lib/api/definitions/trunk_details.py +++ b/neutron_lib/api/definitions/trunk_details.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.api.definitions import port from neutron_lib.api.definitions import trunk from neutron_lib import constants @@ -41,10 +42,10 @@ DESCRIPTION = "Expose trunk port details" TIMESTAMP = "2016-01-01T10:00:00-00:00" # The name of the resource introduced or being extended. -RESOURCE_NAME = 'port' +RESOURCE_NAME = port.RESOURCE_NAME # The plural for the resource introduced or being extended. -COLLECTION_NAME = 'ports' +COLLECTION_NAME = port.COLLECTION_NAME # The specific resources and/or attributes for the extension (optional). TRUNK_DETAILS = 'trunk_details'