Ejemplo n.º 1
0
 def selectDomainAll(self):
     try:
         data = self.data['data']
         k = redisMgnt().control(type='select',
                                 Dict=data,
                                 table='domain_machineinfo')
         fk = []
         for i in k:
             tmp = []
             for m in range(len(i)):
                 if checkJsonFormat(i[m]):
                     g = json.loads(i[m])
                     tmp.append(g)
                 else:
                     tmp.append(i[m])
             fd = dict(zip(data, tmp))
             fk.append(fd)
         print {
             'type': 'SeletDomainAll',
             'status': 'ok',
             'user': '******',
             'des': 'get ok',
             'module': 'api-crontrol-DomainDetailViews'
         }
         return fk
     except Exception, msg:
         return {'error': 451}
Ejemplo n.º 2
0
 def createMachineUse(self):
     try:
         _tmp = {}
         conn = redisMgnt()
         AliveHost = conn.control(type="select",
                                  Dict=['UUID', 'nodeIP'],
                                  table='host_nodeinfo',
                                  Where={'nodeSTATUS': "0"})
         a, b = [x[0] for x in AliveHost], [x[1] for x in AliveHost]
         _tmp['host'] = dict(zip(a, b))
         AliveDisk = conn.control(type="select",
                                  Dict=['UUID', 'image'],
                                  table='disk_diskregister',
                                  Where={'st': "'N'"})
         a, b = [x[0] for x in AliveDisk], [x[1] for x in AliveDisk]
         _tmp['disk'] = dict(zip(a, b))
         AliveImage = conn.control(type="select",
                                   Dict=['UUID', 'image'],
                                   table='imageregister')
         a, b = [x[0] for x in AliveImage], [x[1] for x in AliveImage]
         _tmp['image'] = dict(zip(a, b))
         AliveNetwork = conn.control(type="select",
                                     Dict=['UUID', 'network'],
                                     table='network')
         _tmp['network'] = {k[0]: k[1] for k in AliveNetwork}
         conn.__exit__()
         return _tmp
     except Exception, msg:
         return {'error': 451}
Ejemplo n.º 3
0
 def getResourceNumber(self):
     try:
         conn = redisMgnt()
         instanceNumberAlive = int(
             conn.control(type="select",
                          Dict=['count(*)'],
                          table='domain_machineinfo',
                          Where={'rStatus': "'1'"})[0][0])
         instanceNumberFaild = int(
             conn.control(type="select",
                          Dict=['count(*)'],
                          table='domain_machineinfo',
                          Where={'rStatus': "'0'"})[0][0])
         nodeNumberAlive = int(
             conn.control(type="select",
                          Dict=['count(*)'],
                          table='host_nodeinfo',
                          Where={'nodeSTATUS': "'0'"})[0][0])
         nodeNumberFaild = int(
             conn.control(type="select",
                          Dict=['count(*)'],
                          table='host_nodeinfo',
                          Where={'nodeSTATUS': "'1'"})[0][0])
         return {
             'instanceAlive': instanceNumberAlive,
             'instanceFaild': instanceNumberFaild,
             'nodeAlive': nodeNumberAlive,
             'nodeFaild': nodeNumberFaild
         }
     except Exception, msg:
         print(msg)
         return {'error': 451}
Ejemplo n.º 4
0
 def clusterMangntAll(self):
     try:
         _tmp = {}
         for i in [
                 x for x in redisMgnt().control(
                     type='select',
                     Dict=[
                         'UUID', 'nodeSTATUS', 'nodeMem', 'nodeSysVersion',
                         'nodeCpu', 'nodeIP', 'nodeCpuVersion', 'hostname'
                     ],
                     table='host_nodeinfo')
         ]:
             _tmp[i[0]] = {
                 "status": int(i[1]),
                 "memory": int(i[2]),
                 "systemOS": i[3],
                 "cpu": int(i[4]),
                 "ip": i[5],
                 "cpuVersion": i[6],
                 "hostname": i[7],
                 "uuid": i[0]
             }
         return _tmp
     except Exception, msg:
         return {'error': 451}
Ejemplo n.º 5
0
    def domainControl(self, tuple):
        try:
            str = tuple
            #get num zi duan de zhi
            type = re.findall("(?<=\&)(.+?)(?=\&)", str)[0].split('=')[1]
            if type == 'all':
                cod = re.findall("(?<=\%)(.+?)(?=\%)", str)
                k = redisMgnt().control(type='select',
                                        Dict=cod,
                                        table='domain_machineinfo')
                fk = []
                for i in k:
                    tmp = []
                    for m in range(len(i)):
                        if checkJsonFormat(i[m]):
                            g = json.loads(i[m])
                            tmp.append(g)
                        else:
                            tmp.append(i[m])
                    fd = dict(zip(cod, tmp))
                    fk.append(fd)
                return fk
            if type == 'only':
                cod = re.findall("(?<=\%)(.+?)(?=\%)", str)
                bd = re.findall("(?<=\$)(.+?)(?=\$)", str)
                key = {}
                # sheng cheng where zi duan
                for i in bd:
                    ti = i.split('=')
                    key[ti[0]] = "'{}'".format(ti[1])
                k = redisMgnt().control(type='select',
                                        Dict=cod,
                                        table='domain_machineinfo',
                                        Where=key)[0]
                tmp = []
                for m in range(len(k)):
                    if checkJsonFormat(k[m].encode('utf-8')):
                        g = json.loads(k[m])
                        tmp.append(g)
                    else:
                        tmp.append(k[m])
                fd = dict(zip(cod, tmp))
                return fd

        except Exception, msg:
            pass
Ejemplo n.º 6
0
 def userAuth(self):
     user = self.data['username']
     try:
         print user
         conn = redisMgnt()
         password = hashlib.md5(self.data['password']).hexdigest()
         alist = conn.control(type='select',
                              Dict=['password'],
                              table='userinfo',
                              Where={'user': "******".format(user)})[0][0]
         alist = alist.encode('utf-8')
         if alist:
             if password == alist:
                 now = datetime.datetime.now()
                 time = now.strftime('%Y-%m-%d %H:%M:%S')
                 conn.control(type='update',
                              Dict={"lastlogin": "******".format(time)},
                              table='userinfo',
                              Where={'user': "******".format(user)})
                 conn.__exit__()
                 print {
                     'type': 'user-Auth',
                     'status': 'ok',
                     'user': user,
                     'des': 'login ok',
                     'module': 'api-crontrol-userAuth'
                 }
                 return {'code': 200}
             else:
                 print {
                     'type': 'user-Auth',
                     'status': 'faild',
                     'user': user,
                     'des': 'user password is error',
                     'module': 'api-crontrol-userAuth'
                 }
                 return {'code': 201}
         else:
             print {
                 'type': 'user-Auth',
                 'status': 'faild',
                 'user': user,
                 'des': 'user is not found',
                 'module': 'api-crontrol-userAuth'
             }
             return {'code': 201}
     except Exception, msg:
         print {
             'type': 'user-Auth',
             'status': 'faild',
             'user': user,
             'des': 'user is not found',
             'module': 'api-crontrol-userAuth'
         }
         return {'error': 451}
Ejemplo n.º 7
0
 def getResourceImage(self):
     try:
         conn = redisMgnt()
         imageList = conn.control(type="select",
                                  Dict=['UUID', 'image'],
                                  table='imageregister')
         conn.__exit__()
         _tmp = {}
         for i in imageList:
             _tmp[i[0]] = i[1]
         return _tmp
     except Exception, msg:
         return {'error': 451}
Ejemplo n.º 8
0
 def diskMangntAll(self):
     try:
         DiskInfo = {}
         DomainList = [
             x[0] for x in redisMgnt().control(
                 type='select', Dict=['UUID'], table='disk_diskregister')
         ]
         for i in DomainList:
             DiskInfo[i] = disk_control.diskInfo(UUID=i)
         return DiskInfo
     except Exception, msg:
         print(msg)
         pass
Ejemplo n.º 9
0
 def isIntanceExits(self):
     try:
         data = self.data['data']
         conn = redisMgnt()
         return {
             'code':
             "Y" if data['name'] in [
                 x[0] for x in conn.control(type='select',
                                            Dict=['vName'],
                                            table='domain_machineinfo')
             ] else "N"
         }
     except Exception, msg:
         return {'error': 451}
Ejemplo n.º 10
0
    def instanceMangntAll(self):
        try:

            DomainInfo = {}
            DomainList = [
                x[0] for x in redisMgnt().control(
                    type='select', Dict=['UUID'], table='domain_machineinfo')
            ]
            for i in DomainList:
                DomainInfo[i] = domain_control.domainInfo(UUID=i)
            print({
                'status': 'ok',
                'des': 'get ok',
                'type': 'domaininfo',
                'module': 'api-web_api_module-instanceMangntAll'
            })
            return DomainInfo
        except Exception:
            pass
Ejemplo n.º 11
0
    def getInstanceCreateInfo(self):
        try:
            _tmp = {}
            _a = {}
            conn = redisMgnt()
            aliveHost = conn.control(type="select",
                                     Dict=['UUID', 'nodeIP'],
                                     table='host_nodeinfo',
                                     Where={'nodeSTATUS': "'0'"})
            for i in aliveHost:
                _a[i[0]] = i[1]
            _tmp['inHost'] = _a
            aliveDisk = conn.control(type="select",
                                     Dict=['UUID', 'image'],
                                     table='disk_diskregister',
                                     Where={'st': "'N'"})
            for i in aliveDisk:
                _a[i[0]] = i[1]
            _tmp['Disk'] = _a

        except Exception, msg:
            print(msg)
            return {'error': 451}
Ejemplo n.º 12
0
 def diskControl(self, tuple):
     try:
         str = tuple
         type = re.findall("(?<=\&)(.+?)(?=\&)", str)[0].split('=')[1]
         if type == 'all':
             cod = re.findall("(?<=\%)(.+?)(?=\%)", str)
             k = redisMgnt().control(type='select',
                                     Dict=cod,
                                     table='disk_diskregister')
             fk = []
             for i in k:
                 tmp = []
                 for m in range(len(i)):
                     if checkJsonFormat(i[m]):
                         g = json.loads(i[m])
                         tmp.append(g)
                     else:
                         tmp.append(i[m])
                 fd = dict(zip(cod, tmp))
                 fk.append(fd)
             return fk
         elif type == 'only':
             cod = re.findall("(?<=\%)(.+?)(?=\%)", str)
             bd = re.findall("(?<=\$)(.+?)(?=\$)", str)
             key = {}
             # sheng cheng where zi duan
             for i in bd:
                 ti = i.split('=')
                 key[ti[0]] = "'{}'".format(ti[1])
             k = redisMgnt().control(type='select',
                                     Dict=cod,
                                     table='disk_diskregister',
                                     Where=key)[0]
             tmp = []
             for m in range(len(k)):
                 if checkJsonFormat(k[m].encode('utf-8')):
                     g = json.loads(k[m])
                     tmp.append(g)
                 else:
                     tmp.append(k[m])
             fd = dict(zip(cod, tmp))
             return fd
         if type == 'create':
             bd = re.findall("(?<=\$)(.+?)(?=\$)", str)
             key = {}
             # sheng cheng where zi duan
             for i in bd:
                 ti = i.split('=')
                 key[ti[0]] = "{}".format(ti[1])
             rcode = disk_control.diskCreate(name=key['name'],
                                             size=key['size'])
             if rcode == 200:
                 return {'code': 200}
         if type == 'delete':
             bd = re.findall("(?<=\$)(.+?)(?=\$)", str)
             key = {}
             # sheng cheng where zi duan
             for i in bd:
                 ti = i.split('=')
                 key[ti[0]] = "{}".format(ti[1])
             rcode = disk_control.diskDelete(UUID=key['UUID'])
             if rcode == 200:
                 return {'code': 200}
             else:
                 return {'error': 452}
         if type == 'resize':
             bd = re.findall("(?<=\$)(.+?)(?=\$)", str)
             key = {}
             # sheng cheng where zi duan
             for i in bd:
                 ti = i.split('=')
                 key[ti[0]] = "{}".format(ti[1])
             rcode = disk_control.diskResize(UUID=key['UUID'],
                                             size=key['size'])
             if rcode == 200:
                 return {'code': 200}
             else:
                 return rcode
     except Exception, msg:
         return {"error": 452}