Merge "use neutron-lib address scope apidef"
This commit is contained in:
commit
3f8f6fc289
@ -12,8 +12,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import address_scope as apidef
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.exceptions import address_scope as api_err
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from neutron._i18n import _
|
||||
@ -44,7 +46,7 @@ class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
|
||||
def _get_address_scope(self, context, id):
|
||||
obj = obj_addr_scope.AddressScope.get_object(context, id=id)
|
||||
if obj is None:
|
||||
raise ext_address_scope.AddressScopeNotFound(address_scope_id=id)
|
||||
raise api_err.AddressScopeNotFound(address_scope_id=id)
|
||||
return obj
|
||||
|
||||
def is_address_scope_owned_by_tenant(self, context, id):
|
||||
@ -84,7 +86,7 @@ class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
|
||||
address_scope = self._get_address_scope(context, id)
|
||||
if address_scope.shared and not a_s.get('shared', True):
|
||||
reason = _("Shared address scope can't be unshared")
|
||||
raise ext_address_scope.AddressScopeUpdateError(
|
||||
raise api_err.AddressScopeUpdateError(
|
||||
address_scope_id=id, reason=reason)
|
||||
|
||||
address_scope.update_fields(a_s)
|
||||
@ -114,24 +116,24 @@ class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
if subnetpool_obj.SubnetPool.get_objects(context,
|
||||
address_scope_id=id):
|
||||
raise ext_address_scope.AddressScopeInUse(address_scope_id=id)
|
||||
raise api_err.AddressScopeInUse(address_scope_id=id)
|
||||
address_scope = self._get_address_scope(context, id)
|
||||
address_scope.delete()
|
||||
|
||||
@staticmethod
|
||||
@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
|
||||
network_res[apidef.IPV4_ADDRESS_SCOPE] = None
|
||||
network_res[apidef.IPV6_ADDRESS_SCOPE] = None
|
||||
subnetpools = {subnet.subnetpool for subnet in network_db.subnets
|
||||
if subnet.subnetpool}
|
||||
for subnetpool in subnetpools:
|
||||
# A network will be constrained to only one subnetpool per address
|
||||
# family. Retrieve the address scope of subnetpools as the address
|
||||
# scopes of network.
|
||||
as_id = subnetpool[ext_address_scope.ADDRESS_SCOPE_ID]
|
||||
as_id = subnetpool[apidef.ADDRESS_SCOPE_ID]
|
||||
if subnetpool['ip_version'] == constants.IP_VERSION_4:
|
||||
network_res[ext_address_scope.IPV4_ADDRESS_SCOPE] = as_id
|
||||
network_res[apidef.IPV4_ADDRESS_SCOPE] = as_id
|
||||
if subnetpool['ip_version'] == constants.IP_VERSION_6:
|
||||
network_res[ext_address_scope.IPV6_ADDRESS_SCOPE] = as_id
|
||||
network_res[apidef.IPV6_ADDRESS_SCOPE] = as_id
|
||||
return network_res
|
||||
|
@ -14,118 +14,28 @@
|
||||
|
||||
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.definitions import address_scope as apidef
|
||||
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 import exceptions as nexception
|
||||
from neutron_lib.plugins import directory
|
||||
import six
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron.api.v2 import base
|
||||
|
||||
ADDRESS_SCOPE = 'address_scope'
|
||||
ADDRESS_SCOPES = '%ss' % ADDRESS_SCOPE
|
||||
ADDRESS_SCOPE_ID = 'address_scope_id'
|
||||
IPV4_ADDRESS_SCOPE = 'ipv4_%s' % ADDRESS_SCOPE
|
||||
IPV6_ADDRESS_SCOPE = 'ipv6_%s' % ADDRESS_SCOPE
|
||||
|
||||
# Attribute Map
|
||||
RESOURCE_ATTRIBUTE_MAP = {
|
||||
ADDRESS_SCOPES: {
|
||||
'id': {'allow_post': False,
|
||||
'allow_put': False,
|
||||
'validate': {'type:uuid': None},
|
||||
'is_visible': True,
|
||||
'primary_key': True},
|
||||
'name': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': '',
|
||||
'validate': {'type:string': db_const.NAME_FIELD_SIZE},
|
||||
'is_visible': True},
|
||||
'tenant_id': {'allow_post': True,
|
||||
'allow_put': False,
|
||||
'validate': {
|
||||
'type:string': db_const.PROJECT_ID_FIELD_SIZE},
|
||||
'required_by_policy': True,
|
||||
'is_visible': True},
|
||||
attr.SHARED: {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': False,
|
||||
'convert_to': converters.convert_to_boolean,
|
||||
'is_visible': True,
|
||||
'required_by_policy': True,
|
||||
'enforce_policy': True},
|
||||
'ip_version': {'allow_post': True, 'allow_put': False,
|
||||
'convert_to': converters.convert_to_int,
|
||||
'validate': {'type:values': [4, 6]},
|
||||
'is_visible': True},
|
||||
},
|
||||
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}
|
||||
},
|
||||
net_def.COLLECTION_NAME: {
|
||||
IPV4_ADDRESS_SCOPE: {'allow_post': False,
|
||||
'allow_put': False,
|
||||
'is_visible': True},
|
||||
IPV6_ADDRESS_SCOPE: {'allow_post': False,
|
||||
'allow_put': False,
|
||||
'is_visible': True},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class AddressScopeNotFound(nexception.NotFound):
|
||||
message = _("Address scope %(address_scope_id)s could not be found")
|
||||
|
||||
|
||||
class AddressScopeInUse(nexception.InUse):
|
||||
message = _("Unable to complete operation on "
|
||||
"address scope %(address_scope_id)s. There are one or more"
|
||||
" subnet pools in use on the address scope")
|
||||
|
||||
|
||||
class AddressScopeUpdateError(nexception.BadRequest):
|
||||
message = _("Unable to update address scope %(address_scope_id)s : "
|
||||
"%(reason)s")
|
||||
|
||||
|
||||
class Address_scope(api_extensions.ExtensionDescriptor):
|
||||
class Address_scope(api_extensions.APIExtensionDescriptor):
|
||||
"""Extension class supporting Address Scopes."""
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return "Address scope"
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
return "address-scope"
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return "Address scopes extension."
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2015-07-26T10:00:00-00:00"
|
||||
api_definition = apidef
|
||||
|
||||
@classmethod
|
||||
def get_resources(cls):
|
||||
"""Returns Ext Resources."""
|
||||
plugin = directory.get_plugin()
|
||||
collection_name = ADDRESS_SCOPES.replace('_', '-')
|
||||
params = RESOURCE_ATTRIBUTE_MAP.get(ADDRESS_SCOPES, dict())
|
||||
collection_name = apidef.COLLECTION_NAME.replace('_', '-')
|
||||
params = apidef.RESOURCE_ATTRIBUTE_MAP.get(
|
||||
apidef.COLLECTION_NAME, dict())
|
||||
controller = base.create_resource(collection_name,
|
||||
ADDRESS_SCOPE,
|
||||
apidef.RESOURCE_NAME,
|
||||
plugin, params, allow_bulk=True,
|
||||
allow_pagination=True,
|
||||
allow_sorting=True)
|
||||
@ -134,12 +44,6 @@ class Address_scope(api_extensions.ExtensionDescriptor):
|
||||
attr_map=params)
|
||||
return [ex]
|
||||
|
||||
def get_extended_resources(self, version):
|
||||
if version == "2.0":
|
||||
return RESOURCE_ATTRIBUTE_MAP
|
||||
else:
|
||||
return {}
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class AddressScopePluginBase(object):
|
||||
|
@ -16,6 +16,7 @@ import contextlib
|
||||
|
||||
import mock
|
||||
import netaddr
|
||||
from neutron_lib.api.definitions import address_scope as apidef
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
@ -41,7 +42,7 @@ class AddressScopeTestExtensionManager(object):
|
||||
# initialize the main API router which extends
|
||||
# the global attribute map
|
||||
attr.RESOURCE_ATTRIBUTE_MAP.update(
|
||||
ext_address_scope.RESOURCE_ATTRIBUTE_MAP)
|
||||
apidef.RESOURCE_ATTRIBUTE_MAP)
|
||||
return ext_address_scope.Address_scope.get_resources()
|
||||
|
||||
def get_actions(self):
|
||||
@ -433,8 +434,8 @@ class TestSubnetPoolsWithAddressScopes(AddressScopeTestCase):
|
||||
def test_network_create_contain_address_scope_attr(self):
|
||||
with self.network() as network:
|
||||
result = self._show('networks', network['network']['id'])
|
||||
keys = [ext_address_scope.IPV4_ADDRESS_SCOPE,
|
||||
ext_address_scope.IPV6_ADDRESS_SCOPE]
|
||||
keys = [apidef.IPV4_ADDRESS_SCOPE,
|
||||
apidef.IPV6_ADDRESS_SCOPE]
|
||||
for k in keys:
|
||||
# Correlated address scopes should initially be None
|
||||
self.assertIsNone(result['network'][k])
|
||||
@ -471,10 +472,10 @@ class TestSubnetPoolsWithAddressScopes(AddressScopeTestCase):
|
||||
result = self._show('networks', network['network']['id'])
|
||||
self.assertEqual(
|
||||
v4_as_id,
|
||||
result['network'][ext_address_scope.IPV4_ADDRESS_SCOPE])
|
||||
result['network'][apidef.IPV4_ADDRESS_SCOPE])
|
||||
self.assertEqual(
|
||||
v6_as_id,
|
||||
result['network'][ext_address_scope.IPV6_ADDRESS_SCOPE])
|
||||
result['network'][apidef.IPV6_ADDRESS_SCOPE])
|
||||
|
||||
def test_delete_address_scope_in_use(self):
|
||||
with self.address_scope(name='foo-address-scope') as addr_scope:
|
||||
|
Loading…
Reference in New Issue
Block a user