use core resource attribute constants from neutron-lib
neutron-lib now contains the API definitions for neutron's core resources. This patch removes the constant core resource and collection variables and uses them from lib. Subsequent patches will consume the actual core resource attribute definitions. NeutronLibImpact Change-Id: Ia9afdf620cd538b2aa420593277d6403a45c996b
This commit is contained in:
parent
b1dd13abfb
commit
62576cabf7
@ -14,6 +14,10 @@
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api import converters as lib_converters
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib.api.definitions import subnetpool as subnetpool_def
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import constants as db_const
|
||||
|
||||
@ -22,18 +26,10 @@ from neutron_lib.db import constants as db_const
|
||||
SHARED = 'shared'
|
||||
|
||||
# Define constants for base resource name
|
||||
NETWORK = 'network'
|
||||
NETWORKS = '%ss' % NETWORK
|
||||
PORT = 'port'
|
||||
PORTS = '%ss' % PORT
|
||||
SUBNET = 'subnet'
|
||||
SUBNETS = '%ss' % SUBNET
|
||||
SUBNETPOOL = 'subnetpool'
|
||||
SUBNETPOOLS = '%ss' % SUBNETPOOL
|
||||
CORE_RESOURCES = {'network': 'networks',
|
||||
'subnet': 'subnets',
|
||||
'subnetpool': 'subnetpools',
|
||||
'port': 'ports'}
|
||||
CORE_RESOURCES = {net_def.RESOURCE_NAME: net_def.COLLECTION_NAME,
|
||||
subnet_def.RESOURCE_NAME: subnet_def.COLLECTION_NAME,
|
||||
subnetpool_def.RESOURCE_NAME: subnetpool_def.COLLECTION_NAME,
|
||||
port_def.RESOURCE_NAME: port_def.COLLECTION_NAME}
|
||||
# Note: a default of ATTR_NOT_SPECIFIED indicates that an
|
||||
# attribute is not required, but will be generated by the plugin
|
||||
# if it is not specified. Particularly, a value of ATTR_NOT_SPECIFIED
|
||||
@ -58,7 +54,7 @@ CORE_RESOURCES = {'network': 'networks',
|
||||
# mechanism, ie: there might be rules which refer to this attribute.
|
||||
|
||||
RESOURCE_ATTRIBUTE_MAP = {
|
||||
NETWORKS: {
|
||||
net_def.COLLECTION_NAME: {
|
||||
'id': {'allow_post': False, 'allow_put': False,
|
||||
'validate': {'type:uuid': None},
|
||||
'is_visible': True,
|
||||
@ -88,7 +84,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||
'required_by_policy': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
PORTS: {
|
||||
port_def.COLLECTION_NAME: {
|
||||
'id': {'allow_post': False, 'allow_put': False,
|
||||
'validate': {'type:uuid': None},
|
||||
'is_visible': True,
|
||||
@ -134,7 +130,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||
'status': {'allow_post': False, 'allow_put': False,
|
||||
'is_visible': True},
|
||||
},
|
||||
SUBNETS: {
|
||||
subnet_def.COLLECTION_NAME: {
|
||||
'id': {'allow_post': False, 'allow_put': False,
|
||||
'validate': {'type:uuid': None},
|
||||
'is_visible': True,
|
||||
@ -215,7 +211,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||
'required_by_policy': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
SUBNETPOOLS: {
|
||||
subnetpool_def.COLLECTION_NAME: {
|
||||
'id': {'allow_post': False,
|
||||
'allow_put': False,
|
||||
'validate': {'type:uuid': None},
|
||||
@ -282,7 +278,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||
# Identify the attribute used by a resource to reference another resource
|
||||
|
||||
RESOURCE_FOREIGN_KEYS = {
|
||||
NETWORKS: 'network_id'
|
||||
net_def.COLLECTION_NAME: 'network_id'
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,11 +12,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib import constants
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import _utils as db_utils
|
||||
from neutron.db import api as db_api
|
||||
@ -119,7 +119,7 @@ class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
|
||||
address_scope.delete()
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attr.NETWORKS])
|
||||
@resource_extend.extends([net_def.COLLECTION_NAME])
|
||||
def _extend_network_dict_address_scope(network_res, network_db):
|
||||
network_res[ext_address_scope.IPV4_ADDRESS_SCOPE] = None
|
||||
network_res[ext_address_scope.IPV6_ADDRESS_SCOPE] = None
|
||||
|
@ -13,9 +13,9 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api import validators
|
||||
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron.common import utils
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import _utils as db_utils
|
||||
@ -65,7 +65,7 @@ class AllowedAddressPairsMixin(object):
|
||||
for pair in pairs]
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attr.PORTS])
|
||||
@resource_extend.extends([port_def.COLLECTION_NAME])
|
||||
def _extend_port_dict_allowed_address_pairs(port_res, port_db):
|
||||
# If port_db is provided, allowed address pairs will be accessed via
|
||||
# sqlalchemy models. As they're loaded together with ports this
|
||||
|
@ -11,9 +11,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.extensions import availability_zone as az_ext
|
||||
from neutron.extensions import network_availability_zone as net_az
|
||||
@ -24,7 +24,7 @@ class NetworkAvailabilityZoneMixin(net_az.NetworkAvailabilityZonePluginBase):
|
||||
"""Mixin class to enable network's availability zone attributes."""
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.NETWORKS])
|
||||
@resource_extend.extends([net_def.COLLECTION_NAME])
|
||||
def _extend_availability_zone(net_res, net_db):
|
||||
net_res[az_ext.AZ_HINTS] = az_ext.convert_az_string_to_list(
|
||||
net_db[az_ext.AZ_HINTS])
|
||||
|
@ -15,6 +15,10 @@
|
||||
|
||||
import functools
|
||||
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib.api.definitions import subnetpool as subnetpool_def
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import exceptions as n_exc
|
||||
@ -23,7 +27,6 @@ from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from sqlalchemy.orm import exc
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.common import exceptions
|
||||
from neutron.db import _model_query as model_query
|
||||
@ -154,7 +157,7 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
|
||||
# The shared attribute for a subnet is the same as its parent network
|
||||
res['shared'] = self._is_network_shared(context, subnet.rbac_entries)
|
||||
# Call auxiliary extend functions, if any
|
||||
resource_extend.apply_funcs(attributes.SUBNETS, res, subnet)
|
||||
resource_extend.apply_funcs(subnet_def.COLLECTION_NAME, res, subnet)
|
||||
return db_utils.resource_fields(res, fields)
|
||||
|
||||
def _make_subnetpool_dict(self, subnetpool, fields=None):
|
||||
@ -173,7 +176,8 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
|
||||
'ip_version': subnetpool['ip_version'],
|
||||
'default_quota': subnetpool['default_quota'],
|
||||
'address_scope_id': subnetpool['address_scope_id']}
|
||||
resource_extend.apply_funcs(attributes.SUBNETPOOLS, res, subnetpool)
|
||||
resource_extend.apply_funcs(
|
||||
subnetpool_def.COLLECTION_NAME, res, subnetpool)
|
||||
return db_utils.resource_fields(res, fields)
|
||||
|
||||
def _make_port_dict(self, port, fields=None,
|
||||
@ -192,7 +196,7 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
|
||||
"device_owner": port["device_owner"]}
|
||||
# Call auxiliary extend functions, if any
|
||||
if process_extensions:
|
||||
resource_extend.apply_funcs(attributes.PORTS, res, port)
|
||||
resource_extend.apply_funcs(port_def.COLLECTION_NAME, res, port)
|
||||
return db_utils.resource_fields(res, fields)
|
||||
|
||||
def _get_network(self, context, id):
|
||||
@ -276,7 +280,7 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
|
||||
res['shared'] = self._is_network_shared(context, network.rbac_entries)
|
||||
# Call auxiliary extend functions, if any
|
||||
if process_extensions:
|
||||
resource_extend.apply_funcs(attributes.NETWORKS, res, network)
|
||||
resource_extend.apply_funcs(net_def.COLLECTION_NAME, res, network)
|
||||
return db_utils.resource_fields(res, fields)
|
||||
|
||||
def _is_network_shared(self, context, rbac_entries):
|
||||
|
@ -16,6 +16,8 @@
|
||||
import functools
|
||||
|
||||
import netaddr
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import subnetpool as subnetpool_def
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import exceptions
|
||||
@ -37,7 +39,6 @@ from sqlalchemy import not_
|
||||
|
||||
from neutron._i18n import _, _LE, _LI
|
||||
from neutron.api.rpc.agentnotifiers import l3_rpc_agent_api
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.common import exceptions as n_exc
|
||||
from neutron.common import ipv6_utils
|
||||
@ -947,7 +948,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
if auto_subnet:
|
||||
# special flag to avoid re-allocation on auto subnets
|
||||
fixed.append({'subnet_id': sub_id, 'delete_subnet': True})
|
||||
data = {attributes.PORT: {'fixed_ips': fixed}}
|
||||
data = {port_def.RESOURCE_NAME: {'fixed_ips': fixed}}
|
||||
self.update_port(context, port_id, data)
|
||||
except exc.PortNotFound:
|
||||
# port is gone
|
||||
@ -1159,7 +1160,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
|
||||
for key in ['min_prefixlen', 'max_prefixlen', 'default_prefixlen']:
|
||||
updated['key'] = str(updated[key])
|
||||
resource_extend.apply_funcs(attributes.SUBNETPOOLS,
|
||||
resource_extend.apply_funcs(subnetpool_def.COLLECTION_NAME,
|
||||
updated, orig_sp.db_obj)
|
||||
return updated
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
@ -24,7 +25,6 @@ from neutron_lib.plugins import directory
|
||||
from sqlalchemy.sql import expression as expr
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import _model_query as model_query
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import _utils as db_utils
|
||||
@ -84,7 +84,7 @@ class External_net_db_mixin(object):
|
||||
context, network_id=net_id)
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.NETWORKS])
|
||||
@resource_extend.extends([net_def.COLLECTION_NAME])
|
||||
def _extend_network_dict_l3(network_res, network_db):
|
||||
# Comparing with None for converting uuid into bool
|
||||
network_res[external_net.EXTERNAL] = network_db.external is not None
|
||||
|
@ -14,9 +14,8 @@
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import extra_dhcp_opt as edo_ext
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
from neutron.objects.port.extensions import extra_dhcp_opt as obj_extra_dhcp
|
||||
@ -118,7 +117,7 @@ class ExtraDhcpOptMixin(object):
|
||||
return bool(dopts)
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.PORTS])
|
||||
@resource_extend.extends([port_def.COLLECTION_NAME])
|
||||
def _extend_port_dict_extra_dhcp_opt(res, port):
|
||||
res[edo_ext.EXTRADHCPOPTS] = [{'opt_name': dho.opt_name,
|
||||
'opt_value': dho.opt_value,
|
||||
|
@ -16,6 +16,7 @@
|
||||
import functools
|
||||
|
||||
import netaddr
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import portbindings
|
||||
from neutron_lib.api.definitions import provider_net as providernet
|
||||
from neutron_lib.api import validators
|
||||
@ -35,7 +36,6 @@ from sqlalchemy import exc as sql_exc
|
||||
from sqlalchemy import orm
|
||||
|
||||
from neutron._i18n import _, _LE, _LI, _LW
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.common import utils as n_utils
|
||||
from neutron.db import _utils as db_utils
|
||||
@ -698,7 +698,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
|
||||
port[portbindings.HOST_ID] = host
|
||||
try:
|
||||
self._core_plugin.update_port(admin_ctx, port['id'],
|
||||
{attributes.PORT: port})
|
||||
{port_def.RESOURCE_NAME: port})
|
||||
except (orm.exc.StaleDataError, orm.exc.ObjectDeletedError,
|
||||
n_exc.PortNotFound):
|
||||
# Take concurrently deleted interfaces in to account
|
||||
|
@ -13,6 +13,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib.api.definitions import subnetpool as subnetpool_def
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import constants as db_const
|
||||
from neutron_lib.db import model_base
|
||||
@ -20,7 +24,6 @@ import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
from sqlalchemy import sql
|
||||
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron.db.network_dhcp_agent_binding import models as ndab_model
|
||||
from neutron.db import rbac_db_models
|
||||
from neutron.db import standard_attr
|
||||
@ -106,7 +109,7 @@ class Port(standard_attr.HasStandardAttributes, model_base.BASEV2,
|
||||
name='uniq_ports0network_id0mac_address'),
|
||||
model_base.BASEV2.__table_args__
|
||||
)
|
||||
api_collections = [attr.PORTS]
|
||||
api_collections = [port_def.COLLECTION_NAME]
|
||||
|
||||
def __init__(self, id=None, tenant_id=None, project_id=None, name=None,
|
||||
network_id=None, mac_address=None, admin_state_up=None,
|
||||
@ -198,7 +201,7 @@ class Subnet(standard_attr.HasStandardAttributes, model_base.BASEV2,
|
||||
rbac_db_models.NetworkRBAC, lazy='subquery', uselist=True,
|
||||
foreign_keys='Subnet.network_id',
|
||||
primaryjoin='Subnet.network_id==NetworkRBAC.object_id')
|
||||
api_collections = [attr.SUBNETS]
|
||||
api_collections = [subnet_def.COLLECTION_NAME]
|
||||
|
||||
|
||||
class SubnetPoolPrefix(model_base.BASEV2):
|
||||
@ -235,7 +238,7 @@ class SubnetPool(standard_attr.HasStandardAttributes, model_base.BASEV2,
|
||||
backref='subnetpools',
|
||||
cascade='all, delete, delete-orphan',
|
||||
lazy='subquery')
|
||||
api_collections = [attr.SUBNETPOOLS]
|
||||
api_collections = [subnetpool_def.COLLECTION_NAME]
|
||||
|
||||
|
||||
class Network(standard_attr.HasStandardAttributes, model_base.BASEV2,
|
||||
@ -256,4 +259,4 @@ class Network(standard_attr.HasStandardAttributes, model_base.BASEV2,
|
||||
dhcp_agents = orm.relationship(
|
||||
'Agent', lazy='subquery', viewonly=True,
|
||||
secondary=ndab_model.NetworkDhcpAgentBinding.__table__)
|
||||
api_collections = [attr.NETWORKS]
|
||||
api_collections = [net_def.COLLECTION_NAME]
|
||||
|
@ -13,9 +13,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ class PortBindingBaseMixin(object):
|
||||
port_res.update(self.base_binding_dict)
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.PORTS])
|
||||
@resource_extend.extends([port_def.COLLECTION_NAME])
|
||||
def _extend_port_dict_binding(port_res, port_db):
|
||||
plugin = directory.get_plugin()
|
||||
if not isinstance(plugin, PortBindingBaseMixin):
|
||||
|
@ -13,11 +13,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import portbindings
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import _model_query as model_query
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
@ -103,7 +103,7 @@ class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
|
||||
self._extend_port_dict_binding_host(port_res, host)
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.PORTS])
|
||||
@resource_extend.extends([port_def.COLLECTION_NAME])
|
||||
def _extend_port_dict_binding(port_res, port_db):
|
||||
plugin = directory.get_plugin()
|
||||
if not isinstance(plugin, PortBindingMixin):
|
||||
|
@ -12,12 +12,13 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import network as net_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 import validators
|
||||
from neutron_lib.plugins import directory
|
||||
from neutron_lib.utils import net
|
||||
|
||||
from neutron.api.v2 import attributes as attrs
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import portsecurity_db_common
|
||||
|
||||
@ -26,7 +27,8 @@ from neutron.db import portsecurity_db_common
|
||||
class PortSecurityDbMixin(portsecurity_db_common.PortSecurityDbCommon):
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attrs.NETWORKS, attrs.PORTS])
|
||||
@resource_extend.extends([net_def.COLLECTION_NAME,
|
||||
port_def.COLLECTION_NAME])
|
||||
def _extend_port_security_dict(response_data, db_data):
|
||||
plugin = directory.get_plugin()
|
||||
if ('port-security' in
|
||||
|
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
import netaddr
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import exceptions
|
||||
@ -27,7 +28,6 @@ import six
|
||||
from sqlalchemy.orm import scoped_session
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.common import utils
|
||||
from neutron.db import _model_query as model_query
|
||||
@ -701,7 +701,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
**kwargs)
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.PORTS])
|
||||
@resource_extend.extends([port_def.COLLECTION_NAME])
|
||||
def _extend_port_dict_security_group(port_res, port_db):
|
||||
# Security group bindings will be retrieved from the SQLAlchemy
|
||||
# model. As they're loaded eagerly with ports because of the
|
||||
|
@ -16,7 +16,8 @@
|
||||
# TODO(ihrachys): consider renaming the module since now it does not contain
|
||||
# any models at all
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
|
||||
|
||||
@ -25,7 +26,7 @@ class SubnetServiceTypeMixin(object):
|
||||
"""Mixin class to extend subnet with service type attribute"""
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.SUBNETS])
|
||||
@resource_extend.extends([subnet_def.COLLECTION_NAME])
|
||||
def _extend_subnet_service_types(subnet_res, subnet_db):
|
||||
subnet_res['service_types'] = [service_type['service_type'] for
|
||||
service_type in
|
||||
|
@ -12,7 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.extensions import vlantransparent
|
||||
|
||||
@ -22,7 +23,7 @@ class Vlantransparent_db_mixin(object):
|
||||
"""Mixin class to add vlan transparent methods to db_base_plugin_v2."""
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.NETWORKS])
|
||||
@resource_extend.extends([net_def.COLLECTION_NAME])
|
||||
def _extend_network_dict_vlan_transparent(network_res, network_db):
|
||||
network_res[vlantransparent.VLANTRANSPARENT] = (
|
||||
network_db.vlan_transparent)
|
||||
|
@ -15,6 +15,8 @@
|
||||
import abc
|
||||
|
||||
from neutron_lib.api import converters
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api.definitions import subnetpool as subnetpool_def
|
||||
from neutron_lib.api import extensions as api_extensions
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import constants as db_const
|
||||
@ -64,14 +66,14 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||
'validate': {'type:values': [4, 6]},
|
||||
'is_visible': True},
|
||||
},
|
||||
attr.SUBNETPOOLS: {
|
||||
subnetpool_def.COLLECTION_NAME: {
|
||||
ADDRESS_SCOPE_ID: {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': constants.ATTR_NOT_SPECIFIED,
|
||||
'validate': {'type:uuid_or_none': None},
|
||||
'is_visible': True}
|
||||
},
|
||||
attr.NETWORKS: {
|
||||
net_def.COLLECTION_NAME: {
|
||||
IPV4_ADDRESS_SCOPE: {'allow_post': False,
|
||||
'allow_put': False,
|
||||
'is_visible': True},
|
||||
|
@ -12,14 +12,13 @@
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api import converters
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib.api import extensions
|
||||
from neutron_lib import constants
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
|
||||
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
attributes.SUBNETS: {
|
||||
subnet_def.COLLECTION_NAME: {
|
||||
'use_default_subnetpool': {'allow_post': True,
|
||||
'allow_put': False,
|
||||
'default': False,
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
import re
|
||||
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api import extensions
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import exceptions as n_exc
|
||||
@ -22,7 +23,6 @@ from oslo_config import cfg
|
||||
import six
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron.extensions import l3
|
||||
|
||||
DNS_LABEL_MAX_LEN = 63
|
||||
@ -226,7 +226,7 @@ EXTENDED_ATTRIBUTES_2_0 = {
|
||||
'validate': {'type:dns_domain': FQDN_MAX_LEN},
|
||||
'is_visible': True},
|
||||
},
|
||||
attr.NETWORKS: {
|
||||
net_def.COLLECTION_NAME: {
|
||||
DNSDOMAIN: {'allow_post': True, 'allow_put': True,
|
||||
'default': '',
|
||||
'convert_to': convert_to_lowercase,
|
||||
|
@ -12,9 +12,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api import extensions
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
|
||||
IP_ALLOCATION = 'ip_allocation'
|
||||
IP_ALLOCATION_IMMEDIATE = 'immediate'
|
||||
@ -23,7 +23,7 @@ IP_ALLOCATION_NONE = 'none'
|
||||
|
||||
# Attribute Map
|
||||
RESOURCE_ATTRIBUTE_MAP = {
|
||||
attributes.PORTS: {
|
||||
port_def.COLLECTION_NAME: {
|
||||
IP_ALLOCATION: {'allow_post': False,
|
||||
'allow_put': False,
|
||||
'is_visible': True, },
|
||||
|
@ -17,13 +17,13 @@ import six
|
||||
|
||||
from neutron_lib.api import converters
|
||||
from neutron_lib.api.definitions import provider_net as providernet
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib.api import extensions as api_extensions
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import constants as db_const
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.api.v2 import base
|
||||
|
||||
SEGMENT = 'segment'
|
||||
@ -80,7 +80,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||
'validate': {'type:string_or_none': DESC_LEN},
|
||||
'is_visible': True},
|
||||
},
|
||||
attributes.SUBNETS: {
|
||||
subnet_def.COLLECTION_NAME: {
|
||||
SEGMENT_ID: {'allow_post': True,
|
||||
'allow_put': False,
|
||||
'default': None,
|
||||
|
@ -10,6 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib.api import extensions
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
@ -18,7 +19,6 @@ import six
|
||||
import webob.exc
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.api.v2 import attributes
|
||||
|
||||
|
||||
# List for service plugins to register their own prefixes
|
||||
@ -57,7 +57,7 @@ validators.add_validator('type:validate_subnet_service_types',
|
||||
|
||||
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
attributes.SUBNETS: {
|
||||
subnet_def.COLLECTION_NAME: {
|
||||
'service_types': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': constants.ATTR_NOT_SPECIFIED,
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
import abc
|
||||
|
||||
from neutron_lib.api.definitions import network
|
||||
from neutron_lib.api import extensions as api_extensions
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import exceptions
|
||||
@ -23,7 +24,6 @@ import webob.exc
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.api.v2 import base
|
||||
from neutron.api.v2 import resource as api_resource
|
||||
from neutron.common import rpc as n_rpc
|
||||
@ -37,7 +37,7 @@ TAG_PLUGIN_TYPE = 'TAG'
|
||||
TAG_SUPPORTED_RESOURCES = {
|
||||
# We shouldn't add new resources here. If more resources need to be tagged,
|
||||
# we must add them in new extension.
|
||||
attributes.NETWORKS: attributes.NETWORK,
|
||||
network.COLLECTION_NAME: network.RESOURCE_NAME,
|
||||
}
|
||||
|
||||
TAG_ATTRIBUTE_MAP = {
|
||||
|
@ -11,11 +11,13 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib.api.definitions import subnetpool as subnetpool_def
|
||||
from neutron_lib.api import extensions as api_extensions
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.api.v2 import base
|
||||
from neutron.api.v2 import resource as api_resource
|
||||
from neutron.extensions import l3
|
||||
@ -24,9 +26,9 @@ from neutron.extensions import tag as tag_base
|
||||
TAG_SUPPORTED_RESOURCES = {
|
||||
# We shouldn't add new resources here. If more resources need to be tagged,
|
||||
# we must add them in new extension.
|
||||
attributes.SUBNETS: attributes.SUBNET,
|
||||
attributes.PORTS: attributes.PORT,
|
||||
attributes.SUBNETPOOLS: attributes.SUBNETPOOL,
|
||||
subnet_def.COLLECTION_NAME: subnet_def.RESOURCE_NAME,
|
||||
port_def.COLLECTION_NAME: port_def.RESOURCE_NAME,
|
||||
subnetpool_def.COLLECTION_NAME: subnetpool_def.RESOURCE_NAME,
|
||||
l3.ROUTERS: l3.ROUTER,
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,9 @@ import contextlib
|
||||
import hashlib
|
||||
|
||||
from neutron_lib.api import attributes as lib_attrs
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib import constants as n_const
|
||||
from neutron_lib import exceptions
|
||||
from oslo_config import cfg
|
||||
@ -166,21 +169,21 @@ def _fixup_res_dict(context, attr_name, res_dict, check_allow_post=True):
|
||||
|
||||
|
||||
def create_network(core_plugin, context, net, check_allow_post=True):
|
||||
net_data = _fixup_res_dict(context, attributes.NETWORKS,
|
||||
net_data = _fixup_res_dict(context, net_def.COLLECTION_NAME,
|
||||
net.get('network', {}),
|
||||
check_allow_post=check_allow_post)
|
||||
return core_plugin.create_network(context, {'network': net_data})
|
||||
|
||||
|
||||
def create_subnet(core_plugin, context, subnet, check_allow_post=True):
|
||||
subnet_data = _fixup_res_dict(context, attributes.SUBNETS,
|
||||
subnet_data = _fixup_res_dict(context, subnet_def.COLLECTION_NAME,
|
||||
subnet.get('subnet', {}),
|
||||
check_allow_post=check_allow_post)
|
||||
return core_plugin.create_subnet(context, {'subnet': subnet_data})
|
||||
|
||||
|
||||
def create_port(core_plugin, context, port, check_allow_post=True):
|
||||
port_data = _fixup_res_dict(context, attributes.PORTS,
|
||||
port_data = _fixup_res_dict(context, port_def.COLLECTION_NAME,
|
||||
port.get('port', {}),
|
||||
check_allow_post=check_allow_post)
|
||||
return core_plugin.create_port(context, {'port': port_data})
|
||||
|
@ -15,9 +15,12 @@
|
||||
|
||||
from eventlet import greenthread
|
||||
from neutron_lib.api.definitions import extra_dhcp_opt as edo_ext
|
||||
from neutron_lib.api.definitions import network as net_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 portbindings
|
||||
from neutron_lib.api.definitions import provider_net
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import exceptions
|
||||
@ -48,7 +51,6 @@ from neutron.api.rpc.handlers import dvr_rpc
|
||||
from neutron.api.rpc.handlers import metadata_rpc
|
||||
from neutron.api.rpc.handlers import resources_rpc
|
||||
from neutron.api.rpc.handlers import securitygroups_rpc
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.common import rpc as n_rpc
|
||||
from neutron.common import topics
|
||||
@ -349,7 +351,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
port['status'] = const.PORT_STATUS_DOWN
|
||||
super(Ml2Plugin, self).update_port(
|
||||
mech_context._plugin_context, port_id,
|
||||
{attributes.PORT: {'status': const.PORT_STATUS_DOWN}})
|
||||
{port_def.RESOURCE_NAME: {'status': const.PORT_STATUS_DOWN}})
|
||||
|
||||
if port['device_owner'] == const.DEVICE_OWNER_DVR_INTERFACE:
|
||||
binding.vif_type = portbindings.VIF_TYPE_UNBOUND
|
||||
@ -606,7 +608,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.PORTS])
|
||||
@resource_extend.extends([port_def.COLLECTION_NAME])
|
||||
def _ml2_extend_port_dict_binding(port_res, port_db):
|
||||
plugin = directory.get_plugin()
|
||||
# None when called during unit tests for other plugins.
|
||||
@ -617,21 +619,21 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
# attributes for the resources to add those attributes to the result.
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.NETWORKS])
|
||||
@resource_extend.extends([net_def.COLLECTION_NAME])
|
||||
def _ml2_md_extend_network_dict(result, netdb):
|
||||
plugin = directory.get_plugin()
|
||||
session = plugin._object_session_or_new_session(netdb)
|
||||
plugin.extension_manager.extend_network_dict(session, netdb, result)
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.PORTS])
|
||||
@resource_extend.extends([port_def.COLLECTION_NAME])
|
||||
def _ml2_md_extend_port_dict(result, portdb):
|
||||
plugin = directory.get_plugin()
|
||||
session = plugin._object_session_or_new_session(portdb)
|
||||
plugin.extension_manager.extend_port_dict(session, portdb, result)
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.SUBNETS])
|
||||
@resource_extend.extends([subnet_def.COLLECTION_NAME])
|
||||
def _ml2_md_extend_subnet_dict(result, subnetdb):
|
||||
plugin = directory.get_plugin()
|
||||
session = plugin._object_session_or_new_session(subnetdb)
|
||||
@ -755,12 +757,12 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return min(mtus) if mtus else 0
|
||||
|
||||
def _before_create_network(self, context, network):
|
||||
net_data = network[attributes.NETWORK]
|
||||
net_data = network[net_def.RESOURCE_NAME]
|
||||
registry.notify(resources.NETWORK, events.BEFORE_CREATE, self,
|
||||
context=context, network=net_data)
|
||||
|
||||
def _create_network_db(self, context, network):
|
||||
net_data = network[attributes.NETWORK]
|
||||
net_data = network[net_def.RESOURCE_NAME]
|
||||
tenant_id = net_data['tenant_id']
|
||||
with db_api.context_manager.writer.using(context):
|
||||
net_db = self.create_network_db(context, network)
|
||||
@ -820,13 +822,14 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
def create_network_bulk(self, context, networks):
|
||||
objects = self._create_bulk_ml2(attributes.NETWORK, context, networks)
|
||||
objects = self._create_bulk_ml2(
|
||||
net_def.RESOURCE_NAME, context, networks)
|
||||
return [obj['result'] for obj in objects]
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
def update_network(self, context, id, network):
|
||||
net_data = network[attributes.NETWORK]
|
||||
net_data = network[net_def.RESOURCE_NAME]
|
||||
provider._raise_if_updates_provider_attributes(net_data)
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
@ -961,7 +964,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
result, net_db, ipam_sub = self._create_subnet_precommit(
|
||||
context, subnet)
|
||||
self.extension_manager.process_create_subnet(
|
||||
context, subnet[attributes.SUBNET], result)
|
||||
context, subnet[subnet_def.RESOURCE_NAME], result)
|
||||
network = self._make_network_dict(net_db, context=context)
|
||||
self.type_manager.extend_network_dict_provider(context, network)
|
||||
network[api.MTU] = self._get_network_mtu(network)
|
||||
@ -997,7 +1000,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
def create_subnet_bulk(self, context, subnets):
|
||||
objects = self._create_bulk_ml2(attributes.SUBNET, context, subnets)
|
||||
objects = self._create_bulk_ml2(
|
||||
subnet_def.RESOURCE_NAME, context, subnets)
|
||||
return [obj['result'] for obj in objects]
|
||||
|
||||
@utils.transaction_guard
|
||||
@ -1007,7 +1011,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
updated_subnet, original_subnet = self._update_subnet_precommit(
|
||||
context, id, subnet)
|
||||
self.extension_manager.process_update_subnet(
|
||||
context, subnet[attributes.SUBNET], updated_subnet)
|
||||
context, subnet[subnet_def.RESOURCE_NAME], updated_subnet)
|
||||
updated_subnet = self.get_subnet(context, id)
|
||||
mech_context = driver_context.SubnetContext(
|
||||
self, context, updated_subnet, network=None,
|
||||
@ -1057,7 +1061,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
# TODO(yalei) - will be simplified after security group and address pair be
|
||||
# converted to ext driver too.
|
||||
def _portsec_ext_port_create_processing(self, context, port_data, port):
|
||||
attrs = port[attributes.PORT]
|
||||
attrs = port[port_def.RESOURCE_NAME]
|
||||
port_security = ((port_data.get(psec.PORTSECURITY) is None) or
|
||||
port_data[psec.PORTSECURITY])
|
||||
|
||||
@ -1091,7 +1095,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
provisioning_blocks.DHCP_ENTITY)
|
||||
|
||||
def _before_create_port(self, context, port):
|
||||
attrs = port[attributes.PORT]
|
||||
attrs = port[port_def.RESOURCE_NAME]
|
||||
if not attrs.get('status'):
|
||||
attrs['status'] = const.PORT_STATUS_DOWN
|
||||
|
||||
@ -1102,7 +1106,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
self._ensure_default_security_group(context, attrs['tenant_id'])
|
||||
|
||||
def _create_port_db(self, context, port):
|
||||
attrs = port[attributes.PORT]
|
||||
attrs = port[port_def.RESOURCE_NAME]
|
||||
with db_api.context_manager.writer.using(context):
|
||||
dhcp_opts = attrs.get(edo_ext.EXTRADHCPOPTS, [])
|
||||
port_db = self.create_port_db(context, port)
|
||||
@ -1166,7 +1170,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
def create_port_bulk(self, context, ports):
|
||||
objects = self._create_bulk_ml2(attributes.PORT, context, ports)
|
||||
objects = self._create_bulk_ml2(port_def.RESOURCE_NAME, context, ports)
|
||||
return [obj['result'] for obj in objects]
|
||||
|
||||
# TODO(yalei) - will be simplified after security group and address pair be
|
||||
@ -1215,7 +1219,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
def update_port(self, context, id, port):
|
||||
attrs = port[attributes.PORT]
|
||||
attrs = port[port_def.RESOURCE_NAME]
|
||||
need_port_update_notify = False
|
||||
bound_mech_contexts = []
|
||||
with db_api.context_manager.writer.using(context):
|
||||
@ -1371,7 +1375,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
def update_distributed_port_binding(self, context, id, port):
|
||||
attrs = port[attributes.PORT]
|
||||
attrs = port[port_def.RESOURCE_NAME]
|
||||
|
||||
host = attrs and attrs.get(portbindings.HOST_ID)
|
||||
host_set = validators.is_attr_set(host)
|
||||
|
@ -14,6 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
@ -23,7 +24,6 @@ from neutron_lib.plugins import directory
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutron._i18n import _, _LE
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import exceptions as c_exc
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import _utils as db_utils
|
||||
@ -108,7 +108,7 @@ class AutoAllocatedTopologyMixin(common_db_mixin.CommonDbMixin):
|
||||
return self._l3_plugin
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.NETWORKS])
|
||||
@resource_extend.extends([net_def.COLLECTION_NAME])
|
||||
def _extend_external_network_default(net_res, net_db):
|
||||
"""Add is_default field to 'show' response."""
|
||||
if net_db.external is not None:
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
from keystoneauth1 import loading as ks_loading
|
||||
import netaddr
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
@ -27,7 +30,6 @@ from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from neutron._i18n import _, _LE, _LI
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import exceptions as n_exc
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
@ -61,7 +63,7 @@ class Plugin(db.SegmentDbMixin, segment.SegmentPluginBase):
|
||||
self.nova_updater = NovaSegmentNotifier()
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.NETWORKS])
|
||||
@resource_extend.extends([net_def.COLLECTION_NAME])
|
||||
def _extend_network_dict_binding(network_res, network_db):
|
||||
if not directory.get_plugin('segments'):
|
||||
return
|
||||
@ -73,12 +75,12 @@ class Plugin(db.SegmentDbMixin, segment.SegmentPluginBase):
|
||||
network_res[l2_adjacency.L2_ADJACENCY] = is_adjacent
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.SUBNETS])
|
||||
@resource_extend.extends([subnet_def.COLLECTION_NAME])
|
||||
def _extend_subnet_dict_binding(subnet_res, subnet_db):
|
||||
subnet_res['segment_id'] = subnet_db.get('segment_id')
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.PORTS])
|
||||
@resource_extend.extends([port_def.COLLECTION_NAME])
|
||||
def _extend_port_dict_binding(port_res, port_db):
|
||||
if not directory.get_plugin('segments'):
|
||||
return
|
||||
|
@ -14,11 +14,14 @@
|
||||
|
||||
import functools
|
||||
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
from neutron_lib.api.definitions import subnetpool as subnetpool_def
|
||||
from neutron_lib.plugins import directory
|
||||
from oslo_log import helpers as log_helpers
|
||||
from sqlalchemy.orm import exc
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import _model_query as model_query
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
@ -36,10 +39,10 @@ from neutron.objects import tag as tag_obj
|
||||
resource_model_map = {
|
||||
# When we'll add other resources, we must add new extension for them
|
||||
# if we don't have better discovery mechanism instead of it.
|
||||
attributes.NETWORKS: models_v2.Network,
|
||||
attributes.SUBNETS: models_v2.Subnet,
|
||||
attributes.PORTS: models_v2.Port,
|
||||
attributes.SUBNETPOOLS: models_v2.SubnetPool,
|
||||
net_def.COLLECTION_NAME: models_v2.Network,
|
||||
subnet_def.COLLECTION_NAME: models_v2.Subnet,
|
||||
port_def.COLLECTION_NAME: models_v2.Port,
|
||||
subnetpool_def.COLLECTION_NAME: models_v2.SubnetPool,
|
||||
l3_ext.ROUTERS: l3_model.Router,
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
import copy
|
||||
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import portbindings
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
@ -24,7 +25,6 @@ from neutron_lib.services import base as service_base
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import common_db_mixin
|
||||
@ -66,7 +66,7 @@ class TrunkPlugin(service_base.ServicePluginBase,
|
||||
self.check_compatibility()
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attributes.PORTS])
|
||||
@resource_extend.extends([port_def.COLLECTION_NAME])
|
||||
def _extend_port_trunk_details(port_res, port_db):
|
||||
"""Add trunk details to a port."""
|
||||
if port_db.trunk_port:
|
||||
|
@ -15,9 +15,9 @@
|
||||
from webob import exc as web_exc
|
||||
|
||||
from neutron_lib.api.definitions import data_plane_status as dps_lib
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib import constants
|
||||
|
||||
from neutron.api.v2 import attributes as attrs
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import data_plane_status_db as dps_db
|
||||
from neutron.db import db_base_plugin_v2
|
||||
@ -48,7 +48,7 @@ class DataPlaneStatusExtensionTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
supported_extension_aliases = ["data-plane-status"]
|
||||
|
||||
@staticmethod
|
||||
@resource_extend.extends([attrs.PORTS])
|
||||
@resource_extend.extends([port_def.COLLECTION_NAME])
|
||||
def _extend_port_data_plane_status(port_res, port_db):
|
||||
return dps_db.DataPlaneStatusMixin._extend_port_data_plane_status(
|
||||
port_res, port_db)
|
||||
@ -77,7 +77,7 @@ class DataPlaneStatusExtensionTestCase(
|
||||
def test_update_port_data_plane_status(self):
|
||||
with self.port() as port:
|
||||
data = {'port': {'data_plane_status': constants.ACTIVE}}
|
||||
req = self.new_update_request(attrs.PORTS,
|
||||
req = self.new_update_request(port_def.COLLECTION_NAME,
|
||||
data,
|
||||
port['port']['id'])
|
||||
res = req.get_response(self.api)
|
||||
@ -87,7 +87,8 @@ class DataPlaneStatusExtensionTestCase(
|
||||
|
||||
def test_port_create_data_plane_status_default_none(self):
|
||||
with self.port(name='port1') as port:
|
||||
req = self.new_show_request(attrs.PORTS, port['port']['id'])
|
||||
req = self.new_show_request(
|
||||
port_def.COLLECTION_NAME, port['port']['id'])
|
||||
res = self.deserialize(self.fmt, req.get_response(self.api))
|
||||
self.assertIsNone(res['port'][dps_lib.DATA_PLANE_STATUS])
|
||||
|
||||
@ -102,10 +103,10 @@ class DataPlaneStatusExtensionTestCase(
|
||||
|
||||
def test_port_update_preserves_data_plane_status(self):
|
||||
with self.port(name='port1') as port:
|
||||
res = self._update(attrs.PORTS, port['port']['id'],
|
||||
res = self._update(port_def.COLLECTION_NAME, port['port']['id'],
|
||||
{'port': {dps_lib.DATA_PLANE_STATUS:
|
||||
constants.ACTIVE}})
|
||||
res = self._update(attrs.PORTS, port['port']['id'],
|
||||
res = self._update(port_def.COLLECTION_NAME, port['port']['id'],
|
||||
{'port': {'name': 'port2'}})
|
||||
self.assertEqual(res['port']['name'], 'port2')
|
||||
self.assertEqual(res['port'][dps_lib.DATA_PLANE_STATUS],
|
||||
@ -113,7 +114,7 @@ class DataPlaneStatusExtensionTestCase(
|
||||
|
||||
def test_port_update_with_invalid_data_plane_status(self):
|
||||
with self.port(name='port1') as port:
|
||||
self._update(attrs.PORTS, port['port']['id'],
|
||||
self._update(port_def.COLLECTION_NAME, port['port']['id'],
|
||||
{'port': {dps_lib.DATA_PLANE_STATUS: "abc"}},
|
||||
web_exc.HTTPBadRequest.code)
|
||||
|
||||
@ -121,7 +122,7 @@ class DataPlaneStatusExtensionTestCase(
|
||||
expect_notify = set(['port.update.start',
|
||||
'port.update.end'])
|
||||
with self.port(name='port1') as port:
|
||||
self._update(attrs.PORTS, port['port']['id'],
|
||||
self._update(port_def.COLLECTION_NAME, port['port']['id'],
|
||||
{'port': {dps_lib.DATA_PLANE_STATUS:
|
||||
constants.ACTIVE}})
|
||||
notify = set(n['event_type'] for n in fake_notifier.NOTIFICATIONS)
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
import mock
|
||||
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import portbindings
|
||||
from neutron_lib.api.definitions import provider_net as pnet
|
||||
from neutron_lib import constants
|
||||
@ -25,7 +26,6 @@ from neutron_lib.plugins import directory
|
||||
from oslo_serialization import jsonutils
|
||||
import testtools
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.common import topics
|
||||
from neutron.db import agents_db
|
||||
@ -237,7 +237,7 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
|
||||
else:
|
||||
port[portbindings.HOST_ID] = self.agent2['host']
|
||||
plugin.update_port(self.adminContext, port['id'],
|
||||
{attributes.PORT: port})
|
||||
{port_def.RESOURCE_NAME: port})
|
||||
|
||||
def _get_first_interface(self, net_id, router_id):
|
||||
plugin = directory.get_plugin()
|
||||
|
@ -15,11 +15,11 @@
|
||||
import mock
|
||||
|
||||
from neutron_lib.api.definitions import data_plane_status as dps_lib
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
from neutron.api.v2 import attributes as attrs
|
||||
from neutron.plugins.ml2 import config
|
||||
from neutron.plugins.ml2.extensions import data_plane_status
|
||||
from neutron.tests.unit.plugins.ml2 import test_plugin
|
||||
@ -47,7 +47,8 @@ class DataPlaneStatusSML2ExtDriverTestCase(test_plugin.Ml2PluginV2TestCase):
|
||||
|
||||
def test_show_port_has_data_plane_status(self):
|
||||
with self.port() as port:
|
||||
req = self.new_show_request(attrs.PORTS, port['port']['id'],
|
||||
req = self.new_show_request(port_def.COLLECTION_NAME,
|
||||
port['port']['id'],
|
||||
self.fmt)
|
||||
p = self.deserialize(self.fmt, req.get_response(self.api))
|
||||
self.assertIsNone(p['port'][dps_lib.DATA_PLANE_STATUS])
|
||||
@ -57,7 +58,8 @@ class DataPlaneStatusSML2ExtDriverTestCase(test_plugin.Ml2PluginV2TestCase):
|
||||
admin_ctx = context.get_admin_context()
|
||||
p = {'port': {dps_lib.DATA_PLANE_STATUS: constants.ACTIVE}}
|
||||
self.plugin.update_port(admin_ctx, port['port']['id'], p)
|
||||
req = self.new_show_request(attrs.PORTS, port['port']['id'])
|
||||
req = self.new_show_request(
|
||||
port_def.COLLECTION_NAME, port['port']['id'])
|
||||
res = self.deserialize(self.fmt, req.get_response(self.api))
|
||||
self.assertEqual(res['port'][dps_lib.DATA_PLANE_STATUS],
|
||||
constants.ACTIVE)
|
||||
|
Loading…
Reference in New Issue
Block a user