示例#1
0
def adapters(filterstr="any"):
    dict = {}
    devs = {}
    adt = {}
    fcoe_eth_info = {}

    if filterstr == "fcoe":
        fcoe_eth_info = fcoelib.parse_fcoe_eth_info()

    for a in os.listdir(SYSFS_PATH1):
        proc = match_hbadevs(a, filterstr)
        if not proc:
            continue
        adt[a] = proc
        id = a.replace("host","")
        scsiutil.rescan([id])
        emulex = False
        paths = []
        if proc == "lpfc":
            emulex = True
            paths.append(SYSFS_PATH3)
        else:
            for p in [os.path.join(SYSFS_PATH1,a,"device","session*"),os.path.join(SYSFS_PATH1,a,"device"),\
                          os.path.join(SYSFS_PATH2,"%s:*"%id)]:
                paths += glob.glob(p)

        if not len(paths):
            continue
        for path in paths:
            for i in filter(match_targets,os.listdir(path)):
                tgt = i.replace('target','')
                if emulex:
                    sysfs = os.path.join(SYSFS_PATH3,i,"device")
                else:
                    sysfs = SYSFS_PATH2
                for lun in os.listdir(sysfs):
                    if not match_LUNs(lun,tgt):
                        continue
                    if emulex:
                        dir = os.path.join(sysfs,lun)
                    else:
                        dir = os.path.join(sysfs,lun,"device")
                    (dev, entry) = _extract_dev(dir, proc, id, lun)
                    update_devs_dict(devs, dev, entry)
            # for new qlogic sysfs layout (rport under device, then target)
            for i in filter(match_rport,os.listdir(path)):
                newpath = os.path.join(path, i)
                for j in filter(match_targets,os.listdir(newpath)):
                    tgt = j.replace('target','')
                    sysfs = SYSFS_PATH2
                    for lun in os.listdir(sysfs):
                        if not match_LUNs(lun,tgt):
                            continue
                        #Special casing for fcoe, populating eth information
                        eth = ""
                        if i in fcoe_eth_info.keys():
                            eth = fcoe_eth_info[i]
                        dir = os.path.join(sysfs,lun,"device")
                        (dev, entry) = _extract_dev(dir, proc, id, lun, eth)
                        update_devs_dict(devs, dev, entry)

            # for new mptsas sysfs entries, check for phy* node
            for i in filter(match_phy,os.listdir(path)):
                (target,lunid) = i.replace('phy-','').split(':')
                tgt = "%s:0:0:%s" % (target,lunid)
                sysfs = SYSFS_PATH2
                for lun in os.listdir(sysfs):
                    if not match_LUNs(lun,tgt):
                        continue
                    dir = os.path.join(sysfs,lun,"device")
                    (dev, entry) = _extract_dev(dir, proc, id, lun)
                    update_devs_dict(devs, dev, entry)
            if path.startswith(SYSFS_PATH2):
                os.path.join(path,"device","block:*")
                dev = _extract_dev_name(os.path.join(path, 'device'))
                if devs.has_key(dev):
                    continue
                hbtl = os.path.basename(path)
                (h,b,t,l) = hbtl.split(':')
                entry = {'procname':proc, 'host':id, 'target':l}
                update_devs_dict(devs, dev, entry)

    dict['devs'] = devs
    dict['adt'] = adt
    return dict
示例#2
0
文件: devscan.py 项目: MarkSymsCtx/sm
def adapters(filterstr="any"):
    dict = {}
    devs = {}
    adt = {}
    fcoe_eth_info = {}
    fcoe_port_info = []

    fcoe_port_info = fcoelib.parse_fcoe_port_name_info()
    if filterstr == "fcoe":
        fcoe_eth_info = fcoelib.parse_fcoe_eth_info()

    for a in os.listdir(SYSFS_PATH1):
        proc = match_hbadevs(a, filterstr)
        if not proc:
            continue

        #Special casing for fcoe
        port_name_path = os.path.join(SYSFS_PATH1,a,'device',\
                         'fc_host',a,'port_name')
        port_name_path_exists = os.path.exists(port_name_path)
        util.SMlog("Port name path exists %d" % port_name_path_exists)
        if filterstr == "fcoe" and not port_name_path_exists:
            continue
        if port_name_path_exists:
            port_name = _get_port_name(port_name_path)
            #If we are probing for fcoe luns/ adapters and if the port name
            #in /sys/class/scsi_host/a/device/fc_host/a/port_name does not match
            #one in the output of 'fcoeadm -i', then we shouldn't display that
            #lun/adapter.
            #On the other hand, if we are probing for hba luns, and if the
            #port name in /sys/class/scsi_host/a/device/fc_host/a/port_name
            #matches one in the output of 'fcoeadm -i', then we shouldn't
            #display that lun/adapter, because that would have been discovered
            #via the FCoE protocol.
            if (filterstr == "fcoe" and port_name not in fcoe_port_info) or \
                (filterstr != "fcoe" and port_name in fcoe_port_info):
                continue

        adt[a] = proc
        id = a.replace("host","")
        scsiutil.rescan([id])
        emulex = False
        paths = []
        if proc == "lpfc":
            emulex = True
            paths.append(SYSFS_PATH3)
        else:
            for p in [os.path.join(SYSFS_PATH1,a,"device","session*"),os.path.join(SYSFS_PATH1,a,"device"),\
                          os.path.join(SYSFS_PATH2,"%s:*"%id)]:
                paths += glob.glob(p)

        if not len(paths):
            continue
        for path in paths:
            for i in filter(match_targets,os.listdir(path)):
                tgt = i.replace('target','')
                if emulex:
                    sysfs = os.path.join(SYSFS_PATH3,i,"device")
                else:
                    sysfs = SYSFS_PATH2
                for lun in os.listdir(sysfs):
                    if not match_LUNs(lun,tgt):
                        continue
                    if emulex:
                        dir = os.path.join(sysfs,lun)
                    else:
                        dir = os.path.join(sysfs,lun,"device")
                    (dev, entry) = _extract_dev(dir, proc, id, lun)
                    update_devs_dict(devs, dev, entry)
            # for new qlogic sysfs layout (rport under device, then target)
            for i in filter(match_rport,os.listdir(path)):
                newpath = os.path.join(path, i)
                for j in filter(match_targets,os.listdir(newpath)):
                    tgt = j.replace('target','')
                    sysfs = SYSFS_PATH2
                    for lun in os.listdir(sysfs):
                        if not match_LUNs(lun,tgt):
                            continue
                        #Special casing for fcoe, populating eth information
                        eth = ""
                        if i in fcoe_eth_info.keys():
                            eth = fcoe_eth_info[i]
                        dir = os.path.join(sysfs,lun,"device")
                        (dev, entry) = _extract_dev(dir, proc, id, lun, eth)
                        update_devs_dict(devs, dev, entry)

            # for new mptsas sysfs entries, check for phy* node
            for i in filter(match_phy,os.listdir(path)):
                (target,lunid) = i.replace('phy-','').split(':')
                tgt = "%s:0:0:%s" % (target,lunid)
                sysfs = SYSFS_PATH2
                for lun in os.listdir(sysfs):
                    if not match_LUNs(lun,tgt):
                        continue
                    dir = os.path.join(sysfs,lun,"device")
                    (dev, entry) = _extract_dev(dir, proc, id, lun)
                    update_devs_dict(devs, dev, entry)
            if path.startswith(SYSFS_PATH2):
                os.path.join(path,"device","block:*")
                dev = _extract_dev_name(os.path.join(path, 'device'))
                if devs.has_key(dev):
                    continue
                hbtl = os.path.basename(path)
                (h,b,t,l) = hbtl.split(':')
                entry = {'procname':proc, 'host':id, 'target':l}
                update_devs_dict(devs, dev, entry)

    dict['devs'] = devs
    dict['adt'] = adt
    return dict
示例#3
0
文件: devscan.py 项目: stormi/sm
def adapters(filterstr="any"):
    dict = {}
    devs = {}
    adt = {}
    fcoe_eth_info = {}
    fcoe_port_info = []

    fcoe_port_info = fcoelib.parse_fcoe_port_name_info()
    if filterstr == "fcoe":
        fcoe_eth_info = fcoelib.parse_fcoe_eth_info()

    for a in os.listdir(SYSFS_PATH1):
        proc = match_hbadevs(a, filterstr)
        if not proc:
            continue

        #Special casing for fcoe
        port_name_path = os.path.join(SYSFS_PATH1,a,'device',\
                         'fc_host',a,'port_name')
        port_name_path_exists = os.path.exists(port_name_path)
        util.SMlog("Port name path exists %d" % port_name_path_exists)
        if filterstr == "fcoe" and not port_name_path_exists:
            continue
        if port_name_path_exists:
            port_name = _get_port_name(port_name_path)
            #If we are probing for fcoe luns/ adapters and if the port name
            #in /sys/class/scsi_host/a/device/fc_host/a/port_name does not match
            #one in the output of 'fcoeadm -i', then we shouldn't display that
            #lun/adapter.
            #On the other hand, if we are probing for hba luns, and if the
            #port name in /sys/class/scsi_host/a/device/fc_host/a/port_name
            #matches one in the output of 'fcoeadm -i', then we shouldn't
            #display that lun/adapter, because that would have been discovered
            #via the FCoE protocol.
            if (filterstr == "fcoe" and port_name not in fcoe_port_info) or \
                (filterstr != "fcoe" and port_name in fcoe_port_info):
                continue

        adt[a] = proc
        id = a.replace("host", "")
        scsiutil.rescan([id])
        emulex = False
        paths = []
        if proc == "lpfc":
            emulex = True
            paths.append(SYSFS_PATH3)
        else:
            for p in [os.path.join(SYSFS_PATH1,a,"device","session*"),os.path.join(SYSFS_PATH1,a,"device"),\
                          os.path.join(SYSFS_PATH2,"%s:*"%id)]:
                paths += glob.glob(p)

        if not len(paths):
            continue
        for path in paths:
            for i in filter(match_targets, os.listdir(path)):
                tgt = i.replace('target', '')
                if emulex:
                    sysfs = os.path.join(SYSFS_PATH3, i, "device")
                else:
                    sysfs = SYSFS_PATH2
                for lun in os.listdir(sysfs):
                    if not match_LUNs(lun, tgt):
                        continue
                    if emulex:
                        dir = os.path.join(sysfs, lun)
                    else:
                        dir = os.path.join(sysfs, lun, "device")
                    (dev, entry) = _extract_dev(dir, proc, id, lun)
                    update_devs_dict(devs, dev, entry)
            # for new qlogic sysfs layout (rport under device, then target)
            for i in filter(match_rport, os.listdir(path)):
                newpath = os.path.join(path, i)
                for j in filter(match_targets, os.listdir(newpath)):
                    tgt = j.replace('target', '')
                    sysfs = SYSFS_PATH2
                    for lun in os.listdir(sysfs):
                        if not match_LUNs(lun, tgt):
                            continue
                        #Special casing for fcoe, populating eth information
                        eth = ""
                        if i in fcoe_eth_info.keys():
                            eth = fcoe_eth_info[i]
                        dir = os.path.join(sysfs, lun, "device")
                        (dev, entry) = _extract_dev(dir, proc, id, lun, eth)
                        update_devs_dict(devs, dev, entry)

            # for new mptsas sysfs entries, check for phy* node
            for i in filter(match_phy, os.listdir(path)):
                (target, lunid) = i.replace('phy-', '').split(':')
                tgt = "%s:0:0:%s" % (target, lunid)
                sysfs = SYSFS_PATH2
                for lun in os.listdir(sysfs):
                    if not match_LUNs(lun, tgt):
                        continue
                    dir = os.path.join(sysfs, lun, "device")
                    (dev, entry) = _extract_dev(dir, proc, id, lun)
                    update_devs_dict(devs, dev, entry)
            if path.startswith(SYSFS_PATH2):
                os.path.join(path, "device", "block:*")
                dev = _extract_dev_name(os.path.join(path, 'device'))
                if dev in devs:
                    continue
                hbtl = os.path.basename(path)
                (h, b, t, l) = hbtl.split(':')
                entry = {'procname': proc, 'host': id, 'target': l}
                update_devs_dict(devs, dev, entry)

    dict['devs'] = devs
    dict['adt'] = adt
    return dict
示例#4
0
def adapters(filterstr="any"):
    dict = {}
    devs = {}
    adt = {}
    fcoe_eth_info = {}

    if filterstr == "fcoe":
        fcoe_eth_info = fcoelib.parse_fcoe_eth_info()

    for a in os.listdir(SYSFS_PATH1):
        proc = match_hbadevs(a, filterstr)
        if not proc:
            continue
        adt[a] = proc
        id = a.replace("host", "")
        scsiutil.rescan([id])
        emulex = False
        paths = []
        if proc == "lpfc":
            emulex = True
            paths.append(SYSFS_PATH3)
        else:
            for p in [os.path.join(SYSFS_PATH1,a,"device","session*"),os.path.join(SYSFS_PATH1,a,"device"),\
                          os.path.join(SYSFS_PATH2,"%s:*"%id)]:
                paths += glob.glob(p)

        if not len(paths):
            continue
        for path in paths:
            for i in filter(match_targets, os.listdir(path)):
                tgt = i.replace('target', '')
                if emulex:
                    sysfs = os.path.join(SYSFS_PATH3, i, "device")
                else:
                    sysfs = SYSFS_PATH2
                for lun in os.listdir(sysfs):
                    if not match_LUNs(lun, tgt):
                        continue
                    if emulex:
                        dir = os.path.join(sysfs, lun)
                    else:
                        dir = os.path.join(sysfs, lun, "device")
                    (dev, entry) = _extract_dev(dir, proc, id, lun)
                    update_devs_dict(devs, dev, entry)
            # for new qlogic sysfs layout (rport under device, then target)
            for i in filter(match_rport, os.listdir(path)):
                newpath = os.path.join(path, i)
                for j in filter(match_targets, os.listdir(newpath)):
                    tgt = j.replace('target', '')
                    sysfs = SYSFS_PATH2
                    for lun in os.listdir(sysfs):
                        if not match_LUNs(lun, tgt):
                            continue
                        #Special casing for fcoe, populating eth information
                        eth = ""
                        if i in fcoe_eth_info.keys():
                            eth = fcoe_eth_info[i]
                        dir = os.path.join(sysfs, lun, "device")
                        (dev, entry) = _extract_dev(dir, proc, id, lun, eth)
                        update_devs_dict(devs, dev, entry)

            # for new mptsas sysfs entries, check for phy* node
            for i in filter(match_phy, os.listdir(path)):
                (target, lunid) = i.replace('phy-', '').split(':')
                tgt = "%s:0:0:%s" % (target, lunid)
                sysfs = SYSFS_PATH2
                for lun in os.listdir(sysfs):
                    if not match_LUNs(lun, tgt):
                        continue
                    dir = os.path.join(sysfs, lun, "device")
                    (dev, entry) = _extract_dev(dir, proc, id, lun)
                    update_devs_dict(devs, dev, entry)
            if path.startswith(SYSFS_PATH2):
                os.path.join(path, "device", "block:*")
                dev = _extract_dev_name(os.path.join(path, 'device'))
                if devs.has_key(dev):
                    continue
                hbtl = os.path.basename(path)
                (h, b, t, l) = hbtl.split(':')
                entry = {'procname': proc, 'host': id, 'target': l}
                update_devs_dict(devs, dev, entry)

    dict['devs'] = devs
    dict['adt'] = adt
    return dict