def processStartUp(request): param = json.loads(request.body) hostUuid = param.get('hostUuid') if not GlobalDb.get(hostUuid): GlobalDb.put(hostUuid, getdb()) db = GlobalDb.get(hostUuid) with getlock(db) as mylock: puth(db,hostUuid,param.get('hostClass')) hostid = uuid2hostid(db, hostUuid) putc(db, hostid, param.get('cpuClass')) putms(db, hostid, param.get('memClass')) putns(db, hostid, param.get('netClass')) putds(db, hostid, param.get('diskClass')) if not GlobalQueue.get(hostUuid): loadQueue(hostUuid, GlobalQueue) if not GlobalThread.get(hostUuid): loadThread(hostUuid, GlobalThread) return jresponse('0','ready',request,200)
def processStartUp(request): param = json.loads(request.body) hostUuid = param.get('hostUuid') if not GlobalDb.get(hostUuid): GlobalDb.put(hostUuid, getdb()) db = GlobalDb.get(hostUuid) with getlock(db) as mylock: puth(db, hostUuid, param.get('hostClass')) hostid = uuid2hostid(db, hostUuid) putc(db, hostid, param.get('cpuClass')) putms(db, hostid, param.get('memClass')) putns(db, hostid, param.get('netClass')) putds(db, hostid, param.get('diskClass')) if not GlobalQueue.get(hostUuid): loadQueue(hostUuid, GlobalQueue) if not GlobalThread.get(hostUuid): loadThread(hostUuid, GlobalThread) return jresponse('0', 'ready', request, 200)
def __init__(self, hostUuid): threading.Thread.__init__(self) self.db = getdb() self.hostUuid = hostUuid
staticAttrs = {} hostAttrs = host_queryattrs(db) for attr in hostAttrs: staticAttrs.update({attr.pop(ht.uuid): {'host': attr}}) return staticAttrs def query_host_static(hostUuid): pass def query_all_static(db): ht = Host() staticAttrs = query_hosts(db) for _, staticAttr in staticAttrs.items(): host_id = staticAttr.get('host').get(ht.id) staticAttr.update({'cpu': query_host_cpu(db, host_id)}) staticAttr.update({'mem': query_host_mem(db, host_id)}) staticAttr.update({'disk': query_host_disk(db, host_id)}) staticAttr.update({'net': query_host_net(db, host_id)}) return staticAttrs if __name__ == '__main__': conn = getdb() print query_all_static(conn)
def __init__(self,hostUuid): threading.Thread.__init__(self) self.db = getdb() self.hostUuid = hostUuid
def query_stat_net(db, hid): return net_hid2attrs(db, hid) def query_stat_mem(db, hid): return mem_hid2attrs(db, hid) def query_stat_storage(db, hid): attrs = storage_hid2attrs(db, hid) sorted_attrs = sorted(attrs, key=lambda attr: attr.get('seq'), reverse=True) storage_list = [] uuids = [] for s in sorted_attrs: if s.get('uuid') not in uuids: uuids.append(s.get('uuid')) storage_list.append(s) else: break return storage_list if __name__ == '__main__': db = getdb() res = query_stat_storage(db, 6) print res
def query_stat_cpu(db,hid): return cpu_hid2attrs(db, hid) def query_stat_disk(db,hid): return disk_hid2attrs(db, hid) def query_stat_net(db,hid): return net_hid2attrs(db, hid) def query_stat_mem(db,hid): return mem_hid2attrs(db, hid) def query_stat_storage(db,hid): attrs = storage_hid2attrs(db,hid) sorted_attrs = sorted(attrs, key=lambda attr: attr.get('seq'),reverse=True) storage_list = [] uuids = [] for s in sorted_attrs: if s.get('uuid') not in uuids: uuids.append(s.get('uuid')) storage_list.append(s) else: break return storage_list if __name__ == '__main__': db = getdb() res = query_stat_storage(db,6) print res