Esempio n. 1
0
    def _obj_make_obj_compatible(self, primitive, target_version, field):
        """Backlevel a sub-object based on our versioning rules.

        This is responsible for backporting objects contained within
        this object's primitive according to a set of rules we
        maintain about version dependencies between objects. This
        requires that the obj_relationships table in this object is
        correct and up-to-date.

        :param:primitive: The primitive version of this object
        :param:target_version: The version string requested for this object
        :param:field: The name of the field in this object containing the
                      sub-object to be backported
        """

        def _do_backport(to_version):
            obj = getattr(self, field)
            if not obj:
                return
            if isinstance(obj, CinderObject):
                obj.obj_make_compatible(
                    primitive[field]['cinder_object.data'],
                    to_version)
                primitive[field]['cinder_object.version'] = to_version
            elif isinstance(obj, list):
                for i, element in enumerate(obj):
                    element.obj_make_compatible(
                        primitive[field][i]['cinder_object.data'],
                        to_version)
                    primitive[field][i]['cinder_object.version'] = to_version

        target_version = utils.convert_version_to_tuple(target_version)
        for index, versions in enumerate(self.obj_relationships[field]):
            my_version, child_version = versions
            my_version = utils.convert_version_to_tuple(my_version)
            if target_version < my_version:
                if index == 0:
                    # We're backporting to a version from before this
                    # subobject was added: delete it from the primitive.
                    del primitive[field]
                else:
                    # We're in the gap between index-1 and index, so
                    # backport to the older version
                    last_child_version = \
                        self.obj_relationships[field][index - 1][1]
                    _do_backport(last_child_version)
                return
            elif target_version == my_version:
                # This is the first mapping that satisfies the
                # target_version request: backport the object.
                _do_backport(child_version)
                return
Esempio n. 2
0
    def _obj_make_obj_compatible(self, primitive, target_version, field):
        """Backlevel a sub-object based on our versioning rules.

        This is responsible for backporting objects contained within
        this object's primitive according to a set of rules we
        maintain about version dependencies between objects. This
        requires that the obj_relationships table in this object is
        correct and up-to-date.

        :param:primitive: The primitive version of this object
        :param:target_version: The version string requested for this object
        :param:field: The name of the field in this object containing the
                      sub-object to be backported
        """
        def _do_backport(to_version):
            obj = getattr(self, field)
            if not obj:
                return
            if isinstance(obj, CinderObject):
                obj.obj_make_compatible(primitive[field]['cinder_object.data'],
                                        to_version)
                primitive[field]['cinder_object.version'] = to_version
            elif isinstance(obj, list):
                for i, element in enumerate(obj):
                    element.obj_make_compatible(
                        primitive[field][i]['cinder_object.data'], to_version)
                    primitive[field][i]['cinder_object.version'] = to_version

        target_version = utils.convert_version_to_tuple(target_version)
        for index, versions in enumerate(self.obj_relationships[field]):
            my_version, child_version = versions
            my_version = utils.convert_version_to_tuple(my_version)
            if target_version < my_version:
                if index == 0:
                    # We're backporting to a version from before this
                    # subobject was added: delete it from the primitive.
                    del primitive[field]
                else:
                    # We're in the gap between index-1 and index, so
                    # backport to the older version
                    last_child_version = \
                        self.obj_relationships[field][index - 1][1]
                    _do_backport(last_child_version)
                return
            elif target_version == my_version:
                # This is the first mapping that satisfies the
                # target_version request: backport the object.
                _do_backport(child_version)
                return
Esempio n. 3
0
 def obj_make_compatible(self, primitive, target_version):
     """Make an object representation compatible with a target version."""
     super(Backup, self).obj_make_compatible(primitive, target_version)
     target_version = utils.convert_version_to_tuple(target_version)