|
| 1 | +from pythonlsf import lsf |
| 2 | +import sys |
| 3 | + |
| 4 | +def printLsInfo(argList): |
| 5 | + if lsf.lsb_init("test") > 0: |
| 6 | + return -1; |
| 7 | + |
| 8 | + valueList=["Boolean","Numeric","String","Dynamic","External"] |
| 9 | + orderList=["Inc","Dec","N/A"] |
| 10 | + allInfo = lsf.ls_info_py() |
| 11 | + print("Current cluster has {} resources in total.".format(allInfo["nRes"])) |
| 12 | + print("Current cluster has {} types in total.".format(allInfo["nTypes"])) |
| 13 | + print("Current cluster has {} models in total.".format(allInfo["nModels"])) |
| 14 | + resTable = allInfo["resTable"] |
| 15 | + |
| 16 | + matchList = [] |
| 17 | + unMatchList = [] |
| 18 | + showAll = 0 |
| 19 | + mFlag = 0 |
| 20 | + mmFlag = 0 |
| 21 | + rFlag = 0 |
| 22 | + tFlag = 0 |
| 23 | + resFound = 0 |
| 24 | + if "-m" in argList: |
| 25 | + mFlag = 1 |
| 26 | + if "-M" in argList: |
| 27 | + mFlag = 1 |
| 28 | + mmFlag = 1 |
| 29 | + if "-r" in argList: |
| 30 | + rFlag = 1 |
| 31 | + if "-t" in argList: |
| 32 | + tFlag = 1 |
| 33 | + |
| 34 | + if len(argList) > 0: |
| 35 | + for target in argList: |
| 36 | + if target[0] != "-": |
| 37 | + resFound = 0 |
| 38 | + for i in range(len(resTable)): |
| 39 | + if resTable[i].name == target : |
| 40 | + matchList.append(i) |
| 41 | + resFound = 1 |
| 42 | + break |
| 43 | + if resFound == 0: |
| 44 | + unMatchList.append(target) |
| 45 | + |
| 46 | + if len(argList) == 0 and len(unMatchList) == 0: |
| 47 | + showAll = 1 |
| 48 | + |
| 49 | + if (showAll == 1 or rFlag > 0 or len(matchList) > 0 or len(unMatchList) > 0) : |
| 50 | + print("ESOURCE_NAME TYPE ORDER DESCRIPTION") |
| 51 | + if len(matchList) == 0 and len(unMatchList) == 0: |
| 52 | + for i in range(len(resTable)): |
| 53 | + print("{} {} {} {}".format(resTable[i].name, valueList[resTable[i].valueType], orderList[resTable[i].orderType], resTable[i].des)) |
| 54 | + |
| 55 | + else: |
| 56 | + for i in range(len(resTable)): |
| 57 | + if i in matchList : |
| 58 | + print("{} {} {} {}".format(resTable[i].name, valueList[resTable[i].valueType], orderList[resTable[i].orderType], resTable[i].des)) |
| 59 | + for target in unMatchList : |
| 60 | + print("{}: resource name not found.".format(target)) |
| 61 | + if (showAll == 1 or tFlag > 0): |
| 62 | + hostTypes = allInfo["hostTypes"] |
| 63 | + print("TYPE_NAME") |
| 64 | + for i in range(len(hostTypes)): |
| 65 | + print("{}".format(hostTypes[i])) |
| 66 | + if mFlag > 0 : |
| 67 | + hostModels = allInfo["hostModels"] |
| 68 | + hostArchs = allInfo["hostArchs"] |
| 69 | + modelRefs = allInfo["modelRefs"] |
| 70 | + cpuFactor = allInfo["cpuFactor"] |
| 71 | + print("MODEL_NAME CPU_FACTOR ARCHITECTURE") |
| 72 | + for i in range(allInfo["nModels"]): |
| 73 | + if (mmFlag > 0 or modelRefs[i] > 0): |
| 74 | + print("{} {} {}".format(hostModels[i],cpuFactor[i],hostArchs[i])) |
| 75 | + if (showAll == 0 and len(matchList) == 0 and mFlag == 0 and mmFlag == 0 and rFlag == 0 and tFlag == 0): |
| 76 | + print("No match resource found.") |
| 77 | + |
| 78 | + |
| 79 | + return 0 |
| 80 | + |
| 81 | +if __name__ == '__main__': |
| 82 | + print("LSF Clustername is : {}".format(lsf.ls_getclustername())) |
| 83 | + argList = [] |
| 84 | + if len(sys.argv) > 1 : |
| 85 | + for i in range(1,len(sys.argv)): |
| 86 | + argList.append(sys.argv[i]) |
| 87 | + printLsInfo(argList) |
| 88 | + |
0 commit comments