예제 #1
0
    def obj_to_primitive(self, target_version=None, version_manifest=None):
        """Simple base-case dehydration.

        This calls to_primitive() for each item in fields.
        """
        if target_version is None:
            target_version = self.VERSION
        if (vutils.convert_version_to_tuple(target_version) >
                vutils.convert_version_to_tuple(self.VERSION)):
            raise exception.InvalidTargetVersion(version=target_version)
        primitive = dict()
        for name, field in self.fields.items():
            if self.obj_attr_is_set(name):
                primitive[name] = field.to_primitive(self, name,
                                                     getattr(self, name))
        # NOTE(danms): If we know we're being asked for a different version,
        # then do the compat step. However, even if we think we're not,
        # we may have sub-objects that need it, so if we have a manifest we
        # have to traverse this object just in case. Previously, we
        # required a parent version bump for any child, so the target
        # check was enough.
        if target_version != self.VERSION or version_manifest:
            self.obj_make_compatible_from_manifest(primitive,
                                                   target_version,
                                                   version_manifest)
        obj = {self._obj_primitive_key('name'): self.obj_name(),
               self._obj_primitive_key('namespace'): (
                   self.OBJ_PROJECT_NAMESPACE),
               self._obj_primitive_key('version'): target_version,
               self._obj_primitive_key('data'): primitive}
        if self.obj_what_changed():
            obj[self._obj_primitive_key('changes')] = list(
                self.obj_what_changed())
        return obj
예제 #2
0
파일: base.py 프로젝트: hanlind/nova
 def registration_hook(self, cls, index):
     # NOTE(danms): This is called when an object is registered,
     # and is responsible for maintaining nova.objects.$OBJECT
     # as the highest-versioned implementation of a given object.
     version = versionutils.convert_version_to_tuple(cls.VERSION)
     if not hasattr(objects, cls.obj_name()):
         setattr(objects, cls.obj_name(), cls)
     else:
         cur_version = versionutils.convert_version_to_tuple(getattr(objects, cls.obj_name()).VERSION)
         if version >= cur_version:
             setattr(objects, cls.obj_name(), cls)
예제 #3
0
    def _get_expected(self,
                      version=mv.get_prior_version(mv.REPLICATION_CLUSTER)):
        if (versionutils.convert_version_to_tuple(version) >=
                versionutils.convert_version_to_tuple(mv.REPLICATION_CLUSTER)):
            return EXPECTED

        expect = []
        for cluster in EXPECTED:
            cluster = cluster.copy()
            for key in ('replication_status', 'frozen', 'active_backend_id'):
                cluster.pop(key)
            expect.append(cluster)
        return expect
예제 #4
0
def _check_versions_compatibility(conf_version, actual_version):
    """Checks the configured version against the actual version.

    Returns True if the configured version is <= the actual version;
    otherwise returns False.

    :param conf_version: configured version, a string with dots
    :param actual_version: actual version, a string with dots
    :returns: True if the configured version is <= the actual version;
              False otherwise.
    """
    conf_cap = versionutils.convert_version_to_tuple(conf_version)
    actual_cap = versionutils.convert_version_to_tuple(actual_version)
    return conf_cap <= actual_cap
예제 #5
0
 def _test_relationships_in_order(self, obj_class):
     for field, versions in obj_class.obj_relationships.items():
         last_my_version = (0, 0)
         last_child_version = (0, 0)
         for my_version, child_version in versions:
             _my_version = vutils.convert_version_to_tuple(my_version)
             _ch_version = vutils.convert_version_to_tuple(child_version)
             assert (last_my_version < _my_version
                     and last_child_version <= _ch_version), \
                 ('Object %s relationship '
                  '%s->%s for field %s is out of order') % (
                      obj_class.obj_name(), my_version,
                      child_version, field)
             last_my_version = _my_version
             last_child_version = _ch_version
예제 #6
0
파일: base.py 프로젝트: openstack/kingbird
    def registration_hook(self, cls, index):
        """Callback for object registration.

        When an object is registered, this function will be called for
        maintaining kingbird.objects.$OBJECT as the highest-versioned
        implementation of a given object.
        """
        version = versionutils.convert_version_to_tuple(cls.VERSION)
        if not hasattr(objects, cls.obj_name()):
            setattr(objects, cls.obj_name(), cls)
        else:
            curr_version = versionutils.convert_version_to_tuple(
                getattr(objects, cls.obj_name()).VERSION)
            if version >= curr_version:
                setattr(objects, cls.obj_name(), cls)
예제 #7
0
    def obj_make_compatible(self, primitive, target_version):
        super(ImageMetaProps, self).obj_make_compatible(primitive,
                                                        target_version)
        target_version = versionutils.convert_version_to_tuple(target_version)
        if target_version < (1, 11):
            primitive.pop('hw_firmware_type', None)
        if target_version < (1, 9):
            primitive.pop('hw_cpu_thread_policy', None)
        if target_version < (1, 7):
            primitive.pop('img_config_drive', None)
        if target_version < (1, 5):
            primitive.pop('os_admin_user', None)
        if target_version < (1, 4):
            primitive.pop('hw_vif_multiqueue_enabled', None)
        if target_version < (1, 2):
            primitive.pop('img_hv_type', None)
            primitive.pop('img_hv_requested_version', None)
        if target_version < (1, 1):
            primitive.pop('os_require_quiesce', None)

        if target_version < (1, 6):
            bus = primitive.get('hw_disk_bus', None)
            if bus in ('lxc', 'uml'):
                raise exception.ObjectActionError(
                    action='obj_make_compatible',
                    reason='hw_disk_bus=%s not supported in version %s' % (
                        bus, target_version))
예제 #8
0
 def obj_make_compatible(self, primitive, target_version):
     """Make an object representation compatible with target version."""
     super(VolumeAttachment, self).obj_make_compatible(primitive,
                                                       target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 2):
         primitive.pop('connection_info', None)
예제 #9
0
 def obj_make_compatible(cls, primitive, target_version):
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 1):
         primitive.pop('old_pci_devices', None)
         primitive.pop('new_pci_devices', None)
         primitive.pop('old_pci_requests', None)
         primitive.pop('new_pci_requests', None)
예제 #10
0
파일: migration.py 프로젝트: lyarwood/nova
 def obj_make_compatible(self, primitive, target_version):
     super(Migration, self).obj_make_compatible(primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 2):
         if "migration_type" in primitive:
             del primitive["migration_type"]
             del primitive["hidden"]
예제 #11
0
    def _convert_to_version(self, target_version,
                            remove_unavailable_fields=True):
        """Convert to the target version.

        Convert the object to the target version. The target version may be
        the same, older, or newer than the version of the object. This is
        used for DB interactions as well as for serialization/deserialization.

        Version 1.4: if extra['vif_port_id'] is specified (non-null) and
            internal_info['tenant_vif_port_id'] is not specified, copy the
            .extra value to internal_info. There is nothing to do here when
            downgrading to an older version.

        :param target_version: the desired version of the object
        :param remove_unavailable_fields: True to remove fields that are
            unavailable in the target version; set this to True when
            (de)serializing. False to set the unavailable fields to appropriate
            values; set this to False for DB interactions.
        """
        target_version = versionutils.convert_version_to_tuple(target_version)
        if target_version >= (1, 4):
            if self.obj_attr_is_set('extra'):
                vif = self.extra.get('vif_port_id')
                if vif:
                    internal_info = (self.internal_info
                                     if self.obj_attr_is_set('internal_info')
                                     else {})
                    if 'tenant_vif_port_id' not in internal_info:
                        internal_info['tenant_vif_port_id'] = vif
                        self.internal_info = internal_info
예제 #12
0
 def obj_make_compatible(self, primitive, target_version):
     target_version = versionutils.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]['nova_object.data'], '1.0')
             primitive['requests'][index]['nova_object.version'] = '1.0'
예제 #13
0
    def obj_make_compatible(self, primitive, target_version):
        super(ImageMetaProps, self).obj_make_compatible(primitive, target_version)
        target_version = versionutils.convert_version_to_tuple(target_version)
        if target_version < (1, 11):
            primitive.pop("hw_firmware_type", None)
        if target_version < (1, 9):
            primitive.pop("hw_cpu_thread_policy", None)
        if target_version < (1, 7):
            primitive.pop("img_config_drive", None)
        if target_version < (1, 5):
            primitive.pop("os_admin_user", None)
        if target_version < (1, 4):
            primitive.pop("hw_vif_multiqueue_enabled", None)
        if target_version < (1, 2):
            primitive.pop("img_hv_type", None)
            primitive.pop("img_hv_requested_version", None)
        if target_version < (1, 1):
            primitive.pop("os_require_quiesce", None)

        if target_version < (1, 6):
            bus = primitive.get("hw_disk_bus", None)
            if bus in ("lxc", "uml"):
                raise exception.ObjectActionError(
                    action="obj_make_compatible",
                    reason="hw_disk_bus=%s not supported in version %s" % (bus, target_version),
                )
예제 #14
0
 def obj_make_compatible(self, primitive, target_version):
     super(ComputeNode, self).obj_make_compatible(primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 14):
         if 'ram_allocation_ratio' in primitive:
             del primitive['ram_allocation_ratio']
         if 'cpu_allocation_ratio' in primitive:
             del primitive['cpu_allocation_ratio']
     if target_version < (1, 13) and primitive.get('service_id') is None:
         # service_id is non-nullable in versions before 1.13
         try:
             service = objects.Service.get_by_compute_host(
                 self._context, primitive['host'])
             primitive['service_id'] = service.id
         except (exception.ComputeHostNotFound, KeyError):
             # NOTE(hanlind): In case anything goes wrong like service not
             # found or host not being set, catch and set a fake value just
             # to allow for older versions that demand a value to work.
             # Setting to -1 will, if value is later used result in a
             # ServiceNotFound, so should be safe.
             primitive['service_id'] = -1
     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']
예제 #15
0
파일: ports.py 프로젝트: igordcard/neutron
 def obj_make_compatible(self, primitive, target_version):
     _target_version = versionutils.convert_version_to_tuple(target_version)
     if _target_version < (1, 1):
         primitive.pop('data_plane_status', None)
     if _target_version < (1, 2):
         binding_levels = primitive.get('binding_levels', [])
         for lvl in binding_levels:
             lvl['versioned_object.version'] = '1.0'
             lvl['versioned_object.data'].pop('segment_id', None)
     if _target_version < (1, 3):
         bindings = primitive.pop('distributed_bindings', [])
         primitive['distributed_binding'] = (bindings[0]
                                             if bindings else None)
     if _target_version < (1, 4):
         # In version 1.4 we add support for multiple port bindings.
         # Previous versions only support one port binding. The following
         # lines look for the active port binding, which is the only one
         # needed in previous versions
         if 'bindings' in primitive:
             original_bindings = primitive.pop('bindings')
             primitive['binding'] = None
             for a_binding in original_bindings:
                 if (a_binding['versioned_object.data']['status'] ==
                         constants.ACTIVE):
                     primitive['binding'] = a_binding
                     break
예제 #16
0
    def obj_make_compatible(self, primitive, target_version):
        def filter_rules(obj_names, rules):
            return [rule for rule in rules if
                    rule['versioned_object.name'] in obj_names]

        _target_version = versionutils.convert_version_to_tuple(target_version)
        names = []
        if _target_version >= (1, 0):
            names.append(rule_obj_impl.QosBandwidthLimitRule.obj_name())
        if _target_version >= (1, 1):
            names.append(rule_obj_impl.QosDscpMarkingRule.obj_name())
        if 'rules' in primitive and names:
            primitive['rules'] = filter_rules(names, primitive['rules'])

        if _target_version < (1, 3):
            standard_fields = ['revision_number', 'created_at', 'updated_at']
            for f in standard_fields:
                primitive.pop(f)
            if primitive['description'] is None:
                # description was not nullable before
                raise exception.IncompatibleObjectVersion(
                    objver=target_version, objname='QoSPolicy')

        if _target_version < (1, 4):
            primitive['tenant_id'] = primitive.pop('project_id')
예제 #17
0
 def obj_make_compatible(self, primitive, target_version):
     super(LibvirtLiveMigrateData, self).obj_make_compatible(
         primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 9) and 'vifs' in primitive:
         del primitive['vifs']
     if target_version < (1, 8):
         if 'file_backed_memory_discard' in primitive:
             del primitive['file_backed_memory_discard']
     if target_version < (1, 7):
         if 'dst_wants_file_backed_memory' in primitive:
             del primitive['dst_wants_file_backed_memory']
     if target_version < (1, 6) and 'wait_for_vif_plugged' in primitive:
         del primitive['wait_for_vif_plugged']
     if target_version < (1, 5):
         if 'src_supports_native_luks' in primitive:
             del primitive['src_supports_native_luks']
     if target_version < (1, 4):
         if 'old_vol_attachment_ids' in primitive:
             del primitive['old_vol_attachment_ids']
     if target_version < (1, 3):
         if 'supported_perf_events' in primitive:
             del primitive['supported_perf_events']
     if target_version < (1, 2):
         if 'serial_listen_ports' in primitive:
             del primitive['serial_listen_ports']
     if target_version < (1, 1) and 'target_connect_addr' in primitive:
         del primitive['target_connect_addr']
예제 #18
0
 def obj_make_compatible(self, primitive, target_version):
     super(XenapiLiveMigrateData, self).obj_make_compatible(
         primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 1):
         if 'vif_uuid_map' in primitive:
             del primitive['vif_uuid_map']
예제 #19
0
 def obj_make_compatible(self, primitive, target_version):
     super(HyperVLiveMigrateData, self).obj_make_compatible(
         primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 1):
         if 'is_shared_instance_path' in primitive:
             del primitive['is_shared_instance_path']
예제 #20
0
 def obj_make_compatible(self, primitive, target_version):
     super(PowerVMLiveMigrateData, self).obj_make_compatible(
         primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 1):
         if 'vea_vlan_mappings' in primitive:
             del primitive['vea_vlan_mappings']
예제 #21
0
    def _get_capped_obj_version(self, obj):
        objname = obj.obj_name()
        version_dict = OBJ_VERSIONS.get(self.version_cap, {})
        version_cap = version_dict.get(objname, None)

        if version_cap:
            cap_tuple = versionutils.convert_version_to_tuple(version_cap)
            obj_tuple = versionutils.convert_version_to_tuple(obj.VERSION)
            if cap_tuple > obj_tuple:
                # NOTE(dulek): Do not set version cap to be higher than actual
                # object version as we don't support "forwardporting" of
                # objects. If service will receive an object that's too old it
                # should handle it explicitly.
                version_cap = None

        return version_cap
예제 #22
0
 def obj_make_compatible(self, primitive, target_version):
     super(InstanceMapping, self).obj_make_compatible(primitive,
                                                      target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 1):
         if 'queued_for_delete' in primitive:
             del primitive['queued_for_delete']
예제 #23
0
 def obj_make_compatible(self, primitive, target_version):
     super(InstanceNUMACell, self).obj_make_compatible(primitive,
                                                     target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 3):
         primitive.pop('cpu_policy', None)
         primitive.pop('cpu_thread_policy', None)
예제 #24
0
    def _convert_to_version(self, target_version,
                            remove_unavailable_fields=True):
        """Convert to the target version.

        Convert the object to the target version. The target version may be
        the same, older, or newer than the version of the object. This is
        used for DB interactions as well as for serialization/deserialization.

        Version 1.22: rescue_interface field was added. Its default value is
            None. For versions prior to this, it should be set to None (or
            removed).
        Version 1.23: traits field was added. Its default value is
            None. For versions prior to this, it should be set to None (or
            removed).
        Version 1.24: bios_interface field was added. Its default value is
            None. For versions prior to this, it should be set to None (or
            removed).
        Version 1.25: fault field was added. For versions prior to
            this, it should be removed.
        Version 1.26: deploy_step field was added. For versions prior to
            this, it should be removed.
        Version 1.27: conductor_group field was added. For versions prior to
            this, it should be removed.
        Version 1.28: automated_clean was added. For versions prior to this, it
            should be set to None (or removed).
        Version 1.29: protected was added. For versions prior to this, it
            should be set to False (or removed).
        Version 1.30: owner was added. For versions prior to this, it should be
            set to None or removed.
        Version 1.31: allocation_id was added. For versions prior to this, it
            should be set to None (or removed).
        Version 1.32: description was added. For versions prior to this, it
            should be set to None (or removed).

        :param target_version: the desired version of the object
        :param remove_unavailable_fields: True to remove fields that are
            unavailable in the target version; set this to True when
            (de)serializing. False to set the unavailable fields to appropriate
            values; set this to False for DB interactions.
        """
        target_version = versionutils.convert_version_to_tuple(target_version)

        # Convert the different fields depending on version
        fields = [('rescue_interface', 22), ('traits', 23),
                  ('bios_interface', 24), ('fault', 25),
                  ('automated_clean', 28), ('protected_reason', 29),
                  ('owner', 30), ('allocation_id', 31), ('description', 32)]
        for name, minor in fields:
            self._adjust_field_to_version(name, None, target_version,
                                          1, minor, remove_unavailable_fields)

        # NOTE(dtantsur): the default is False for protected
        self._adjust_field_to_version('protected', False, target_version,
                                      1, 29, remove_unavailable_fields)

        self._convert_deploy_step_field(target_version,
                                        remove_unavailable_fields)
        self._convert_conductor_group_field(target_version,
                                            remove_unavailable_fields)
예제 #25
0
 def obj_make_compatible(self, primitive, target_version):
     super(InstancePCIRequest, self).obj_make_compatible(primitive,
                                                         target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 2) and 'numa_policy' in primitive:
         del primitive['numa_policy']
     if target_version < (1, 1) and 'request_id' in primitive:
         del primitive['request_id']
예제 #26
0
파일: build_request.py 프로젝트: sapcc/nova
 def obj_make_compatible(self, primitive, target_version):
     super(BuildRequest, self).obj_make_compatible(primitive,
                                                   target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 1) and 'block_device_mappings' in primitive:
         del primitive['block_device_mappings']
     elif target_version < (1, 3) and 'tags' in primitive:
         del primitive['tags']
예제 #27
0
 def obj_make_compatible(self, primitive, target_version):
     super(ChildObject, self).obj_make_compatible(primitive,
                                                  target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 1):
         primitive.pop('text', None)
     if target_version < (1, 2):
         primitive.pop('integer', None)
예제 #28
0
파일: rule.py 프로젝트: eayunstack/neutron
 def obj_make_compatible(self, primitive, target_version):
     _target_version = versionutils.convert_version_to_tuple(target_version)
     if _target_version < (1, 3) and 'direction' in primitive:
         direction = primitive.pop('direction')
         if direction == constants.INGRESS_DIRECTION:
             raise exception.IncompatibleObjectVersion(
                 objver=target_version,
                 objtype="QosBandwidthLimitRule")
예제 #29
0
    def obj_make_compatible(self, primitive, target_version):
        """Make an object representation compatible with a target version."""
        super(Snapshot, self).obj_make_compatible(primitive, target_version)
        target_version = versionutils.convert_version_to_tuple(target_version)

        if target_version < (1, 3):
            if primitive.get('status') == c_fields.SnapshotStatus.UNMANAGING:
                primitive['status'] = c_fields.SnapshotStatus.DELETING
예제 #30
0
파일: policy.py 프로젝트: klmitch/neutron
 def obj_make_compatible(self, primitive, target_version):
     _target_version = versionutils.convert_version_to_tuple(target_version)
     if _target_version < (1, 1):
         if "rules" in primitive:
             bw_obj_name = rule_obj_impl.QosBandwidthLimitRule.obj_name()
             primitive["rules"] = filter(
                 lambda rule: (rule["versioned_object.name"] == bw_obj_name), primitive["rules"]
             )
예제 #31
0
 def obj_make_compatible(self, primitive, target_version):
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 11):
         # NOTE(yikun): Before 1.11, we had a policies property which is
         # the list of policy name, even though it was a list, there was
         # ever only one entry in the list.
         policy = primitive.pop('policy', None)
         if policy:
             primitive['policies'] = [policy]
         else:
             primitive['policies'] = []
         primitive.pop('rules', None)
     if target_version < (1, 7):
         # NOTE(danms): Before 1.7, we had an always-empty
         # metadetails property
         primitive['metadetails'] = {}
예제 #32
0
    def obj_make_compatible(self, primitive, target_version):
        def filter_rules(obj_names, rules):
            return [
                rule for rule in rules
                if rule['versioned_object.name'] in obj_names
            ]

        def filter_ingress_bandwidth_limit_rules(rules):
            bwlimit_obj_name = rule_obj_impl.QosBandwidthLimitRule.obj_name()
            filtered_rules = []
            for rule in rules:
                if rule['versioned_object.name'] == bwlimit_obj_name:
                    direction = rule['versioned_object.data'].get("direction")
                    if direction == n_const.EGRESS_DIRECTION:
                        rule['versioned_object.data'].pop('direction')
                        filtered_rules.append(rule)
                else:
                    filtered_rules.append(rule)
            return filtered_rules

        _target_version = versionutils.convert_version_to_tuple(target_version)
        names = []
        if _target_version >= (1, 0):
            names.append(rule_obj_impl.QosBandwidthLimitRule.obj_name())
        if _target_version >= (1, 1):
            names.append(rule_obj_impl.QosDscpMarkingRule.obj_name())
        if _target_version >= (1, 2):
            names.append(rule_obj_impl.QosMinimumBandwidthRule.obj_name())
        if 'rules' in primitive and names:
            primitive['rules'] = filter_rules(names, primitive['rules'])

        if _target_version < (1, 3):
            standard_fields = ['revision_number', 'created_at', 'updated_at']
            for f in standard_fields:
                primitive.pop(f)
            if primitive['description'] is None:
                # description was not nullable before
                raise exception.IncompatibleObjectVersion(
                    objver=target_version, objname='QoSPolicy')

        if _target_version < (1, 4):
            primitive['tenant_id'] = primitive.pop('project_id')

        if _target_version < (1, 5):
            if 'rules' in primitive:
                primitive['rules'] = filter_ingress_bandwidth_limit_rules(
                    primitive['rules'])
예제 #33
0
    def obj_make_compatible(self, primitive, target_version):
        super(InstanceNUMACell,
              self).obj_make_compatible(primitive, target_version)
        target_version = versionutils.convert_version_to_tuple(target_version)
        if target_version < (1, 4):
            primitive.pop('cpuset_reserved', None)

        if target_version < (1, 3):
            primitive.pop('cpu_policy', None)
            primitive.pop('cpu_thread_policy', None)
        # NOTE(jgauld): R4 to R5 upgrades, Pike upversion to 1.4. Drop L3
        #               related fields with R4/Newton.
        if target_version < (1, 4) or CONF.upgrade_levels.compute == 'newton':
            primitive.pop('l3_cpuset', None)
            primitive.pop('l3_both_size', None)
            primitive.pop('l3_code_size', None)
            primitive.pop('l3_data_size', None)
예제 #34
0
    def obj_make_compatible(self, primitive, target_version):
        _target_version = versionutils.convert_version_to_tuple(target_version)

        def filter_remote_address_group_id_from_rules(rules):
            sg_rule = SecurityGroupRule()
            for rule in rules:
                sg_rule.obj_make_compatible(rule['versioned_object.data'],
                                            '1.0')
                rule['versioned_object.version'] = '1.0'

        if _target_version < (1, 1):
            primitive.pop('shared')
        if _target_version < (1, 2):
            primitive.pop('stateful')
        if _target_version < (1, 3):
            if 'rules' in primitive:
                filter_remote_address_group_id_from_rules(primitive['rules'])
예제 #35
0
 def obj_make_compatible_from_manifest(self, primitive, target_version,
                                       version_manifest):
     super(Service,
           self).obj_make_compatible_from_manifest(primitive,
                                                   target_version,
                                                   version_manifest)
     _target_version = versionutils.convert_version_to_tuple(target_version)
     if _target_version < (1, 16) and 'version' in primitive:
         del primitive['version']
     if _target_version < (1, 14) and 'forced_down' in primitive:
         del primitive['forced_down']
     if _target_version < (1, 13) and 'last_seen_up' in primitive:
         del primitive['last_seen_up']
     if _target_version < (1, 10):
         # service.compute_node was not lazy-loaded, we need to provide it
         # when called
         self._do_compute_node(self._context, primitive, version_manifest)
예제 #36
0
파일: node.py 프로젝트: tmaleeva/ironic
    def _convert_to_version(self, target_version,
                            remove_unavailable_fields=True):
        """Convert to the target version.

        Convert the object to the target version. The target version may be
        the same, older, or newer than the version of the object. This is
        used for DB interactions as well as for serialization/deserialization.

        Version 1.22: rescue_interface field was added. Its default value is
            None. For versions prior to this, it should be set to None (or
            removed).
        Version 1.23: traits field was added. Its default value is
            None. For versions prior to this, it should be set to None (or
            removed).
        Version 1.24: bios_interface field was added. Its default value is
            None. For versions prior to this, it should be set to None (or
            removed).
        Version 1.25: fault field was added. For versions prior to
            this, it should be removed.
        Version 1.26: deploy_step field was added. For versions prior to
            this, it should be removed.
        Version 1.27: conductor_group field was added. For versions prior to
            this, it should be removed.
        Version 1.28: automated_clean was added. For versions prior to this, it
            should be set to None (or removed).

        :param target_version: the desired version of the object
        :param remove_unavailable_fields: True to remove fields that are
            unavailable in the target version; set this to True when
            (de)serializing. False to set the unavailable fields to appropriate
            values; set this to False for DB interactions.
        """
        target_version = versionutils.convert_version_to_tuple(target_version)

        # Convert the different fields depending on version
        fields = [('rescue_interface', 22), ('traits', 23),
                  ('bios_interface', 24), ('automated_clean', 28)]
        for name, minor in fields:
            self._adjust_field_to_version(name, None, target_version,
                                          1, minor, remove_unavailable_fields)

        self._convert_fault_field(target_version, remove_unavailable_fields)
        self._convert_deploy_step_field(target_version,
                                        remove_unavailable_fields)
        self._convert_conductor_group_field(target_version,
                                            remove_unavailable_fields)
예제 #37
0
파일: policy.py 프로젝트: zhhuabj/neutron
 def obj_make_compatible(self, primitive, target_version):
     def filter_rules(obj_names, rules):
         return [rule for rule in rules if
                 rule['versioned_object.name'] in obj_names]
     _target_version = versionutils.convert_version_to_tuple(target_version)
     if _target_version < (1, 8):
         raise exception.IncompatibleObjectVersion(
             objver=target_version, objname=self.__class__.__name__)
     names = [
         rule_obj_impl.QosBandwidthLimitRule.obj_name(),
         rule_obj_impl.QosDscpMarkingRule.obj_name(),
         rule_obj_impl.QosMinimumBandwidthRule.obj_name(),
     ]
     if _target_version >= (1, 9):
         names.append(rule_obj_impl.QosPacketRateLimitRule.obj_name())
     if 'rules' in primitive and names:
         primitive['rules'] = filter_rules(names, primitive['rules'])
예제 #38
0
파일: image_meta.py 프로젝트: zsvic/nova
    def obj_make_compatible(self, primitive, target_version):
        super(ImageMetaProps,
              self).obj_make_compatible(primitive, target_version)
        target_version = versionutils.convert_version_to_tuple(target_version)
        if target_version < (1, 20):
            primitive.pop('traits_required', None)
        if target_version < (1, 19):
            primitive.pop('img_hide_hypervisor_id', None)
        if target_version < (1, 16) and 'hw_watchdog_action' in primitive:
            # Check to see if hw_watchdog_action was set to 'disabled' and if
            # so, remove it since not specifying it is the same behavior.
            if primitive['hw_watchdog_action'] == \
                    fields.WatchdogAction.DISABLED:
                primitive.pop('hw_watchdog_action')
        if target_version < (1, 15):
            primitive.pop('hw_rescue_bus', None)
            primitive.pop('hw_rescue_device', None)
        if target_version < (1, 14):
            primitive.pop('hw_pointer_model', None)
        if target_version < (1, 13):
            primitive.pop('os_secure_boot', None)
        if target_version < (1, 11):
            primitive.pop('hw_firmware_type', None)
        if target_version < (1, 10):
            primitive.pop('hw_cpu_realtime_mask', None)
        if target_version < (1, 9):
            primitive.pop('hw_cpu_thread_policy', None)
        if target_version < (1, 7):
            primitive.pop('img_config_drive', None)
        if target_version < (1, 5):
            primitive.pop('os_admin_user', None)
        if target_version < (1, 4):
            primitive.pop('hw_vif_multiqueue_enabled', None)
        if target_version < (1, 2):
            primitive.pop('img_hv_type', None)
            primitive.pop('img_hv_requested_version', None)
        if target_version < (1, 1):
            primitive.pop('os_require_quiesce', None)

        if target_version < (1, 6):
            bus = primitive.get('hw_disk_bus', None)
            if bus in ('lxc', 'uml'):
                raise exception.ObjectActionError(
                    action='obj_make_compatible',
                    reason='hw_disk_bus=%s not supported in version %s' %
                    (bus, target_version))
예제 #39
0
파일: api.py 프로젝트: suman-d/cinder
    def _is_scalable_only(self):
        """True if we're running in deployment where all c-bak are scalable.

        We need this method to decide if we can assume that all of our c-bak
        services are decoupled from c-vol.

        FIXME(dulek): This shouldn't be needed in Newton.
        """
        cap = self.backup_rpcapi.client.version_cap
        if cap:
            cap = versionutils.convert_version_to_tuple(cap)
            return cap >= (1, 3)  # Mitaka is marked by c-bak 1.3+.
        else:
            # NOTE(dulek): No version cap means we're running in an environment
            # without c-bak services. Letting it pass as Mitaka, request will
            # just fail anyway so it doesn't really matter.
            return True
예제 #40
0
 def obj_make_compatible(self, primitive, target_version):
     super(RequestSpec, self).obj_make_compatible(primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 11) and 'is_bfv' in primitive:
         del primitive['is_bfv']
     if target_version < (1, 10):
         if 'network_metadata' in primitive:
             del primitive['network_metadata']
     if target_version < (1, 9):
         if 'user_id' in primitive:
             del primitive['user_id']
     if target_version < (1, 8):
         if 'security_groups' in primitive:
             del primitive['security_groups']
     if target_version < (1, 6):
         if 'requested_destination' in primitive:
             del primitive['requested_destination']
예제 #41
0
 def obj_make_compatible(self, primitive, target_version):
     super(ComputeNode, self).obj_make_compatible(primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     # NOTE(jgauld): R4 to R5 upgrades, Pike upversion to 1.18. Drop L3
     #               related fields.
     if target_version < (1, 18) or CONF.upgrade_levels.compute == 'newton':
         if 'l3_closids' in primitive:
             del primitive['l3_closids']
         if 'l3_closids_used' in primitive:
             del primitive['l3_closids_used']
     if target_version < (1, 17):
         if 'mapped' in primitive:
             del primitive['mapped']
     if target_version < (1, 16):
         if 'disk_allocation_ratio' in primitive:
             del primitive['disk_allocation_ratio']
     if target_version < (1, 15):
         if 'uuid' in primitive:
             del primitive['uuid']
     if target_version < (1, 14):
         if 'ram_allocation_ratio' in primitive:
             del primitive['ram_allocation_ratio']
         if 'cpu_allocation_ratio' in primitive:
             del primitive['cpu_allocation_ratio']
     if target_version < (1, 13) and primitive.get('service_id') is None:
         # service_id is non-nullable in versions before 1.13
         try:
             service = objects.Service.get_by_compute_host(
                 self._context, primitive['host'])
             primitive['service_id'] = service.id
         except (exception.ComputeHostNotFound, KeyError):
             # NOTE(hanlind): In case anything goes wrong like service not
             # found or host not being set, catch and set a fake value just
             # to allow for older versions that demand a value to work.
             # Setting to -1 will, if value is later used result in a
             # ServiceNotFound, so should be safe.
             primitive['service_id'] = -1
     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']
예제 #42
0
파일: migrate_data.py 프로젝트: zsvic/nova
 def obj_make_compatible(self, primitive, target_version):
     super(LibvirtLiveMigrateData,
           self).obj_make_compatible(primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 5):
         if 'src_supports_native_luks' in primitive:
             del primitive['src_supports_native_luks']
     if target_version < (1, 4):
         if 'old_vol_attachment_ids' in primitive:
             del primitive['old_vol_attachment_ids']
     if target_version < (1, 3):
         if 'supported_perf_events' in primitive:
             del primitive['supported_perf_events']
     if target_version < (1, 2):
         if 'serial_listen_ports' in primitive:
             del primitive['serial_listen_ports']
     if target_version < (1, 1) and 'target_connect_addr' in primitive:
         del primitive['target_connect_addr']
예제 #43
0
    def obj_make_compatible(self, primitive, target_version):
        """Make an object representation compatible with a target version."""
        super(Snapshot, self).obj_make_compatible(primitive, target_version)
        target_version = versionutils.convert_version_to_tuple(target_version)

        backport_statuses = (((1, 3),
                              (c_fields.SnapshotStatus.UNMANAGING,
                               c_fields.SnapshotStatus.DELETING)),
                             ((1, 4),
                             (c_fields.SnapshotStatus.BACKING_UP,
                              c_fields.SnapshotStatus.AVAILABLE)),
                             ((1, 5),
                              (c_fields.SnapshotStatus.RESTORING,
                               c_fields.SnapshotStatus.AVAILABLE)))
        for version, status in backport_statuses:
            if target_version < version:
                if primitive.get('status') == status[0]:
                    primitive['status'] = status[1]
예제 #44
0
 def obj_make_compatible(self, primitive, target_version):
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 2) and 'request_id' in primitive:
         del primitive['request_id']
     if target_version < (1, 4) and 'parent_addr' in primitive:
         if primitive['parent_addr'] is not None:
             extra_info = primitive.get('extra_info', {})
             extra_info['phys_function'] = primitive['parent_addr']
         del primitive['parent_addr']
     if target_version < (1, 5) and 'parent_addr' in primitive:
         added_statuses = (fields.PciDeviceStatus.UNCLAIMABLE,
                           fields.PciDeviceStatus.UNAVAILABLE)
         status = primitive['status']
         if status in added_statuses:
             raise exception.ObjectActionError(
                 action='obj_make_compatible',
                 reason='status=%s not supported in version %s' %
                 (status, target_version))
예제 #45
0
 def obj_make_compatible(self, primitive, target_version):
     super(Migration, self).obj_make_compatible(primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 2):
         if 'migration_type' in primitive:
             del primitive['migration_type']
             del primitive['hidden']
     if target_version < (1, 4):
         if 'memory_total' in primitive:
             del primitive['memory_total']
             del primitive['memory_processed']
             del primitive['memory_remaining']
             del primitive['disk_total']
             del primitive['disk_processed']
             del primitive['disk_remaining']
     if target_version < (1, 5):
         if 'uuid' in primitive:
             del primitive['uuid']
예제 #46
0
파일: session.py 프로젝트: thewayonly/nova
    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 = versionutils.convert_version_to_tuple(
            product_version_str)

        return product_version, product_brand
예제 #47
0
파일: checks.py 프로젝트: stackhpc/neutron
def _get_ovn_version(check_type):
    if check_type in (OVNCheckType.nb_version, OVNCheckType.nb_db_schema):
        cmd = ['ovn-nbctl', '--version']
    elif check_type in (OVNCheckType.nb_version, OVNCheckType.nb_db_schema):
        cmd = ['ovn-sbctl', '--version']
    else:
        raise RuntimeError

    out = agent_utils.execute(cmd)
    if check_type == OVNCheckType.nb_version:
        matched_line = re.search(r"ovn-nbctl.*", out)
    elif check_type == OVNCheckType.sb_version:
        matched_line = re.search(r"ovn-sbctl.*", out)
    else:
        matched_line = re.search(r"DB Schema.*", out)

    matched_version = re.search(r"(\d+\.\d+)", matched_line.group(0))
    return versionutils.convert_version_to_tuple(matched_version.group(1) if
                                                 matched_version else '0.0')
예제 #48
0
 def obj_make_compatible(self, primitive, target_version):
     super(FlavorPayload, self).obj_make_compatible(primitive,
                                                    target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 1):
         primitive.pop('name', None)
         primitive.pop('swap', None)
         primitive.pop('rxtx_factor', None)
         primitive.pop('vcpu_weight', None)
         primitive.pop('disabled', None)
         primitive.pop('is_public', None)
     if target_version < (1, 2):
         primitive.pop('extra_specs', None)
         primitive.pop('projects', None)
     if target_version < (1, 3):
         if 'projects' not in primitive or primitive['projects'] is None:
             primitive['projects'] = []
         if ('extra_specs' not in primitive or
                 primitive['extra_specs'] is None):
             primitive['extra_specs'] = {}
예제 #49
0
    def get_octavia_version(self):
        lbaas = clients.get_loadbalancer_client()
        region_name = getattr(CONF.neutron, 'region_name', None)

        regions = lbaas.get_all_version_data()
        # If region was specified take it, otherwise just take first as default
        endpoints = regions.get(region_name, list(regions.values())[0])
        # Take the first endpoint
        services = list(endpoints.values())[0]
        # Try load-balancer service, if not take the first
        versions = services.get('load-balancer', list(services.values())[0])
        # Lookup the latest version. For safety, we won't look for
        # version['status'] == 'CURRENT' and assume it's the maximum. Also we
        # won't assume this dict is sorted.
        max_ver = 0, 0
        for version in versions:
            v_tuple = versionutils.convert_version_to_tuple(version['version'])
            if v_tuple > max_ver:
                max_ver = v_tuple

        LOG.debug("Detected Octavia version %d.%d", *max_ver)
        return max_ver
예제 #50
0
    def obj_make_compatible(self, primitive, target_version):
        def filter_rules(obj_names, rules):
            return filter(
                lambda rule: (rule['versioned_object.name'] in obj_names),
                rules)

        _target_version = versionutils.convert_version_to_tuple(target_version)
        names = []
        if _target_version >= (1, 0):
            names.append(rule_obj_impl.QosBandwidthLimitRule.obj_name())
        if _target_version >= (1, 1):
            names.append(rule_obj_impl.QosDscpMarkingRule.obj_name())
        if 'rules' in primitive and names:
            primitive['rules'] = filter_rules(names, primitive['rules'])

        if _target_version < (1, 3):
            standard_fields = ['revision_number', 'created_at', 'updated_at']
            for f in standard_fields:
                primitive.pop(f)
            if primitive['description'] is None:
                # description was not nullable before
                raise exception.IncompatibleObjectVersion(
                    objver=target_version, objname='QoSPolicy')
예제 #51
0
파일: image_meta.py 프로젝트: punituee/nova
    def obj_make_compatible(self, primitive, target_version):
        super(ImageMetaProps,
              self).obj_make_compatible(primitive, target_version)
        target_version = versionutils.convert_version_to_tuple(target_version)
        if target_version < (1, 7):
            primitive.pop('img_config_drive', None)
        if target_version < (1, 5):
            primitive.pop('os_admin_user', None)
        if target_version < (1, 4):
            primitive.pop('hw_vif_multiqueue_enabled', None)
        if target_version < (1, 2):
            primitive.pop('img_hv_type', None)
            primitive.pop('img_hv_requested_version', None)
        if target_version < (1, 1):
            primitive.pop('os_require_quiesce', None)

        if target_version < (1, 6):
            bus = primitive.get('hw_disk_bus', None)
            if bus in ('lxc', 'uml'):
                raise exception.ObjectActionError(
                    action='obj_make_compatible',
                    reason='hw_disk_bus=%s not supported in version %s' %
                    (bus, target_version))
예제 #52
0
    def obj_make_compatible(self, primitive, target_version):
        super(ImageMetaProps,
              self).obj_make_compatible(primitive, target_version)
        target_version = versionutils.convert_version_to_tuple(target_version)
        if target_version < (1, 15):
            primitive.pop('hw_rescue_bus', None)
            primitive.pop('hw_rescue_device', None)
        if target_version < (1, 14):
            primitive.pop('hw_pointer_model', None)
        if target_version < (1, 13):
            primitive.pop('os_secure_boot', None)
        if target_version < (1, 11):
            primitive.pop('hw_firmware_type', None)
        if target_version < (1, 10):
            primitive.pop('hw_cpu_realtime_mask', None)
        if target_version < (1, 9):
            primitive.pop('hw_cpu_thread_policy', None)
        if target_version < (1, 7):
            primitive.pop('img_config_drive', None)
        if target_version < (1, 5):
            primitive.pop('os_admin_user', None)
        if target_version < (1, 4):
            primitive.pop('hw_vif_multiqueue_enabled', None)
        if target_version < (1, 2):
            primitive.pop('img_hv_type', None)
            primitive.pop('img_hv_requested_version', None)
        if target_version < (1, 1):
            primitive.pop('os_require_quiesce', None)

        if target_version < (1, 6):
            bus = primitive.get('hw_disk_bus', None)
            if bus in ('lxc', 'uml'):
                raise exception.ObjectActionError(
                    action='obj_make_compatible',
                    reason='hw_disk_bus=%s not supported in version %s' %
                    (bus, target_version))
예제 #53
0
 def obj_make_compatible(self, primitive, target_version):
     super(LibvirtLiveMigrateData,
           self).obj_make_compatible(primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if (target_version < (1, 10)
             and 'src_supports_numa_live_migration' in primitive):
         del primitive['src_supports_numa_live_migration']
     if (target_version < (1, 10)
             and 'dst_supports_numa_live_migration' in primitive):
         del primitive['dst_supports_numa_live_migration']
     if target_version < (1, 10) and 'dst_numa_info' in primitive:
         del primitive['dst_numa_info']
     if target_version < (1, 9) and 'vifs' in primitive:
         del primitive['vifs']
     if target_version < (1, 8):
         if 'file_backed_memory_discard' in primitive:
             del primitive['file_backed_memory_discard']
     if target_version < (1, 7):
         if 'dst_wants_file_backed_memory' in primitive:
             del primitive['dst_wants_file_backed_memory']
     if target_version < (1, 6) and 'wait_for_vif_plugged' in primitive:
         del primitive['wait_for_vif_plugged']
     if target_version < (1, 5):
         if 'src_supports_native_luks' in primitive:
             del primitive['src_supports_native_luks']
     if target_version < (1, 4):
         if 'old_vol_attachment_ids' in primitive:
             del primitive['old_vol_attachment_ids']
     if target_version < (1, 3):
         if 'supported_perf_events' in primitive:
             del primitive['supported_perf_events']
     if target_version < (1, 2):
         if 'serial_listen_ports' in primitive:
             del primitive['serial_listen_ports']
     if target_version < (1, 1) and 'target_connect_addr' in primitive:
         del primitive['target_connect_addr']
예제 #54
0
 def obj_make_compatible(self, primitive, target_version):
     """Make an object representation compatible with a target version."""
     super(Volume, self).obj_make_compatible(primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
예제 #55
0
 def obj_make_compatible(self, primitive, target_version):
     super(InstanceNUMATopology,
           self).obj_make_compatible(primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 3):
         primitive.pop('emulator_threads_policy', None)
예제 #56
0
    def obj_make_compatible(self, primitive, target_version):
        _target_version = versionutils.convert_version_to_tuple(target_version)

        if _target_version < (1, 1):
            primitive.pop('data_plane_status', None)
예제 #57
0
 def obj_make_compatible(self, primitive, target_version):
     _target_version = versionutils.convert_version_to_tuple(target_version)
     if _target_version < (1, 1):
         primitive.pop('dns_domain', None)
예제 #58
0
파일: rule.py 프로젝트: rohitmalaga/neutron
 def obj_make_compatible(self, primitive, target_version):
     _target_version = versionutils.convert_version_to_tuple(target_version)
     if _target_version < (1, 2):
         raise exception.IncompatibleObjectVersion(
             objver=target_version, objname="QosMinimumBandwidthRule")
예제 #59
0
파일: rule.py 프로젝트: rohitmalaga/neutron
 def obj_make_compatible(self, primitive, target_version):
     _target_version = versionutils.convert_version_to_tuple(target_version)
     if _target_version < (1, 1):
         raise exception.IncompatibleObjectVersion(
             objver=target_version, objname="QosDscpMarkingRule")
예제 #60
0
 def obj_make_compatible(self, primitive, target_version):
     super(Destination, self).obj_make_compatible(primitive, target_version)
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 1):
         if 'cell' in primitive:
             del primitive['cell']