Example #1
0
 def test_id_or_uuid(self):
     self.assertEqual((False, 123), uuid_utils.id_or_uuid(123))
     self.assertEqual((False, 123), uuid_utils.id_or_uuid('123'))
     self.assertEqual(
         (True, '12345678-abcd-ABCD-0000-0a1B2c3D4e5F'),
         uuid_utils.id_or_uuid('12345678-abcd-ABCD-0000-0a1B2c3D4e5F'))
     self.assertRaises(ValueError, uuid_utils.id_or_uuid,
                       '12345678abcdABCD00000a1B2c3D4e5F')
     # This one has too many digits
     self.assertRaises(ValueError, uuid_utils.id_or_uuid,
                       '12345678-abcd-ABCD-0000-0a1B2c3D4e5F0')
Example #2
0
 def test_id_or_uuid(self):
     self.assertEqual((False, 123), uuid_utils.id_or_uuid(123))
     self.assertEqual((False, 123), uuid_utils.id_or_uuid('123'))
     self.assertEqual(
         (True, '12345678-abcd-ABCD-0000-0a1B2c3D4e5F'),
         uuid_utils.id_or_uuid('12345678-abcd-ABCD-0000-0a1B2c3D4e5F'))
     self.assertRaises(ValueError, uuid_utils.id_or_uuid,
                       '12345678abcdABCD00000a1B2c3D4e5F')
     # This one has too many digits
     self.assertRaises(ValueError, uuid_utils.id_or_uuid,
                       '12345678-abcd-ABCD-0000-0a1B2c3D4e5F0')
Example #3
0
 def test_id_or_uuid(self):
     self.assertEqual((False, 123), uuid_utils.id_or_uuid(123))
     # Test all stringish permutations
     converters = [lambda x: x, six.text_type]
     for conv in converters:
         self.assertEqual((False, 123), uuid_utils.id_or_uuid(conv('123')))
         uuid = conv('12345678-abcd-ABCD-0000-0a1B2c3D4e5F')
         self.assertEqual((True, uuid), uuid_utils.id_or_uuid(uuid))
         uuid = conv('12345678abcdABCD00000a1B2c3D4e5F')
         self.assertEqual((True, uuid), uuid_utils.id_or_uuid(uuid))
         # This one has too many digits
         self.assertRaises(ValueError, uuid_utils.id_or_uuid,
                           conv('12345678-abcd-ABCD-0000-0a1B2c3D4e5F0'))
Example #4
0
def find_maps(mapping_list,
              client_lpar_id=None,
              match_func=None,
              stg_elem=None,
              include_orphans=False):
    """Filter a list of scsi mappings by LPAR ID/UUID and a matching function.

    :param mapping_list: The mappings to filter.  Iterable of VSCSIMapping.
    :param client_lpar_id: Integer short ID or string UUID of the LPAR on the
                           client side of the mapping.  Note that the UUID form
                           relies on the presence of the client_lpar_href
                           field.  Some mappings lack this field, and would
                           therefore be ignored. If client_lpar_id is not
                           passed it will return matching mappings for all
                           the lpar_ids.
    :param match_func: Callable with the following specification:

        def match_func(storage_elem)
            param storage_elem: A backing storage element wrapper (VOpt, VDisk,
                                PV, or LU) to be analyzed.  May be None (some
                                mappings have no backing storage).
            return: True if the storage_elem's mapping should be included;
                    False otherwise.

                       If neither match_func nor stg_elem is specified, the
                       default is to match everything - that is, find_maps will
                       return all mappings for the specified client_lpar_id.
                       It is illegal to specify both match_func and stg_elem.
    :param stg_elem: Match mappings associated with a specific storage element.
                     Effectively, this generates a default match_func which
                     matches on the type and name of the storage element.
                     If neither match_func nor stg_elem is specified, the
                     default is to match everything - that is, find_maps will
                     return all mappings for the specified client_lpar_id.
                     It is illegal to specify both match_func and stg_elem.
    :param include_orphans: An "orphan" contains a server adapter but no client
                            adapter.  If this parameter is True, mappings with
                            no client adapter will still be considered for
                            inclusion.  If False, mappings with no client
                            adapter will be skipped entirely, regardless of any
                            other criteria.
    :return: A list comprising the subset of the input mapping_list whose
             client LPAR IDs match client_lpar_id and whose backing storage
             elements satisfy match_func.
    :raise ValueError: If both match_func and stg_elem are specified.
    """
    if match_func and stg_elem:
        raise ValueError(_("Must not specify both match_func and stg_elem."))
    if not match_func:
        # Default no filter
        match_func = lambda x: True
    if stg_elem:
        # Match storage element on type and name
        match_func = lambda stg_el: (stg_el is not None and stg_el.schema_type
                                     == stg_elem.schema_type and stg_el.name ==
                                     stg_elem.name)

    is_uuid = False
    client_id = None
    if client_lpar_id:
        is_uuid, client_id = uuid.id_or_uuid(client_lpar_id)
    matching_maps = []
    for existing_scsi_map in mapping_list:
        # No client, continue on unless including orphans.
        if not include_orphans and existing_scsi_map.client_adapter is None:
            continue

        # If to a different VM, continue on.
        href = existing_scsi_map.client_lpar_href
        if is_uuid and (not href or client_id != util.get_req_path_uuid(
                href, preserve_case=True)):
            continue
        elif (client_lpar_id and not is_uuid and
              # Use the server adapter in case this is an orphan.
              existing_scsi_map.server_adapter.lpar_id != client_id):
            continue

        if match_func(existing_scsi_map.backing_storage):
            # Found a match!
            matching_maps.append(existing_scsi_map)
    return matching_maps
Example #5
0
def find_maps(mapping_list, client_lpar_id, client_adpt=None, port_map=None):
    """Filter a list of VFC mappings by LPAR ID.

    This is based on scsi_mapper.find_maps, but does not yet provide all the
    same functionality.

    :param mapping_list: The mappings to filter.  Iterable of VFCMapping.
    :param client_lpar_id: Integer short ID or string UUID of the LPAR on the
                           client side of the mapping.  Note that the UUID form
                           relies on the presence of the client_lpar_href
                           field.  Some mappings lack this field, and would
                           therefore be ignored.
    :param client_adpt: (Optional, Default=None) If set, will only include the
                        mapping if the client adapter's WWPNs match as well.
    :param port_map: (Optional, Default=None) If set, will look for a matching
                     mapping based off the client WWPNs as specified by the
                     port mapping.  The format of this is defined by the
                     derive_npiv_map method.
    :return: A list comprising the subset of the input mapping_list whose
             client LPAR IDs match client_lpar_id.
    """
    is_uuid, client_id = uuid.id_or_uuid(client_lpar_id)
    matching_maps = []

    if port_map:
        v_wwpns = [u.sanitize_wwpn_for_api(x) for x in port_map[1].split()]

    for vfc_map in mapping_list:
        # If to a different VM, continue on.
        href = vfc_map.client_lpar_href
        if is_uuid and (not href or client_id != u.get_req_path_uuid(
                href, preserve_case=True)):
            continue
        elif (not is_uuid and
                # Use the server adapter in case this is an orphan.
                vfc_map.server_adapter.lpar_id != client_id):
            continue

        # If there is a client adapter, and it is not a 'ANY WWPN', then
        # check to see if the mappings match.
        if client_adpt and client_adpt.wwpns != {_ANY_WWPN}:
            # If they passed in a client adapter, but the map doesn't have
            # one, then we have to ignore
            if not vfc_map.client_adapter:
                continue

            # Check to make sure the WWPNs between the two match.  This should
            # be an order independence check (as this query shouldn't care...
            # but the API itself does care about order).
            if set(client_adpt.wwpns) != set(vfc_map.client_adapter.wwpns):
                continue

        # If the user had a port map, do the virtual WWPNs from that port
        # map match the client adapter wwpn map.
        if port_map:
            if vfc_map.client_adapter is None:
                continue

            # If it is a new mapping with generated WWPNs, then the client
            # adapter can't have WWPNs.
            if v_wwpns == [_ANY_WWPN, _ANY_WWPN]:
                if vfc_map.client_adapter.wwpns != []:
                    continue
            elif set(vfc_map.client_adapter.wwpns) != set(v_wwpns):
                continue

        # Found a match!
        matching_maps.append(vfc_map)

    return matching_maps
Example #6
0
def find_maps(mapping_list, client_lpar_id=None, match_func=None,
              stg_elem=None, include_orphans=False):
    """Filter a list of scsi mappings by LPAR ID/UUID and a matching function.

    :param mapping_list: The mappings to filter.  Iterable of VSCSIMapping.
    :param client_lpar_id: Integer short ID or string UUID of the LPAR on the
                           client side of the mapping.  Note that the UUID form
                           relies on the presence of the client_lpar_href
                           field.  Some mappings lack this field, and would
                           therefore be ignored. If client_lpar_id is not
                           passed it will return matching mappings for all
                           the lpar_ids.
    :param match_func: Callable with the following specification:

        def match_func(storage_elem)
            param storage_elem: A backing storage element wrapper (VOpt, VDisk,
                                PV, or LU) to be analyzed.  May be None (some
                                mappings have no backing storage).
            return: True if the storage_elem's mapping should be included;
                    False otherwise.

                       If neither match_func nor stg_elem is specified, the
                       default is to match everything - that is, find_maps will
                       return all mappings for the specified client_lpar_id.
                       It is illegal to specify both match_func and stg_elem.
    :param stg_elem: Match mappings associated with a specific storage element.
                     Effectively, this generates a default match_func which
                     matches on the type and name of the storage element.
                     If neither match_func nor stg_elem is specified, the
                     default is to match everything - that is, find_maps will
                     return all mappings for the specified client_lpar_id.
                     It is illegal to specify both match_func and stg_elem.
    :param include_orphans: An "orphan" contains a server adapter but no client
                            adapter.  If this parameter is True, mappings with
                            no client adapter will still be considered for
                            inclusion.  If False, mappings with no client
                            adapter will be skipped entirely, regardless of any
                            other criteria.
    :return: A list comprising the subset of the input mapping_list whose
             client LPAR IDs match client_lpar_id and whose backing storage
             elements satisfy match_func.
    :raise ValueError: If both match_func and stg_elem are specified.
    """
    if match_func and stg_elem:
        raise ValueError(_("Must not specify both match_func and stg_elem."))
    if not match_func:
        # Default no filter
        match_func = lambda x: True
    if stg_elem:
        # Match storage element on type and name
        match_func = lambda stg_el: (
            stg_el is not None and
            stg_el.schema_type == stg_elem.schema_type and
            stg_el.name == stg_elem.name)

    is_uuid = False
    client_id = None
    if client_lpar_id:
        is_uuid, client_id = uuid.id_or_uuid(client_lpar_id)
    matching_maps = []
    for existing_scsi_map in mapping_list:
        # No client, continue on unless including orphans.
        if not include_orphans and existing_scsi_map.client_adapter is None:
            continue

        # If to a different VM, continue on.
        href = existing_scsi_map.client_lpar_href
        if is_uuid and (not href or client_id != util.get_req_path_uuid(
                href, preserve_case=True)):
            continue
        elif (client_lpar_id and not is_uuid and
                # Use the server adapter in case this is an orphan.
                existing_scsi_map.server_adapter.lpar_id != client_id):
            continue

        if match_func(existing_scsi_map.backing_storage):
            # Found a match!
            matching_maps.append(existing_scsi_map)
    return matching_maps