예제 #1
0
파일: base.py 프로젝트: hsluoyz/patron
    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
파일: base.py 프로젝트: 2Exception/patron
    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
파일: service.py 프로젝트: hsluoyz/patron
 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
파일: network.py 프로젝트: hsluoyz/patron
 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
파일: keypair.py 프로젝트: hsluoyz/patron
 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']