diff --git a/lower-constraints.txt b/lower-constraints.txt index a7b386f2c..84b185838 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -70,6 +70,7 @@ os-resource-classes==0.1.0 os-service-types==1.2.0 os-testr==1.0.0 os-traits==0.15.0 +os-vif==1.15.1 os-win==4.0.0 osc-lib==1.10.0 oslo.cache==1.29.0 diff --git a/requirements.txt b/requirements.txt index 9ca669593..6b9447979 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,6 +29,7 @@ oslo.upgradecheck>=0.1.0 # Apache-2.0 os-brick>=2.2.0 # Apache-2.0 os-resource-classes>=0.1.0 # Apache-2.0 os-traits>=0.15.0 # Apache-2.0 +os-vif>=1.15.1 # Apache-2.0 six>=1.10.0 # MIT SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.0.10 # MIT stevedore>=1.20.0 # Apache-2.0 diff --git a/zun/objects/__init__.py b/zun/objects/__init__.py index 233514af5..8cd250d5a 100644 --- a/zun/objects/__init__.py +++ b/zun/objects/__init__.py @@ -25,6 +25,7 @@ from zun.objects import registry from zun.objects import request_group from zun.objects import resource_class from zun.objects import resource_provider +from zun.objects import vif from zun.objects import volume from zun.objects import volume_mapping from zun.objects import zun_network @@ -56,6 +57,7 @@ ContainerActionEvent = container_action.ContainerActionEvent ExecInstance = exec_instance.ExecInstance Registry = registry.Registry RequestGroup = request_group.RequestGroup +VIFState = vif.VIFState __all__ = ( 'Container', @@ -82,4 +84,5 @@ __all__ = ( 'ExecInstance', 'Registry', 'RequestGroup', + 'VIFState', ) diff --git a/zun/objects/fields.py b/zun/objects/fields.py index 298014a15..c1e4dff76 100644 --- a/zun/objects/fields.py +++ b/zun/objects/fields.py @@ -10,10 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -import six - +from os_vif.objects import vif from oslo_serialization import jsonutils as json from oslo_versionedobjects import fields +import six from zun.common import consts @@ -132,3 +132,8 @@ class PciDeviceTypeField(fields.BaseEnumField): class PciDeviceStatusField(fields.BaseEnumField): AUTO_TYPE = PciDeviceStatus() + + +class DictOfVIFsField(fields.AutoTypedField): + AUTO_TYPE = fields.Dict(fields.Object(vif.VIFBase.__name__, + subclasses=True)) diff --git a/zun/objects/vif.py b/zun/objects/vif.py new file mode 100644 index 000000000..23743143a --- /dev/null +++ b/zun/objects/vif.py @@ -0,0 +1,45 @@ +# 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 os_vif.objects import vif as obj_osvif +from oslo_versionedobjects import fields as obj_fields + +from zun.common import consts +from zun.objects import base +from zun.objects import fields as zun_fields + + +@base.ZunObjectRegistry.register +class VIFState(base.ZunObject): + # Version 1.0: Initial version + VERSION = '1.0' + + # FIXME(dulek): I know it's an ugly hack, but turns out you cannot + # serialize-deserialize objects containing objects from + # different namespaces, so we need 'os_vif' namespace here. + OBJ_PROJECT_NAMESPACE = 'os_vif' + OBJ_SERIAL_NAMESPACE = 'versioned_object' + + fields = { + 'default_vif': obj_fields.ObjectField(obj_osvif.VIFBase.__name__, + subclasses=True, nullable=False), + 'additional_vifs': zun_fields.DictOfVIFsField(default={}), + } + + @property + def vifs(self): + d = { + consts.DEFAULT_IFNAME: self.default_vif, + } + if self.obj_attr_is_set('additional_vifs'): + d.update(self.additional_vifs) + return d diff --git a/zun/tests/unit/objects/test_objects.py b/zun/tests/unit/objects/test_objects.py index 2ee2f0ff4..f4a5aeae2 100644 --- a/zun/tests/unit/objects/test_objects.py +++ b/zun/tests/unit/objects/test_objects.py @@ -380,8 +380,14 @@ class TestObjectVersions(test_base.TestCase): # Test the versions of current objects with the static tree above. # This ensures that any incompatible object changes require a version # bump. - classes = base.ZunObjectRegistry.obj_classes() - checker = fixture.ObjectVersionChecker(obj_classes=classes) + all_classes = base.ZunObjectRegistry.obj_classes() + zun_classes = {} + for name in all_classes: + objclasses = all_classes[name] + if (objclasses[0].OBJ_PROJECT_NAMESPACE == + base.ZunObject.OBJ_PROJECT_NAMESPACE): + zun_classes[name] = objclasses + checker = fixture.ObjectVersionChecker(obj_classes=zun_classes) expected, actual = checker.test_hashes(object_data) self.assertEqual(expected, actual,