diff --git a/neutron/objects/plugins/ml2/base.py b/neutron/objects/plugins/ml2/base.py new file mode 100644 index 00000000000..3a4d6088300 --- /dev/null +++ b/neutron/objects/plugins/ml2/base.py @@ -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 diff --git a/neutron/objects/plugins/ml2/geneveallocation.py b/neutron/objects/plugins/ml2/geneveallocation.py new file mode 100644 index 00000000000..4d91bfdb49f --- /dev/null +++ b/neutron/objects/plugins/ml2/geneveallocation.py @@ -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), + } diff --git a/neutron/objects/plugins/ml2/greallocation.py b/neutron/objects/plugins/ml2/greallocation.py new file mode 100644 index 00000000000..cb12bc5fa4b --- /dev/null +++ b/neutron/objects/plugins/ml2/greallocation.py @@ -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) + } diff --git a/neutron/objects/plugins/ml2/vxlanallocation.py b/neutron/objects/plugins/ml2/vxlanallocation.py new file mode 100644 index 00000000000..cdb74398bd7 --- /dev/null +++ b/neutron/objects/plugins/ml2/vxlanallocation.py @@ -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), + } diff --git a/neutron/tests/unit/objects/plugins/ml2/test_geneveallocation.py b/neutron/tests/unit/objects/plugins/ml2/test_geneveallocation.py new file mode 100644 index 00000000000..2ca836c2824 --- /dev/null +++ b/neutron/tests/unit/objects/plugins/ml2/test_geneveallocation.py @@ -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 diff --git a/neutron/tests/unit/objects/plugins/ml2/test_greallocation.py b/neutron/tests/unit/objects/plugins/ml2/test_greallocation.py new file mode 100644 index 00000000000..d56ac5f467f --- /dev/null +++ b/neutron/tests/unit/objects/plugins/ml2/test_greallocation.py @@ -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 diff --git a/neutron/tests/unit/objects/plugins/ml2/test_vxlanallocation.py b/neutron/tests/unit/objects/plugins/ml2/test_vxlanallocation.py new file mode 100644 index 00000000000..ceb343139a6 --- /dev/null +++ b/neutron/tests/unit/objects/plugins/ml2/test_vxlanallocation.py @@ -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 diff --git a/neutron/tests/unit/objects/test_objects.py b/neutron/tests/unit/objects/test_objects.py index dbc4d14bbd6..b54f6ef49c8 100644 --- a/neutron/tests/unit/objects/test_objects.py +++ b/neutron/tests/unit/objects/test_objects.py @@ -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', }