Пример #1
0
    def obj_calculate_child_version(self, target_version, child):
        """Calculate the appropriate version for a child object.

        This is to be used when backporting an object for an older client.
        A sub-object will need to be backported to a suitable version for
        the client as well, and this method will calculate what that
        version should be, based on obj_relationships.

        :param target_version: Version this object is being backported to
        :param child: The child field for which the appropriate version
                      is to be calculated
        :returns: None if the child should be omitted from the backport,
                  otherwise, the version to which the child should be
                  backported
        """
        target_version = utils.convert_version_to_tuple(target_version)
        for index, versions in enumerate(self.obj_relationships[child]):
            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.
                    return None
                else:
                    # We're in the gap between index-1 and index, so
                    # backport to the older version
                    return self.obj_relationships[child][index - 1][1]
            elif target_version == my_version:
                # This is the first mapping that satisfies the
                # target_version request: backport the object.
                return child_version
        # No need to backport, as far as we know, so return the latest
        # version of the sub-object we know about
        return self.obj_relationships[child][-1][1]
Пример #2
0
    def obj_calculate_child_version(self, target_version, child):
        """Calculate the appropriate version for a child object.

        This is to be used when backporting an object for an older client.
        A sub-object will need to be backported to a suitable version for
        the client as well, and this method will calculate what that
        version should be, based on obj_relationships.

        :param target_version: Version this object is being backported to
        :param child: The child field for which the appropriate version
                      is to be calculated
        :returns: None if the child should be omitted from the backport,
                  otherwise, the version to which the child should be
                  backported
        """
        target_version = utils.convert_version_to_tuple(target_version)
        for index, versions in enumerate(self.obj_relationships[child]):
            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.
                    return None
                else:
                    # We're in the gap between index-1 and index, so
                    # backport to the older version
                    return self.obj_relationships[child][index - 1][1]
            elif target_version == my_version:
                # This is the first mapping that satisfies the
                # target_version request: backport the object.
                return child_version
        # No need to backport, as far as we know, so return the latest
        # version of the sub-object we know about
        return self.obj_relationships[child][-1][1]
Пример #3
0
 def obj_make_compatible(self, primitive, target_version):
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 1) and 'requests' in primitive:
         for index, request in enumerate(self.requests):
             request.obj_make_compatible(
                 primitive['requests'][index]['patron_object.data'], '1.0')
             primitive['requests'][index]['patron_object.version'] = '1.0'
Пример #4
0
 def obj_make_compatible(self, primitive, target_version):
     _target_version = utils.convert_version_to_tuple(target_version)
     if _target_version < (1, 10):
         target_compute_version = self.obj_calculate_child_version(
             target_version, 'compute_node')
         # service.compute_node was not lazy-loaded, we need to provide it
         # when called
         self._do_compute_node(self._context, primitive,
                               target_compute_version)
     super(Service, self).obj_make_compatible(primitive, target_version)
Пример #5
0
 def obj_make_compatible(self, primitive, target_version):
     _target_version = utils.convert_version_to_tuple(target_version)
     if _target_version < (1, 10):
         target_compute_version = self.obj_calculate_child_version(
             target_version, 'compute_node')
         # service.compute_node was not lazy-loaded, we need to provide it
         # when called
         self._do_compute_node(self._context, primitive,
                               target_compute_version)
     super(Service, self).obj_make_compatible(primitive, target_version)
Пример #6
0
 def obj_make_compatible(self, primitive, target_version):
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 2):
         if 'mtu' in primitive:
             del primitive['mtu']
         if 'enable_dhcp' in primitive:
             del primitive['enable_dhcp']
         if 'dhcp_server' in primitive:
             del primitive['dhcp_server']
         if 'share_address' in primitive:
             del primitive['share_address']
Пример #7
0
 def obj_make_compatible(self, primitive, target_version):
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 2):
         if 'mtu' in primitive:
             del primitive['mtu']
         if 'enable_dhcp' in primitive:
             del primitive['enable_dhcp']
         if 'dhcp_server' in primitive:
             del primitive['dhcp_server']
         if 'share_address' in primitive:
             del primitive['share_address']
Пример #8
0
 def obj_make_compatible(self, primitive, target_version):
     super(ComputeNode, self).obj_make_compatible(primitive, target_version)
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 7) and 'host' in primitive:
         del primitive['host']
     if target_version < (1, 5) and 'numa_topology' in primitive:
         del primitive['numa_topology']
     if target_version < (1, 4) and 'host_ip' in primitive:
         del primitive['host_ip']
     if target_version < (1, 3) and 'stats' in primitive:
         # pre 1.3 version does not have a stats field
         del primitive['stats']
Пример #9
0
 def obj_make_compatible(self, primitive, target_version):
     super(ComputeNode, self).obj_make_compatible(primitive, target_version)
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 7) and 'host' in primitive:
         del primitive['host']
     if target_version < (1, 5) and 'numa_topology' in primitive:
         del primitive['numa_topology']
     if target_version < (1, 4) and 'host_ip' in primitive:
         del primitive['host_ip']
     if target_version < (1, 3) and 'stats' in primitive:
         # pre 1.3 version does not have a stats field
         del primitive['stats']
Пример #10
0
    def _get_product_version_and_brand(self):
        """Return a tuple of (major, minor, rev) for the host version and
        a string of the product brand.
        """
        software_version = self._get_software_version()

        product_version_str = software_version.get('product_version')
        # Product version is only set in some cases (e.g. XCP, XenServer) and
        # not in others (e.g. xenserver-core, XAPI-XCP).
        # In these cases, the platform version is the best number to use.
        if product_version_str is None:
            product_version_str = software_version.get('platform_version',
                                                       '0.0.0')
        product_brand = software_version.get('product_brand')
        product_version = utils.convert_version_to_tuple(product_version_str)

        return product_version, product_brand
Пример #11
0
 def test_convert_version_to_tuple(self):
     self.assertEqual(utils.convert_version_to_tuple('6.7.0'), (6, 7, 0))
Пример #12
0
 def test_convert_version_to_tuple(self):
     self.assertEqual(utils.convert_version_to_tuple('6.7.0'), (6, 7, 0))
Пример #13
0
 def obj_make_compatible(self, primitive, target_version):
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 2) and 'request_id' in primitive:
         del primitive['request_id']
Пример #14
0
 def obj_make_compatible(self, primitive, target_version):
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 7):
         # NOTE(danms): Before 1.7, we had an always-empty
         # metadetails property
         primitive['metadetails'] = {}
Пример #15
0
 def obj_make_compatible(self, primitive, target_version):
     super(KeyPair, self).obj_make_compatible(primitive, target_version)
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 2) and 'type' in primitive:
         del primitive['type']
Пример #16
0
 def obj_make_compatible(self, primitive, target_version):
     super(FixedIP, self).obj_make_compatible(primitive, target_version)
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 4) and 'default_route' in primitive:
         del primitive['default_route']
Пример #17
0
 def obj_make_compatible(self, primitive, target_version):
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 1) and 'numa_node' in primitive:
         del primitive['numa_node']
Пример #18
0
 def obj_make_compatible(self, primitive, target_version):
     super(KeyPair, self).obj_make_compatible(primitive, target_version)
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 2) and 'type' in primitive:
         del primitive['type']