def find_candidate_devs(probe_optical=True, dslist=None):
    """Return a list of devices that may contain the config drive.

    The returned list is sorted by search order where the first item has
    should be searched first (highest priority)

    config drive v1:
       Per documentation, this is "associated as the last available disk on the
       instance", and should be VFAT.
       Currently, we do not restrict search list to "last available disk"

    config drive v2:
       Disk should be:
        * either vfat or iso9660 formated
        * labeled with 'config-2' or 'CONFIG-2'
    """
    if dslist is None:
        dslist = []

    # query optical drive to get it in blkid cache for 2.6 kernels
    if probe_optical:
        for device in OPTICAL_DEVICES:
            try:
                util.find_devs_with(path=device)
            except util.ProcessExecutionError:
                pass

    by_fstype = []
    for fs_type in FS_TYPES:
        by_fstype.extend(util.find_devs_with("TYPE=%s" % (fs_type)))

    by_label = []
    for label in LABEL_TYPES:
        by_label.extend(util.find_devs_with("LABEL=%s" % (label)))

    # give preference to "last available disk" (vdb over vda)
    # note, this is not a perfect rendition of that.
    by_fstype.sort(reverse=True)
    by_label.sort(reverse=True)

    # combine list of items by putting by-label items first
    # followed by fstype items, but with dupes removed
    candidates = (by_label + [d for d in by_fstype if d not in by_label])

    # We are looking for a block device or partition with necessary label or
    # an unpartitioned block device (ex sda, not sda1)
    devices = [
        d for d in candidates if d in by_label or not util.is_partition(d)
    ]

    LOG.debug("devices=%s dslist=%s", devices, dslist)
    if devices and "IBMCloud" in dslist:
        # IBMCloud uses config-2 label, but limited to a single UUID.
        ibm_platform, ibm_path = get_ibm_platform()
        if ibm_path in devices:
            devices.remove(ibm_path)
            LOG.debug("IBMCloud device '%s' (%s) removed from candidate list",
                      ibm_path, ibm_platform)

    return devices
def find_candidate_devs(probe_optical=True, dslist=None):
    """Return a list of devices that may contain the config drive.

    The returned list is sorted by search order where the first item has
    should be searched first (highest priority)

    config drive v1:
       Per documentation, this is "associated as the last available disk on the
       instance", and should be VFAT.
       Currently, we do not restrict search list to "last available disk"

    config drive v2:
       Disk should be:
        * either vfat or iso9660 formated
        * labeled with 'config-2' or 'CONFIG-2'
    """
    if dslist is None:
        dslist = []

    # query optical drive to get it in blkid cache for 2.6 kernels
    if probe_optical:
        for device in OPTICAL_DEVICES:
            try:
                util.find_devs_with(path=device)
            except util.ProcessExecutionError:
                pass

    by_fstype = []
    for fs_type in FS_TYPES:
        by_fstype.extend(util.find_devs_with("TYPE=%s" % (fs_type)))

    by_label = []
    for label in LABEL_TYPES:
        by_label.extend(util.find_devs_with("LABEL=%s" % (label)))

    # give preference to "last available disk" (vdb over vda)
    # note, this is not a perfect rendition of that.
    by_fstype.sort(reverse=True)
    by_label.sort(reverse=True)

    # combine list of items by putting by-label items first
    # followed by fstype items, but with dupes removed
    candidates = (by_label + [d for d in by_fstype if d not in by_label])

    # We are looking for a block device or partition with necessary label or
    # an unpartitioned block device (ex sda, not sda1)
    devices = [d for d in candidates
               if d in by_label or not util.is_partition(d)]

    LOG.debug("devices=%s dslist=%s", devices, dslist)
    if devices and "IBMCloud" in dslist:
        # IBMCloud uses config-2 label, but limited to a single UUID.
        ibm_platform, ibm_path = get_ibm_platform()
        if ibm_path in devices:
            devices.remove(ibm_path)
            LOG.debug("IBMCloud device '%s' (%s) removed from candidate list",
                      ibm_path, ibm_platform)

    return devices
def find_candidate_devs():
    """Return a list of devices that may contain the config drive.

    The returned list is sorted by search order where the first item has
    should be searched first (highest priority)

    config drive v1:
       Per documentation, this is "associated as the last available disk on the
       instance", and should be VFAT.
       Currently, we do not restrict search list to "last available disk"

    config drive v2:
       Disk should be:
        * either vfat or iso9660 formated
        * labeled with 'config-2'
    """

    # Query optical drive to get it in blkid cache for 2.6 kernels
    util.find_devs_with(path="/dev/sr0")
    util.find_devs_with(path="/dev/sr1")

    by_fstype = (util.find_devs_with("TYPE=vfat") +
                 util.find_devs_with("TYPE=iso9660"))
    by_label = util.find_devs_with("LABEL=config-2")

    # give preference to "last available disk" (vdb over vda)
    # note, this is not a perfect rendition of that.
    by_fstype.sort(reverse=True)
    by_label.sort(reverse=True)

    # combine list of items by putting by-label items first
    # followed by fstype items, but with dupes removed
    combined = (by_label + [d for d in by_fstype if d not in by_label])

    # We are looking for a block device or partition with necessary label or
    # an unpartitioned block device.
    combined = [d for d in combined
                    if d in by_label or not util.is_partition(d)]

    return combined
Beispiel #4
0
def find_candidate_devs():
    """Return a list of devices that may contain the config drive.

    The returned list is sorted by search order where the first item has
    should be searched first (highest priority)

    config drive v1:
       Per documentation, this is "associated as the last available disk on the
       instance", and should be VFAT.
       Currently, we do not restrict search list to "last available disk"

    config drive v2:
       Disk should be:
        * either vfat or iso9660 formated
        * labeled with 'config-2'
    """

    # Query optical drive to get it in blkid cache for 2.6 kernels
    util.find_devs_with(path="/dev/sr0")
    util.find_devs_with(path="/dev/sr1")

    by_fstype = (util.find_devs_with("TYPE=vfat") +
                 util.find_devs_with("TYPE=iso9660"))
    by_label = util.find_devs_with("LABEL=config-2")

    # give preference to "last available disk" (vdb over vda)
    # note, this is not a perfect rendition of that.
    by_fstype.sort(reverse=True)
    by_label.sort(reverse=True)

    # combine list of items by putting by-label items first
    # followed by fstype items, but with dupes removed
    combined = (by_label + [d for d in by_fstype if d not in by_label])

    # We are looking for block device (sda, not sda1), ignore partitions
    combined = [d for d in combined if not util.is_partition(d)]

    return combined