use api def ALIAS in supported_extension_aliases

Today a number of classes define their supported_extension_aliases
using static strings rather than API definition ALIASes. This patch
switches them to use the ALIAS where applicable.

Change-Id: Ic82a971a41993e4a555132b6363b2cc96e64ba2a
This commit is contained in:
Boden R 2019-02-19 11:33:34 -07:00
parent 214d7e831e
commit 0f20c9594f
7 changed files with 128 additions and 96 deletions

View File

@ -18,6 +18,8 @@
import weakref import weakref
from neutron_lib.agent import topics from neutron_lib.agent import topics
from neutron_lib.api.definitions import agent as agent_apidef
from neutron_lib.api.definitions import dhcpagentscheduler
from neutron_lib import constants as const from neutron_lib import constants as const
from neutron_lib import rpc as n_rpc from neutron_lib import rpc as n_rpc
from oslo_concurrency import lockutils from oslo_concurrency import lockutils
@ -101,7 +103,7 @@ class DhcpMetadataAccess(object):
cfg.CONF.network_scheduler_driver cfg.CONF.network_scheduler_driver
) )
self.supported_extension_aliases.extend( self.supported_extension_aliases.extend(
['agent', 'dhcp_agent_scheduler']) [agent_apidef.ALIAS, dhcpagentscheduler.ALIAS])
def _setup_nsx_dhcp_metadata(self): def _setup_nsx_dhcp_metadata(self):
self._check_services_requirements() self._check_services_requirements()
@ -134,7 +136,8 @@ class DhcpMetadataAccess(object):
return notifier return notifier
def _init_extensions(self): def _init_extensions(self):
extensions = (lsn.EXT_ALIAS, 'agent', 'dhcp_agent_scheduler') extensions = (lsn.EXT_ALIAS, agent_apidef.ALIAS,
dhcpagentscheduler.ALIAS)
for ext in extensions: for ext in extensions:
if ext in self.supported_extension_aliases: if ext in self.supported_extension_aliases:
self.supported_extension_aliases.remove(ext) self.supported_extension_aliases.remove(ext)

View File

@ -14,10 +14,22 @@
# under the License. # under the License.
from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef
from neutron_lib.api.definitions import external_net as enet_apidef
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef
from neutron_lib.api.definitions import port_security as psec from neutron_lib.api.definitions import port_security as psec
from neutron_lib.api.definitions import portbindings as pbin
from neutron_lib.api.definitions import provider_net as pnet
from neutron_lib.api.definitions import vlantransparent as vlan_apidef
from neutron_lib.api import validators
from neutron_lib import constants
from neutron_lib.db import api as db_api
from neutron_lib.db import resource_extend
from neutron_lib.db import utils as db_utils from neutron_lib.db import utils as db_utils
from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import allowedaddresspairs as addr_exc from neutron_lib.exceptions import allowedaddresspairs as addr_exc
from neutron_lib.exceptions import port_security as psec_exc from neutron_lib.exceptions import port_security as psec_exc
from neutron_lib.plugins import utils
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
@ -38,16 +50,7 @@ from neutron.db import vlantransparent_db as vlan_ext_db
from neutron.extensions import providernet from neutron.extensions import providernet
from neutron.extensions import securitygroup as ext_sg from neutron.extensions import securitygroup as ext_sg
from neutron.quota import resource_registry from neutron.quota import resource_registry
from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef
from neutron_lib.api.definitions import portbindings as pbin
from neutron_lib.api.definitions import provider_net as pnet
from neutron_lib.api.definitions import vlantransparent as vlan_apidef
from neutron_lib.api import validators
from neutron_lib import constants
from neutron_lib.db import api as db_api
from neutron_lib.db import resource_extend
from neutron_lib import exceptions as n_exc
from neutron_lib.plugins import utils
import vmware_nsx import vmware_nsx
from vmware_nsx._i18n import _ from vmware_nsx._i18n import _
@ -80,16 +83,16 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
dns_db.DNSDbMixin, dns_db.DNSDbMixin,
vlan_ext_db.Vlantransparent_db_mixin): vlan_ext_db.Vlantransparent_db_mixin):
supported_extension_aliases = ["allowed-address-pairs", supported_extension_aliases = [addr_apidef.ALIAS,
"binding", pbin.ALIAS,
"external-net", enet_apidef.ALIAS,
"multi-provider", mpnet_apidef.ALIAS,
"port-security", psec.ALIAS,
"provider", pnet.ALIAS,
"quotas", "quotas",
"router", l3_apidef.ALIAS,
"security-group", "security-group",
"vlan-transparent"] vlan_apidef.ALIAS]
__native_bulk_support = True __native_bulk_support = True
__native_pagination_support = True __native_pagination_support = True

View File

@ -16,17 +16,30 @@
import weakref import weakref
from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef
from neutron_lib.api.definitions import dvr as dvr_apidef
from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib.api.definitions import external_net as extnet_apidef
from neutron_lib.api.definitions import extra_dhcp_opt as edo_ext
from neutron_lib.api.definitions import extraroute as xroute_apidef
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef
from neutron_lib.api.definitions import port_security as psec from neutron_lib.api.definitions import port_security as psec
from neutron_lib.api.definitions import portbindings as pbin
from neutron_lib.api.definitions import provider_net as pnet
from neutron_lib.api import faults from neutron_lib.api import faults
from neutron_lib.api import validators from neutron_lib.api import validators
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import context as q_context from neutron_lib import context as q_context
from neutron_lib.db import api as db_api
from neutron_lib.db import model_query
from neutron_lib.db import resource_extend
from neutron_lib.db import utils as db_utils from neutron_lib.db import utils as db_utils
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import allowedaddresspairs as addr_exc from neutron_lib.exceptions import allowedaddresspairs as addr_exc
from neutron_lib.exceptions import extraroute as xroute_exc
from neutron_lib.exceptions import l3 as l3_exc from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.exceptions import multiprovidernet as mpnet_exc
from neutron_lib.exceptions import port_security as psec_exc from neutron_lib.exceptions import port_security as psec_exc
from neutron_lib.plugins import utils
from oslo_concurrency import lockutils from oslo_concurrency import lockutils
from oslo_config import cfg from oslo_config import cfg
from oslo_db import exception as db_exc from oslo_db import exception as db_exc
@ -60,17 +73,6 @@ from neutron.db import securitygroups_db
from neutron.extensions import providernet from neutron.extensions import providernet
from neutron.extensions import securitygroup as ext_sg from neutron.extensions import securitygroup as ext_sg
from neutron.quota import resource_registry from neutron.quota import resource_registry
from neutron_lib.api.definitions import extra_dhcp_opt as edo_ext
from neutron_lib.api.definitions import extraroute as xroute_apidef
from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef
from neutron_lib.api.definitions import portbindings as pbin
from neutron_lib.api.definitions import provider_net as pnet
from neutron_lib.db import api as db_api
from neutron_lib.db import model_query
from neutron_lib.db import resource_extend
from neutron_lib.exceptions import extraroute as xroute_exc
from neutron_lib.exceptions import multiprovidernet as mpnet_exc
from neutron_lib.plugins import utils
import vmware_nsx import vmware_nsx
from vmware_nsx._i18n import _ from vmware_nsx._i18n import _
@ -121,21 +123,21 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
securitygroups_db.SecurityGroupDbMixin, securitygroups_db.SecurityGroupDbMixin,
dns_db.DNSDbMixin): dns_db.DNSDbMixin):
supported_extension_aliases = ["allowed-address-pairs", supported_extension_aliases = [addr_apidef.ALIAS,
"binding", pbin.ALIAS,
"dvr", dvr_apidef.ALIAS,
"ext-gw-mode", "ext-gw-mode",
xroute_apidef.ALIAS, xroute_apidef.ALIAS,
"mac-learning", "mac-learning",
"multi-provider", "multi-provider",
"network-gateway", "network-gateway",
"port-security", psec.ALIAS,
"provider", pnet.ALIAS,
"qos-queue", "qos-queue",
"quotas", "quotas",
"external-net", extnet_apidef.ALIAS,
"extra_dhcp_opt", edo_ext.ALIAS,
"router", l3_apidef.ALIAS,
"security-group", "security-group",
constants.SUBNET_ALLOCATION_EXT_ALIAS] constants.SUBNET_ALLOCATION_EXT_ALIAS]

View File

@ -30,11 +30,19 @@ from neutron.db import models_v2
from neutron.extensions import providernet from neutron.extensions import providernet
from neutron.extensions import securitygroup as ext_sg from neutron.extensions import securitygroup as ext_sg
from neutron.quota import resource_registry from neutron.quota import resource_registry
from neutron_lib.api.definitions import agent as agent_apidef
from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef
from neutron_lib.api.definitions import availability_zone as az_apidef
from neutron_lib.api.definitions import dhcpagentscheduler
from neutron_lib.api.definitions import external_net from neutron_lib.api.definitions import external_net
from neutron_lib.api.definitions import extra_dhcp_opt as ext_edo from neutron_lib.api.definitions import extra_dhcp_opt as ext_edo
from neutron_lib.api.definitions import extraroute
from neutron_lib.api.definitions import l3 as l3_apidef from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import network_availability_zone
from neutron_lib.api.definitions import port_security as psec from neutron_lib.api.definitions import port_security as psec
from neutron_lib.api.definitions import portbindings as pbin_apidef
from neutron_lib.api.definitions import provider_net as pnet_apidef
from neutron_lib.api.definitions import router_availability_zone
from neutron_lib.api.definitions import vlantransparent as vlan_apidef from neutron_lib.api.definitions import vlantransparent as vlan_apidef
from neutron_lib.api import extensions from neutron_lib.api import extensions
from neutron_lib.api import validators from neutron_lib.api import validators
@ -112,24 +120,24 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
__native_pagination_support = True __native_pagination_support = True
__native_sorting_support = True __native_sorting_support = True
supported_extension_aliases = ["allowed-address-pairs", supported_extension_aliases = [addr_apidef.ALIAS,
"address-scope", "address-scope",
"quotas", "quotas",
"binding", pbin_apidef.ALIAS,
"extra_dhcp_opt", ext_edo.ALIAS,
"agent", agent_apidef.ALIAS,
"dhcp_agent_scheduler", dhcpagentscheduler.ALIAS,
"ext-gw-mode", "ext-gw-mode",
"security-group", "security-group",
"secgroup-rule-local-ip-prefix", "secgroup-rule-local-ip-prefix",
"port-security", psec.ALIAS,
"provider", pnet_apidef.ALIAS,
"external-net", external_net.ALIAS,
"extraroute", extraroute.ALIAS,
"router", l3_apidef.ALIAS,
"availability_zone", az_apidef.ALIAS,
"network_availability_zone", network_availability_zone.ALIAS,
"router_availability_zone", router_availability_zone.ALIAS,
"subnet_allocation", "subnet_allocation",
"security-group-logging", "security-group-logging",
"provider-security-group", "provider-security-group",
@ -178,7 +186,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
# Support transparent VLANS only if the global configuration flag # Support transparent VLANS only if the global configuration flag
# vlan_transparent is True # vlan_transparent is True
if cfg.CONF.vlan_transparent: if cfg.CONF.vlan_transparent:
self.supported_extension_aliases.append("vlan-transparent") self.supported_extension_aliases.append(vlan_apidef.ALIAS)
nsxlib_utils.set_inject_headers_callback(v3_utils.inject_headers) nsxlib_utils.set_inject_headers_callback(v3_utils.inject_headers)
self._validate_nsx_policy_version() self._validate_nsx_policy_version()

View File

@ -19,16 +19,23 @@ import xml.etree.ElementTree as et
import netaddr import netaddr
from neutron_lib.agent import topics from neutron_lib.agent import topics
from neutron_lib.api.definitions import agent as agent_apidef
from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef
from neutron_lib.api.definitions import availability_zone as az_def from neutron_lib.api.definitions import availability_zone as az_def
from neutron_lib.api.definitions import dvr as dvr_apidef
from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib.api.definitions import external_net as extnet_apidef
from neutron_lib.api.definitions import extra_dhcp_opt as ext_edo from neutron_lib.api.definitions import extra_dhcp_opt as ext_edo
from neutron_lib.api.definitions import extraroute
from neutron_lib.api.definitions import flavors as flavors_apidef
from neutron_lib.api.definitions import l3 as l3_apidef from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import l3_flavors
from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef
from neutron_lib.api.definitions import network_availability_zone
from neutron_lib.api.definitions import port as port_def from neutron_lib.api.definitions import port as port_def
from neutron_lib.api.definitions import port_security as psec from neutron_lib.api.definitions import port_security as psec
from neutron_lib.api.definitions import portbindings as pbin from neutron_lib.api.definitions import portbindings as pbin
from neutron_lib.api.definitions import provider_net as pnet from neutron_lib.api.definitions import provider_net as pnet
from neutron_lib.api.definitions import router_availability_zone
from neutron_lib.api.definitions import subnet as subnet_def from neutron_lib.api.definitions import subnet as subnet_def
from neutron_lib.api.definitions import vlantransparent as vlan_apidef from neutron_lib.api.definitions import vlantransparent as vlan_apidef
from neutron_lib.api import extensions from neutron_lib.api import extensions
@ -206,21 +213,21 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
mac_db.MacLearningDbMixin, mac_db.MacLearningDbMixin,
hk_ext.Housekeeper): hk_ext.Housekeeper):
supported_extension_aliases = ["agent", supported_extension_aliases = [agent_apidef.ALIAS,
"allowed-address-pairs", addr_apidef.ALIAS,
"address-scope", "address-scope",
"binding", pbin.ALIAS,
"dns-search-domain", "dns-search-domain",
"dvr", dvr_apidef.ALIAS,
"ext-gw-mode", "ext-gw-mode",
"multi-provider", mpnet_apidef.ALIAS,
"port-security", psec.ALIAS,
"provider", pnet.ALIAS,
"quotas", "quotas",
"external-net", extnet_apidef.ALIAS,
"extra_dhcp_opt", ext_edo.ALIAS,
"extraroute", extraroute.ALIAS,
"router", l3_apidef.ALIAS,
"security-group", "security-group",
"secgroup-rule-local-ip-prefix", "secgroup-rule-local-ip-prefix",
"security-group-logging", "security-group-logging",
@ -229,11 +236,11 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
"vnic-index", "vnic-index",
"advanced-service-providers", "advanced-service-providers",
"subnet_allocation", "subnet_allocation",
"availability_zone", az_def.ALIAS,
"network_availability_zone", network_availability_zone.ALIAS,
"router_availability_zone", router_availability_zone.ALIAS,
"l3-flavors", l3_flavors.ALIAS,
"flavors", flavors_apidef.ALIAS,
"dhcp-mtu", "dhcp-mtu",
"mac-learning", "mac-learning",
"housekeeper", "housekeeper",
@ -319,7 +326,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
# True # True
if cfg.CONF.vlan_transparent: if cfg.CONF.vlan_transparent:
if c_utils.is_nsxv_version_6_3(self.nsx_v.vcns.get_version()): if c_utils.is_nsxv_version_6_3(self.nsx_v.vcns.get_version()):
self.supported_extension_aliases.append("vlan-transparent") self.supported_extension_aliases.append(vlan_apidef.ALIAS)
else: else:
LOG.warning("Transparent support only from " LOG.warning("Transparent support only from "
"NSX 6.3 onwards") "NSX 6.3 onwards")

View File

@ -18,14 +18,32 @@ import time
import mock import mock
import netaddr import netaddr
from neutron_lib.agent import topics from neutron_lib.agent import topics
from neutron_lib.api.definitions import agent as agent_apidef
from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef
from neutron_lib.api.definitions import availability_zone
from neutron_lib.api.definitions import dhcpagentscheduler
from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib.api.definitions import external_net as extnet_apidef
from neutron_lib.api.definitions import extra_dhcp_opt as ext_edo
from neutron_lib.api.definitions import extraroute
from neutron_lib.api.definitions import l3 as l3_apidef from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import network_availability_zone
from neutron_lib.api.definitions import port_security as psec from neutron_lib.api.definitions import port_security as psec
from neutron_lib.api.definitions import portbindings as pbin_apidef
from neutron_lib.api.definitions import provider_net
from neutron_lib.api.definitions import router_availability_zone
from neutron_lib.api.definitions import vlantransparent as vlan_apidef
from neutron_lib.api import extensions from neutron_lib.api import extensions
from neutron_lib.api import validators
from neutron_lib.callbacks import events
from neutron_lib.callbacks import exceptions as callback_exc
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import constants as const
from neutron_lib import context as q_context
from neutron_lib.db import api as db_api from neutron_lib.db import api as db_api
from neutron_lib.db import resource_extend from neutron_lib.db import resource_extend
from neutron_lib.db import utils as db_utils from neutron_lib.db import utils as db_utils
from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import l3 as l3_exc from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants as plugin_const from neutron_lib.plugins import constants as plugin_const
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
@ -43,16 +61,7 @@ from neutron.db import models_v2
from neutron.extensions import providernet from neutron.extensions import providernet
from neutron.extensions import securitygroup as ext_sg from neutron.extensions import securitygroup as ext_sg
from neutron.quota import resource_registry from neutron.quota import resource_registry
from neutron_lib.api.definitions import extra_dhcp_opt as ext_edo
from neutron_lib.api.definitions import vlantransparent as vlan_apidef
from neutron_lib.api import validators
from neutron_lib.callbacks import events
from neutron_lib.callbacks import exceptions as callback_exc
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import constants as const
from neutron_lib import context as q_context
from neutron_lib import exceptions as n_exc
from oslo_config import cfg from oslo_config import cfg
from oslo_db import exception as db_exc from oslo_db import exception as db_exc
from oslo_log import log from oslo_log import log
@ -129,24 +138,24 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
__native_pagination_support = True __native_pagination_support = True
__native_sorting_support = True __native_sorting_support = True
supported_extension_aliases = ["allowed-address-pairs", supported_extension_aliases = [addr_apidef.ALIAS,
"address-scope", "address-scope",
"quotas", "quotas",
"binding", pbin_apidef.ALIAS,
"extra_dhcp_opt", ext_edo.ALIAS,
"agent", agent_apidef.ALIAS,
"dhcp_agent_scheduler", dhcpagentscheduler.ALIAS,
"ext-gw-mode", "ext-gw-mode",
"security-group", "security-group",
"secgroup-rule-local-ip-prefix", "secgroup-rule-local-ip-prefix",
"port-security", psec.ALIAS,
"provider", provider_net.ALIAS,
"external-net", extnet_apidef.ALIAS,
"extraroute", extraroute.ALIAS,
"router", l3_apidef.ALIAS,
"availability_zone", availability_zone.ALIAS,
"network_availability_zone", network_availability_zone.ALIAS,
"router_availability_zone", router_availability_zone.ALIAS,
"subnet_allocation", "subnet_allocation",
"security-group-logging", "security-group-logging",
"provider-security-group", "provider-security-group",
@ -240,7 +249,7 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
# True # True
if cfg.CONF.vlan_transparent: if cfg.CONF.vlan_transparent:
if self.nsxlib.feature_supported(nsxlib_consts.FEATURE_TRUNK_VLAN): if self.nsxlib.feature_supported(nsxlib_consts.FEATURE_TRUNK_VLAN):
self.supported_extension_aliases.append("vlan-transparent") self.supported_extension_aliases.append(vlan_apidef.ALIAS)
else: else:
LOG.warning("Current NSX version %s doesn't support " LOG.warning("Current NSX version %s doesn't support "
"transparent vlans", self.nsxlib.get_version()) "transparent vlans", self.nsxlib.get_version())

View File

@ -15,7 +15,7 @@
# under the License. # under the License.
from neutron.services.qos import qos_plugin from neutron.services.qos import qos_plugin
from neutron_lib.api.definitions import qos as qos_apidef
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
@ -29,7 +29,7 @@ class NsxVQosPlugin(qos_plugin.QoSPlugin):
"""Service plugin for VMware NSX-v to implement Neutron's Qos API.""" """Service plugin for VMware NSX-v to implement Neutron's Qos API."""
supported_extension_aliases = ["qos"] supported_extension_aliases = [qos_apidef.ALIAS]
def __init__(self): def __init__(self):
LOG.info("Loading VMware NSX-V Qos Service Plugin") LOG.info("Loading VMware NSX-V Qos Service Plugin")