def ListVCs(userName): ret = [] vcList = DataManager.ListVCs() for vc in vcList: if AuthorizationManager.HasAccess(userName, ResourceType.VC, vc["vcName"], Permission.User): ret.append(vc) # web portal (client) can filter out Default VC return ret
def getClusterVCs(): vcList = None try: with vc_cache_lock: vcList = copy.deepcopy(vc_cache.values()) except Exception: pass if not vcList: vcList = DataManager.ListVCs() with vc_cache_lock: for vc in vcList: vc_cache[vc["vcName"]] = vc return vcList
def GetVC(userName, vcName): ret = None clusterStatus, dummy = DataManager.GetClusterStatus() clusterTotalRes = ResourceInfo(clusterStatus["gpu_capacity"]) clusterReservedRes = ResourceInfo(clusterStatus["gpu_unschedulable"]) user_status = {} vcList = DataManager.ListVCs() for vc in vcList: if vc["vcName"] == vcName and AuthorizationManager.HasAccess(userName, ResourceType.VC, vcName, Permission.User): vcTotalRes = ResourceInfo(json.loads(vc["quota"])) vcConsumedRes = ResourceInfo() jobs = DataManager.GetAllPendingJobs(vcName) for job in jobs: if job["jobStatus"] == "running": username = job["userName"] jobParam = json.loads(base64.b64decode(job["jobParams"])) if "gpuType" in jobParam and not jobParam["preemptionAllowed"]: vcConsumedRes.Add(ResourceInfo({jobParam["gpuType"] : GetJobTotalGpu(jobParam)})) if username not in user_status: user_status[username] = ResourceInfo() user_status[username].Add(ResourceInfo({jobParam["gpuType"] : GetJobTotalGpu(jobParam)})) vcReservedRes = clusterReservedRes.GetFraction(vcTotalRes, clusterTotalRes) vcAvailableRes = ResourceInfo.Difference(ResourceInfo.Difference(vcTotalRes, vcConsumedRes), vcReservedRes) vc["gpu_capacity"] = vcTotalRes.ToSerializable() vc["gpu_used"] = vcConsumedRes.ToSerializable() vc["gpu_unschedulable"] = vcReservedRes.ToSerializable() vc["gpu_avaliable"] = vcAvailableRes.ToSerializable() vc["AvaliableJobNum"] = len(jobs) vc["node_status"] = clusterStatus["node_status"] vc["user_status"] = [] for user_name, user_gpu in user_status.iteritems(): # TODO: job_manager.getAlias should be put in a util file user_name = user_name.split("@")[0].strip() vc["user_status"].append({"userName":user_name, "userGPU":user_gpu.ToSerializable()}) ret = vc break return ret