OVO for Allocation and Endpoint

This patch introduces Oslo-Versioned Objects for VxlanAllocation,
VxlanEndpoint, GeneveAllocation, GeneveEndpoint, GreAllocation and
GreEndpoint.

Change-Id: I473386077ac6328ac232942d79eef8713d14cef1
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
Co-Authored-By: John Woodburn <john.l.woodburn@intel.com>
Co-Authored-By: Sindhu Devale <sindhu.devale@intel.com>
Co-Authored-By: Mohit Malik<mohit.malik@intel.com>
Co-Authored-By: Anindita Das<anindita.das@intel.com>
Co-Authored-By: Nakul Dahiwade<nakul.dahiwade@intel.com>
This commit is contained in:
Victor Morales 2016-11-10 11:01:32 -06:00
parent 920ddeaf58
commit 2baeaeac8e
8 changed files with 304 additions and 0 deletions

View File

@ -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.
import netaddr
from neutron.objects import base
class EndpointBase(base.NeutronDbObject):
primary_keys = ['ip_address']
@classmethod
def modify_fields_from_db(cls, db_obj):
result = super(EndpointBase, cls).modify_fields_from_db(db_obj)
if 'ip_address' in result:
result['ip_address'] = netaddr.IPAddress(result['ip_address'])
return result
@classmethod
def modify_fields_to_db(cls, fields):
result = super(EndpointBase, cls).modify_fields_to_db(fields)
if 'ip_address' in fields:
result['ip_address'] = cls.filter_to_str(result['ip_address'])
return result

View File

@ -0,0 +1,48 @@
# 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 geneveallocation
from neutron.objects import base
from neutron.objects.plugins.ml2 import base as ml2_base
@obj_base.VersionedObjectRegistry.register
class GeneveAllocation(base.NeutronDbObject):
# Version 1.0: Initial version
VERSION = '1.0'
db_model = geneveallocation.GeneveAllocation
primary_keys = ['geneve_vni']
fields = {
'geneve_vni': obj_fields.IntegerField(),
'allocated': obj_fields.BooleanField(default=False),
}
@obj_base.VersionedObjectRegistry.register
class GeneveEndpoint(ml2_base.EndpointBase):
# Version 1.0: Initial version
VERSION = '1.0'
db_model = geneveallocation.GeneveEndpoints
fields = {
'ip_address': obj_fields.IPAddressField(),
'host': obj_fields.StringField(nullable=True),
}

View File

@ -0,0 +1,48 @@
# 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 gre_allocation_endpoints as gre_model
from neutron.objects import base
from neutron.objects.plugins.ml2 import base as ml2_base
@obj_base.VersionedObjectRegistry.register
class GreAllocation(base.NeutronDbObject):
# Version 1.0: Initial version
VERSION = '1.0'
db_model = gre_model.GreAllocation
primary_keys = ['gre_id']
fields = {
'gre_id': obj_fields.IntegerField(),
'allocated': obj_fields.BooleanField(default=False)
}
@obj_base.VersionedObjectRegistry.register
class GreEndpoint(ml2_base.EndpointBase):
# Version 1.0: Initial version
VERSION = '1.0'
db_model = gre_model.GreEndpoints
fields = {
'ip_address': obj_fields.IPAddressField(),
'host': obj_fields.StringField(nullable=True)
}

View File

@ -0,0 +1,50 @@
# 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 vxlanallocation as vxlan_model
from neutron.objects import base
from neutron.objects import common_types
from neutron.objects.plugins.ml2 import base as ml2_base
@obj_base.VersionedObjectRegistry.register
class VxlanAllocation(base.NeutronDbObject):
# Version 1.0: Initial version
VERSION = '1.0'
db_model = vxlan_model.VxlanAllocation
primary_keys = ['vxlan_vni']
fields = {
'vxlan_vni': obj_fields.IntegerField(),
'allocated': obj_fields.BooleanField(default=False),
}
@obj_base.VersionedObjectRegistry.register
class VxlanEndpoint(ml2_base.EndpointBase):
# Version 1.0: Initial version
VERSION = '1.0'
db_model = vxlan_model.VxlanEndpoints
fields = {
'ip_address': obj_fields.IPAddressField(),
'udp_port': common_types.PortRangeField(),
'host': obj_fields.StringField(nullable=True),
}

View File

@ -0,0 +1,38 @@
# 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 geneveallocation
from neutron.tests.unit.objects import test_base
from neutron.tests.unit import testlib_api
class GeneveAllocationIfaceObjTestCase(test_base.BaseObjectIfaceTestCase):
_test_class = geneveallocation.GeneveAllocation
class GeneveAllocationDbObjTestCase(test_base.BaseDbObjectTestCase,
testlib_api.SqlTestCase):
_test_class = geneveallocation.GeneveAllocation
class GeneveEndpointIfaceObjTestCase(test_base.BaseObjectIfaceTestCase):
_test_class = geneveallocation.GeneveEndpoint
class GeneveEndpointDbObjTestCase(test_base.BaseDbObjectTestCase,
testlib_api.SqlTestCase):
_test_class = geneveallocation.GeneveEndpoint

View File

@ -0,0 +1,39 @@
# 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 greallocation as gre_object
from neutron.tests.unit.objects import test_base
from neutron.tests.unit import testlib_api
class GreAllocationIfaceObjTestCase(test_base.BaseObjectIfaceTestCase):
_test_class = gre_object.GreAllocation
class GreAllocationDbObjTestCase(test_base.BaseDbObjectTestCase,
testlib_api.SqlTestCase):
_test_class = gre_object.GreAllocation
class GreEndpointIfaceObjTestCase(test_base.BaseObjectIfaceTestCase):
_test_class = gre_object.GreEndpoint
class GreEndpointDbObjTestCase(test_base.BaseDbObjectTestCase,
testlib_api.SqlTestCase):
_test_class = gre_object.GreEndpoint

View File

@ -0,0 +1,39 @@
# 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 vxlanallocation as vxlan_obj
from neutron.tests.unit.objects import test_base
from neutron.tests.unit import testlib_api
class VxlanAllocationIfaceObjTestCase(test_base.BaseObjectIfaceTestCase):
_test_class = vxlan_obj.VxlanAllocation
class VxlanAllocationDbObjTestCase(test_base.BaseDbObjectTestCase,
testlib_api.SqlTestCase):
_test_class = vxlan_obj.VxlanAllocation
class VxlanEndpointIfaceObjTestCase(test_base.BaseObjectIfaceTestCase):
_test_class = vxlan_obj.VxlanEndpoint
class VxlanEndpointDbObjTestCase(test_base.BaseDbObjectTestCase,
testlib_api.SqlTestCase):
_test_class = vxlan_obj.VxlanEndpoint

View File

@ -35,6 +35,10 @@ object_data = {
'DNSNameServer': '1.0-bf87a85327e2d812d1666ede99d9918b',
'ExtraDhcpOpt': '1.0-632f689cbeb36328995a7aed1d0a78d3',
'FloatingIPDNS': '1.0-ee3db848500fa1825235f701828c06d5',
'GeneveAllocation': '1.0-d5f76e8eac60a778914d61dd8e23e90f',
'GeneveEndpoint': '1.0-040f026996b5952e2ae4ccd40ac61ca6',
'GreAllocation': '1.0-9ee1bbc4d999bea84c99425484b11ac5',
'GreEndpoint': '1.0-040f026996b5952e2ae4ccd40ac61ca6',
'IPAllocation': '1.0-47251b4c6d45c3b5feb0297fe5c461f2',
'IPAllocationPool': '1.0-371016a6480ed0b4299319cb46d9215d',
'Network': '1.0-f2f6308f79731a767b92b26b0f4f3849',
@ -66,6 +70,8 @@ object_data = {
'SubPort': '1.0-72c8471068db1f0491b5480fe49b52bb',
'Trunk': '1.0-80ebebb57f2b0dbb510f84d91421ed10',
'VlanAllocation': '1.0-72636c1b7d5c8eef987bd09666e64f3e',
'VxlanAllocation': '1.0-934638cd32d00f81d6fbf93c8eb5755a',
'VxlanEndpoint': '1.0-40522eafdcf838758711dfa886cbdb2e',
}