Merge "use neutron_lib's provider_net api-def"
This commit is contained in:
commit
f58904e669
@ -16,6 +16,7 @@
|
||||
import functools
|
||||
|
||||
import netaddr
|
||||
from neutron_lib.api.definitions import provider_net as providernet
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import exceptions as n_exc
|
||||
@ -48,7 +49,6 @@ from neutron.db.models import l3ha as l3ha_model
|
||||
from neutron.extensions import l3
|
||||
from neutron.extensions import l3_ext_ha_mode as l3_ha
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import providernet
|
||||
from neutron.plugins.common import utils as p_utils
|
||||
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api import converters
|
||||
from neutron_lib.api.definitions import provider_net as pnet
|
||||
from neutron_lib.api import extensions
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
@ -21,7 +22,6 @@ from neutron_lib import exceptions as nexception
|
||||
import webob.exc
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.extensions import providernet as pnet
|
||||
|
||||
SEGMENTS = 'segments'
|
||||
|
||||
|
@ -13,53 +13,22 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api import converters
|
||||
from neutron_lib.api.definitions import provider_net
|
||||
from neutron_lib.api import extensions
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import exceptions as n_exc
|
||||
|
||||
from neutron._i18n import _
|
||||
|
||||
|
||||
NETWORK_TYPE = 'provider:network_type'
|
||||
PHYSICAL_NETWORK = 'provider:physical_network'
|
||||
SEGMENTATION_ID = 'provider:segmentation_id'
|
||||
ATTRIBUTES = (NETWORK_TYPE, PHYSICAL_NETWORK, SEGMENTATION_ID)
|
||||
|
||||
# Common definitions for maximum string field length
|
||||
NETWORK_TYPE_MAX_LEN = 32
|
||||
PHYSICAL_NETWORK_MAX_LEN = 64
|
||||
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
'networks': {
|
||||
NETWORK_TYPE: {'allow_post': True, 'allow_put': True,
|
||||
'validate': {'type:string': NETWORK_TYPE_MAX_LEN},
|
||||
'default': constants.ATTR_NOT_SPECIFIED,
|
||||
'enforce_policy': True,
|
||||
'is_visible': True},
|
||||
PHYSICAL_NETWORK: {'allow_post': True, 'allow_put': True,
|
||||
'validate': {'type:string':
|
||||
PHYSICAL_NETWORK_MAX_LEN},
|
||||
'default': constants.ATTR_NOT_SPECIFIED,
|
||||
'enforce_policy': True,
|
||||
'is_visible': True},
|
||||
SEGMENTATION_ID: {'allow_post': True, 'allow_put': True,
|
||||
'convert_to': converters.convert_to_int,
|
||||
'enforce_policy': True,
|
||||
'default': constants.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def _raise_if_updates_provider_attributes(attrs):
|
||||
"""Raise exception if provider attributes are present.
|
||||
|
||||
This method is used for plugins that do not support
|
||||
updating provider networks.
|
||||
"""
|
||||
if any(validators.is_attr_set(attrs.get(a)) for a in ATTRIBUTES):
|
||||
if any(validators.is_attr_set(attrs.get(a))
|
||||
for a in provider_net.ATTRIBUTES):
|
||||
msg = _("Plugin does not support updating provider attributes")
|
||||
raise n_exc.InvalidInput(error_message=msg)
|
||||
|
||||
@ -79,22 +48,22 @@ class Providernet(extensions.ExtensionDescriptor):
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return "Provider Network"
|
||||
return provider_net.NAME
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
return "provider"
|
||||
return provider_net.ALIAS
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return "Expose mapping of virtual networks to physical networks"
|
||||
return provider_net.DESCRIPTION
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2012-09-07T10:00:00-00:00"
|
||||
return provider_net.UPDATED_TIMESTAMP
|
||||
|
||||
def get_extended_resources(self, version):
|
||||
if version == "2.0":
|
||||
return EXTENDED_ATTRIBUTES_2_0
|
||||
return provider_net.RESOURCE_ATTRIBUTE_MAP
|
||||
else:
|
||||
return {}
|
||||
|
@ -16,6 +16,7 @@ import abc
|
||||
import six
|
||||
|
||||
from neutron_lib.api import converters
|
||||
from neutron_lib.api.definitions import provider_net as providernet
|
||||
from neutron_lib.api import extensions as api_extensions
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import constants as db_const
|
||||
@ -24,7 +25,6 @@ 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.extensions import providernet
|
||||
|
||||
SEGMENT = 'segment'
|
||||
SEGMENTS = '%ss' % SEGMENT
|
||||
|
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import provider_net as provider
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import exceptions as exc
|
||||
@ -28,7 +29,6 @@ from neutron.db import segments_db
|
||||
from neutron.extensions import external_net
|
||||
from neutron.extensions import multiprovidernet as mpnet
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import providernet as provider
|
||||
from neutron.extensions import vlantransparent
|
||||
from neutron.plugins.ml2.common import exceptions as ml2_exc
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
from eventlet import greenthread
|
||||
from neutron_lib.api.definitions import provider_net
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants as const
|
||||
from neutron_lib import exceptions as exc
|
||||
@ -698,7 +699,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
except KeyError:
|
||||
segments = [network]
|
||||
for s in segments:
|
||||
segment_type = s[provider.NETWORK_TYPE]
|
||||
segment_type = s[provider_net.NETWORK_TYPE]
|
||||
try:
|
||||
type_driver = self.type_manager.drivers[segment_type].obj
|
||||
except KeyError:
|
||||
@ -709,7 +710,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
# a bad setup, it's better to be safe than sorry here. Also,
|
||||
# several unit tests use non-existent driver types that may
|
||||
# trigger the exception here.
|
||||
if segment_type and s[provider.SEGMENTATION_ID]:
|
||||
if segment_type and s[provider_net.SEGMENTATION_ID]:
|
||||
LOG.warning(
|
||||
_LW("Failed to determine MTU for segment "
|
||||
"%(segment_type)s:%(segment_id)s; network "
|
||||
@ -717,12 +718,12 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
"accurate"),
|
||||
{
|
||||
'segment_type': segment_type,
|
||||
'segment_id': s[provider.SEGMENTATION_ID],
|
||||
'segment_id': s[provider_net.SEGMENTATION_ID],
|
||||
'network_id': network['id'],
|
||||
}
|
||||
)
|
||||
else:
|
||||
mtu = type_driver.get_mtu(s[provider.PHYSICAL_NETWORK])
|
||||
mtu = type_driver.get_mtu(s[provider_net.PHYSICAL_NETWORK])
|
||||
# Some drivers, like 'local', may return None; the assumption
|
||||
# then is that for the segment type, MTU has no meaning or
|
||||
# unlimited, and so we should then ignore those values.
|
||||
|
@ -16,6 +16,7 @@
|
||||
import collections
|
||||
from operator import attrgetter
|
||||
|
||||
from neutron_lib.api.definitions import provider_net as providernet
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context
|
||||
import six
|
||||
@ -25,7 +26,6 @@ from neutron.db import agents_db
|
||||
from neutron.db import agentschedulers_db
|
||||
from neutron.db import common_db_mixin
|
||||
from neutron.db.network_dhcp_agent_binding import models as ndab_model
|
||||
from neutron.extensions import providernet
|
||||
from neutron.scheduler import dhcp_agent_scheduler
|
||||
from neutron.tests.common import helpers
|
||||
from neutron.tests.unit.plugins.ml2 import test_plugin
|
||||
|
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from neutron_lib.api.definitions import provider_net as providernet
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib import exceptions as n_exc
|
||||
@ -40,7 +41,6 @@ from neutron.extensions import external_net
|
||||
from neutron.extensions import l3
|
||||
from neutron.extensions import l3_ext_ha_mode
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import providernet
|
||||
from neutron.scheduler import l3_agent_scheduler
|
||||
from neutron.services.revisions import revision_plugin
|
||||
from neutron.tests.common import helpers
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from neutron_lib.api.definitions import provider_net
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib.plugins import directory
|
||||
@ -81,9 +82,9 @@ class ProvidernetExtensionTestCase(testlib_api.WebTestCase):
|
||||
|
||||
def _prepare_net_data(self):
|
||||
return {'name': 'net1',
|
||||
pnet.NETWORK_TYPE: 'sometype',
|
||||
pnet.PHYSICAL_NETWORK: 'physnet',
|
||||
pnet.SEGMENTATION_ID: 666}
|
||||
provider_net.NETWORK_TYPE: 'sometype',
|
||||
provider_net.PHYSICAL_NETWORK: 'physnet',
|
||||
provider_net.SEGMENTATION_ID: 666}
|
||||
|
||||
def _put_network_with_provider_attrs(self, ctx, expect_errors=False):
|
||||
data = self._prepare_net_data()
|
||||
@ -140,7 +141,7 @@ class ProvidernetExtensionTestCase(testlib_api.WebTestCase):
|
||||
def test_network_create_with_bad_provider_attrs_400(self):
|
||||
ctx = context.get_admin_context()
|
||||
ctx.tenant_id = 'an_admin'
|
||||
bad_data = {pnet.SEGMENTATION_ID: "abc"}
|
||||
bad_data = {provider_net.SEGMENTATION_ID: "abc"}
|
||||
res, _1 = self._post_network_with_bad_provider_attrs(ctx, bad_data,
|
||||
True)
|
||||
self.assertEqual(web_exc.HTTPBadRequest.code, res.status_int)
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from neutron_lib.api.definitions import provider_net as pnet
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib import exceptions
|
||||
@ -29,7 +30,6 @@ from neutron.db import common_db_mixin
|
||||
from neutron.db import l3_agentschedulers_db
|
||||
from neutron.db import l3_hamode_db
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import providernet as pnet
|
||||
from neutron.plugins.ml2 import db as ml2_db
|
||||
from neutron.plugins.ml2 import driver_context
|
||||
from neutron.plugins.ml2.drivers.l2pop import db as l2pop_db
|
||||
|
@ -17,6 +17,7 @@ from keystoneauth1 import loading
|
||||
from keystoneauth1 import session
|
||||
import mock
|
||||
import netaddr
|
||||
from neutron_lib.api.definitions import provider_net as pnet
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib.plugins import directory
|
||||
@ -24,7 +25,6 @@ from oslo_utils import uuidutils
|
||||
import testtools
|
||||
|
||||
from neutron.extensions import dns
|
||||
from neutron.extensions import providernet as pnet
|
||||
from neutron.objects import ports as port_obj
|
||||
from neutron.plugins.ml2 import config
|
||||
from neutron.plugins.ml2.extensions import dns_integration
|
||||
|
@ -21,6 +21,7 @@ import six
|
||||
import testtools
|
||||
import webob
|
||||
|
||||
from neutron_lib.api.definitions import provider_net as pnet
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib import exceptions as exc
|
||||
@ -44,7 +45,6 @@ from neutron.extensions import availability_zone as az_ext
|
||||
from neutron.extensions import external_net
|
||||
from neutron.extensions import multiprovidernet as mpnet
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import providernet as pnet
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.ml2.common import exceptions as ml2_exc
|
||||
from neutron.plugins.ml2 import config
|
||||
|
Loading…
Reference in New Issue
Block a user