Ejemplo n.º 1
0
def get_meminfo_fromdb(db, dbname):
    totalMem = 0
    vmTotalMem = 0
    vmUsedMem = 0

    if dbname == "octframe":
        ret = db.select("tb_vm", dbname=dbname)
        if ret == -1:
            ERROR("select tb_vm from db err")

        for dur in db.cur:
            obj = row_to_dict("tb_vm", dur, dbname)
            basic = transToObj(obj['V_Basic'].replace('\n', '\\n'))
            if basic == None:
                continue

            memory = int(basic["memory"])  #unit MByte
            vmTotalMem += memory * 1024 * 1024

            state = int(obj['V_State'])
            if state == 2:  #running
                vmUsedMem += memory * 1024 * 1024  #unit Byte

        ret = db.select("tb_host", dbname=dbname)
        if ret == -1:
            ERROR("select tb_host from db err")

        for dur in db.cur:
            obj = row_to_dict("tb_host", dur, dbname)
            memObj = transToObj(obj['H_Memory'].replace('\n', '\\n'))
            if memObj == None:
                continue

            tmp = int(memObj["total"])  #unit MByte
            totalMem += tmp * 1024 * 1024  #unit Byte

    else:
        ret = db.select("tb_vm", dbname=dbname)
        if ret == -1:
            ERROR("select tb_vm from db err")

        for dur in db.cur:
            obj = row_to_dict("tb_vm", dur, dbname)
            memory = int(obj["V_Memory"])  #unit MByte
            status = obj["V_Status"]

            vmTotalMem += memory * 1024 * 1024
            if status == "Running":
                vmUsedMem += memory * 1024 * 1024  #unit Byte

        ret = db.select("v_host", dbname=dbname)
        if ret == -1:
            ERROR("select v_host from db err")

        for dur in db.cur:
            obj = row_to_dict("v_host", dur, dbname)
            tmp = int(obj["MemoryTotal"])  #unit KB
            totalMem += tmp * 1024  #unit Byte

    return (totalMem, vmTotalMem, vmUsedMem)
Ejemplo n.º 2
0
def get_cpuinfo_fromdb(db, dbname):
    vcpuTotal = 0
    vcpuUsed = 0
    vcpuAlloc = 0

    if dbname == "octframe":
        ret = db.select("tb_vm", dbname=dbname)
        if ret == -1:
            ERROR("select tb_vm from db err")

        for dur in db.cur:
            obj = row_to_dict("tb_vm", dur, dbname)
            basic = transToObj(obj['V_Basic'].replace('\n', '\\n'))
            if basic == None:
                continue

            state = int(obj['V_State'])

            vcpuAlloc += int(basic["cpu"])
            if state == 2:  #running
                vcpuUsed += int(basic["cpu"])

        ret = db.select("tb_host", dbname=dbname)
        if ret == -1:
            ERROR("select tb_host from db err")

        for dur in db.cur:
            obj = row_to_dict("tb_host", dur, dbname)
            other = transToObj(obj['H_Others'].replace('\n', '\\n'))

            vcpuTotal = int(other["cpu_core"]) * 4

    else:
        ret = db.select("tb_vm", dbname=dbname)
        if ret == -1:
            ERROR("select tb_vm from db err")

        for dur in db.cur:
            obj = row_to_dict("tb_vm", dur, dbname)
            cpunum = int(obj["V_CpuNum"])
            status = obj["V_Status"]

            vcpuAlloc += cpunum
            if status == "Running":
                vcpuUsed += cpunum

        ret = db.select("v_host", dbname=dbname)
        if ret == -1:
            ERROR("select v_host from db err")

        for dur in db.cur:
            obj = row_to_dict("v_host", dur, dbname)
            vcpuTotal += int(obj["VCpuTotal"])

    return (vcpuTotal, vcpuUsed, vcpuAlloc)
Ejemplo n.º 3
0
    def loadFromObj(self):
        self.myId = self.dbObj["ID"]
        self.name = self.dbObj["QR_Name"]
        self.type = self.dbObj["QR_Type"]
        self.price = self.dbObj["QR_Price"]
        self.points = self.dbObj["QR_Points"]

        self.info = transToObj(self.dbObj["QR_Info"])
        self.paras = transToObj(self.dbObj["QR_Paras"])
        self.desc = self.dbObj["QR_Description"]
        self.createTime = self.dbObj["QR_CreateTime"]

        return 0
Ejemplo n.º 4
0
    def loadFromObj(self):

        self.myId = self.dbObj["ID"]
        self.accountId = self.dbObj["AT_AccountId"]
        self.state = self.dbObj["AT_State"]
        self.name = self.dbObj["AT_Name"]
        self.type = self.dbObj["AT_Type"]
        self.user = transToObj(self.dbObj["AT_User"])
        self.apiId = self.dbObj["AT_ApiId"]
        self.request = transToObj(self.dbObj["AT_Request"])
        self.reply = transToObj(self.dbObj["AT_Reply"])
        self.startTime = self.dbObj["AT_StartTime"]
        self.finishTime = self.dbObj["AT_FinishTime"]

        return 0
Ejemplo n.º 5
0
Archivo: Msg.py Proyecto: maqg/quantum
    def loadFromObj(self):

        self.type = self.dbObj["M_Type"]
        self.msg = transToObj(self.dbObj["M_Msg"])
        self.agentId = self.dbObj["M_AgentId"]
        self.time = self.dbObj["M_Time"]

        return 0
Ejemplo n.º 6
0
    def loadFromObj(self):

        self.myId = self.dbObj["ID"]
        self.username = self.dbObj["S_UserName"]
        self.role = self.dbObj["S_UserType"]
        self.userId = self.dbObj["S_UserId"]
        self.cookie = transToObj(self.dbObj["S_Cookie"])
        self.createTime = self.dbObj["S_CreateTime"]
        self.expireTime = self.dbObj["S_ExpireTime"]

        return 0
Ejemplo n.º 7
0
    def loadFromObj(self):

        self.myId = self.dbObj["ID"]
        self.name = self.dbObj["P_Name"]

        self.type = self.dbObj["P_Type"]
        self.typeName = self.dbObj["P_TypeName"]
        self.infoObj = transToObj(self.dbObj["P_Info"])
        self.info = ProductInfo(self.type, self.infoObj)
        self.desc = self.dbObj["P_Description"]
        self.state = self.dbObj["P_State"]

        self.lastSync = self.dbObj["P_LastSync"]
        self.createTime = self.dbObj["P_CreateTime"]

        return 0