OVO for VlanAllocation
This patch introduces OVO for VlanAllocation. SegmentTypeDriver integration will be required during the integration of this patch, therefore it will be handled in I0d592bae452876b24c28ca4cc4bf6392b5ab6493 Change-Id: I8ad7e74ec74bf91b2cdf9d8aed231074ef252e71 Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
This commit is contained in:
parent
f448cccabb
commit
640618b6c3
|
@ -23,6 +23,7 @@ from neutron._i18n import _
|
|||
from neutron.common import constants
|
||||
from neutron.extensions import dns as dns_ext
|
||||
from neutron.objects import exceptions as o_exc
|
||||
from neutron.plugins.common import constants as plugin_constants
|
||||
|
||||
|
||||
class IPV6ModeEnumField(obj_fields.AutoTypedField):
|
||||
|
@ -71,6 +72,17 @@ class PortRangeField(obj_fields.AutoTypedField):
|
|||
AUTO_TYPE = PortRange()
|
||||
|
||||
|
||||
class VlanIdRange(RangeConstrainedInteger):
|
||||
def __init__(self, **kwargs):
|
||||
super(VlanIdRange, self).__init__(start=plugin_constants.MIN_VLAN_TAG,
|
||||
end=plugin_constants.MAX_VLAN_TAG,
|
||||
**kwargs)
|
||||
|
||||
|
||||
class VlanIdRangeField(obj_fields.AutoTypedField):
|
||||
AUTO_TYPE = VlanIdRange()
|
||||
|
||||
|
||||
class ListOfIPNetworksField(obj_fields.AutoTypedField):
|
||||
AUTO_TYPE = obj_fields.List(obj_fields.IPNetwork())
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
# Copyright (c) 2016 Intel Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_versionedobjects import base as obj_base
|
||||
from oslo_versionedobjects import fields as obj_fields
|
||||
|
||||
from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model
|
||||
from neutron.objects import base
|
||||
from neutron.objects import common_types
|
||||
|
||||
|
||||
@obj_base.VersionedObjectRegistry.register
|
||||
class VlanAllocation(base.NeutronDbObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
|
||||
db_model = vlan_alloc_model.VlanAllocation
|
||||
|
||||
fields = {
|
||||
'physical_network': obj_fields.StringField(),
|
||||
'vlan_id': common_types.VlanIdRangeField(),
|
||||
'allocated': obj_fields.BooleanField(),
|
||||
}
|
||||
|
||||
primary_keys = ['physical_network', 'vlan_id']
|
|
@ -35,6 +35,7 @@ import unittest2
|
|||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.db import common_db_mixin
|
||||
from neutron.plugins.common import constants as p_const
|
||||
|
||||
|
||||
class AttributeMapMemento(fixtures.Fixture):
|
||||
|
@ -242,6 +243,10 @@ def get_random_port():
|
|||
return random.randint(n_const.PORT_RANGE_MIN, n_const.PORT_RANGE_MAX)
|
||||
|
||||
|
||||
def get_random_vlan():
|
||||
return random.randint(p_const.MIN_VLAN_TAG, p_const.MAX_VLAN_TAG)
|
||||
|
||||
|
||||
def get_random_ip_version():
|
||||
return random.choice(n_const.IP_ALLOWED_VERSIONS)
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
# Copyright (c) 2016 Intel Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.objects.plugins.ml2 import vlanallocation
|
||||
from neutron.tests.unit.objects import test_base
|
||||
from neutron.tests.unit import testlib_api
|
||||
|
||||
|
||||
class VlanAllocationIfaceObjTestCase(test_base.BaseObjectIfaceTestCase):
|
||||
|
||||
_test_class = vlanallocation.VlanAllocation
|
||||
|
||||
|
||||
class VlanAllocationDbObjTestCase(test_base.BaseDbObjectTestCase,
|
||||
testlib_api.SqlTestCase):
|
||||
|
||||
_test_class = vlanallocation.VlanAllocation
|
|
@ -420,6 +420,7 @@ FIELD_TYPE_VALUE_GENERATOR_MAP = {
|
|||
common_types.IpProtocolEnumField: tools.get_random_ip_protocol,
|
||||
common_types.PortRangeField: tools.get_random_port,
|
||||
common_types.SetOfUUIDsField: get_set_of_random_uuids,
|
||||
common_types.VlanIdRangeField: tools.get_random_vlan,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ object_data = {
|
|||
'SubnetServiceType': '1.0-05ae4cdb2a9026a697b143926a1add8c',
|
||||
'SubPort': '1.0-72c8471068db1f0491b5480fe49b52bb',
|
||||
'Trunk': '1.0-80ebebb57f2b0dbb510f84d91421ed10',
|
||||
'VlanAllocation': '1.0-72636c1b7d5c8eef987bd09666e64f3e',
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue