예제 #1
0
파일: mpathcount.py 프로젝트: robhoes/sm
def get_path_count(SCSIid, active=True):
    count = 0
    if mpp_luncheck.is_RdacLun(SCSIid):
        (total_count, active_count) = mpp_mpathutil.get_pathinfo(SCSIid)
        return (total_count, active_count)
    lines = mpath_cli.get_topology(SCSIid)
    for line in filter(match_dmpLUN, lines):
        if not active:
            count += 1
        elif match_pathup(line):
            count += 1
    return count
예제 #2
0
파일: mpathcount.py 프로젝트: MrMEEE/sm
def get_path_count(SCSIid, active=True):
    count = 0
    if (mpp_luncheck.is_RdacLun(SCSIid)):
        (total_count, active_count) = mpp_mpathutil.get_pathinfo(SCSIid)
        return (total_count, active_count)
    lines = mpath_cli.get_topology(SCSIid)
    for line in filter(match_dmpLUN,lines):
        if not active:
            count += 1
        elif match_pathup(line):
            count += 1
    return count
예제 #3
0
def UpdatePaths():

    while True:
        try:
            session = None
            # Garbage collect any memory allocated in the last run of the loop
            DEBUG("The garbage collection routine returned: %d" % gc.collect())

            # Sleep for some time before checking the status again
            time.sleep(MPP_PATH_STATUS_UPDATE_INTERVAL)

            # List the contents of the directory /dev/disk/mpInuse
            fileList = glob.glob(MPP_DEVICES_IN_USE_LOCATION + "/" + "*")
            if not len(fileList):
                continue

            # for each SCSI ID get the cached values of the total paths and active paths
            # and then compare this with the current path status obtained using mpp_mpathutil.py
            for filename in fileList:
                # extract the SCSI ID from the file name.
                scsiid = filename.rsplit("/")[len(filename.rsplit("/")) - 1].split("-")[0]
                if not (mpp_luncheck.is_RdacLun(scsiid)):
                    continue

                # Get the cached value for the total and active paths for this SCSI ID
                try:
                    cacheFile = glob.glob(MPP_PATH_CACHE_LOCATION + "/" + scsiid + "*")
                    if len(cacheFile) > 1:
                        DEBUG("More than one cache file found for SCSI ID %s. Please check the cache manually.")
                        raise Exception

                        # This will return only one file name of the form SCSIID:TOTALPATHS:ACTIVEPATHS, so parse accordingly
                    cachedTotalPaths = cacheFile[0].split(":")[1]
                    cachedActivePaths = cacheFile[0].split(":")[2]
                    cacheFileFound = True
                except:
                    DEBUG("There was an exception getting the cached path status for SCSI ID %s, assuming 0s." % scsiid)
                    cachedTotalPaths = 0
                    cachedActivePaths = 0
                    cacheFileFound = False

                (totalPaths, activePaths) = mpp_mpathutil.get_pathinfo(scsiid)

                DEBUG(
                    "For SCSI ID %s, cached TotalPaths: %s, cached ActivePaths: %s, New Totalpaths: %s New ActivePaths: %s"
                    % (scsiid, cachedTotalPaths, cachedActivePaths, totalPaths, activePaths)
                )

                if cachedTotalPaths != str(totalPaths) or cachedActivePaths != str(activePaths):
                    DEBUG("Some path status has changed for SCSI ID %s, updating PBD." % scsiid)
                    entry = "[" + str(activePaths) + ", " + str(totalPaths) + "]"
                    DEBUG(entry)
                    cmd = ["/opt/xensource/sm/mpathcount.py", scsiid, entry]
                    util.pread2(cmd)

                    # Now update the cache with this updated path status
                    DEBUG("Checking if cache file was found.")
                    if cacheFileFound == True:
                        DEBUG("Cache file was found, delete it.")
                        os.remove(cacheFile[0])
                    cacheFileName = (
                        MPP_PATH_CACHE_LOCATION + "/" + scsiid + ":" + str(totalPaths) + ":" + str(activePaths)
                    )
                    DEBUG("Generated new cache file name %s" % cacheFileName)
                    open(cacheFileName, "w").close()

        except:
            pass
        # DEBUG("There was some exception while updating path status for the SCSI ID %s." % scsiid )
        # break

        if session != None:
            session.xenapi.session.logout()

    return
예제 #4
0
def UpdatePaths():

    while (True):
        try:
            session = None
            # Garbage collect any memory allocated in the last run of the loop
            DEBUG("The garbage collection routine returned: %d" % gc.collect())

            # Sleep for some time before checking the status again
            time.sleep(MPP_PATH_STATUS_UPDATE_INTERVAL)

            # List the contents of the directory /dev/disk/mpInuse
            fileList = glob.glob(MPP_DEVICES_IN_USE_LOCATION + "/" + "*")
            if not len(fileList):
                continue

        # for each SCSI ID get the cached values of the total paths and active paths
        # and then compare this with the current path status obtained using mpp_mpathutil.py
            for filename in fileList:
                # extract the SCSI ID from the file name.
                scsiid = filename.rsplit("/")[len(filename.rsplit("/")) -
                                              1].split('-')[0]
                if not (mpp_luncheck.is_RdacLun(scsiid)):
                    continue

        # Get the cached value for the total and active paths for this SCSI ID
                try:
                    cacheFile = glob.glob(MPP_PATH_CACHE_LOCATION + "/" +
                                          scsiid + "*")
                    if len(cacheFile) > 1:
                        DEBUG(
                            "More than one cache file found for SCSI ID %s. Please check the cache manually."
                        )
                        raise Exception

                    # This will return only one file name of the form SCSIID:TOTALPATHS:ACTIVEPATHS, so parse accordingly
                    cachedTotalPaths = cacheFile[0].split(":")[1]
                    cachedActivePaths = cacheFile[0].split(":")[2]
                    cacheFileFound = True
                except:
                    DEBUG(
                        "There was an exception getting the cached path status for SCSI ID %s, assuming 0s."
                        % scsiid)
                    cachedTotalPaths = 0
                    cachedActivePaths = 0
                    cacheFileFound = False

                (totalPaths, activePaths) = mpp_mpathutil.get_pathinfo(scsiid)

                DEBUG(
                    "For SCSI ID %s, cached TotalPaths: %s, cached ActivePaths: %s, New Totalpaths: %s New ActivePaths: %s"
                    % (scsiid, cachedTotalPaths, cachedActivePaths, totalPaths,
                       activePaths))

                if cachedTotalPaths != str(
                        totalPaths) or cachedActivePaths != str(activePaths):
                    DEBUG(
                        "Some path status has changed for SCSI ID %s, updating PBD."
                        % scsiid)
                    entry = "[" + str(activePaths) + ", " + str(
                        totalPaths) + "]"
                    DEBUG(entry)
                    cmd = ['/opt/xensource/sm/mpathcount.py', scsiid, entry]
                    util.pread2(cmd)

                    # Now update the cache with this updated path status
                    DEBUG("Checking if cache file was found.")
                    if cacheFileFound == True:
                        DEBUG("Cache file was found, delete it.")
                        os.remove(cacheFile[0])
                    cacheFileName = MPP_PATH_CACHE_LOCATION + "/" + scsiid + ":" + str(
                        totalPaths) + ":" + str(activePaths)
                    DEBUG("Generated new cache file name %s" % cacheFileName)
                    open(cacheFileName, 'w').close()

        except:
            pass
#DEBUG("There was some exception while updating path status for the SCSI ID %s." % scsiid )
        #break

        if session != None:
            session.xenapi.session.logout()

    return