コード例 #1
0
ファイル: flushtables.py プロジェクト: qbaoma/web
 def FlushofGamelist(self):
     
     ''' No.1 clear table of gamelist '''
     localgamelist = DBSession.query(GameList).all()
     
     if len(localgamelist) != 0:
         for eachlist in range(len(localgamelist)):
             DBSession.delete(localgamelist[eachlist])
             
     DBSession.commit()
     
     ''' No.2 analyst Config and create conn '''
     self.getConfig = readFromConfigFile().get_config_zonelist('/WebserviceInterface/ServiceConfig/setting.ini')
     
     for eachTuple in range(len(self.getConfig['Zonelist'])):
         if self.getConfig['Zonelist'][eachTuple][0] == 'username':
             self.change['username'] = self.getConfig['Zonelist'][eachTuple][1]
         elif self.getConfig['Zonelist'][eachTuple][0] == 'password':
             self.change['password'] = self.getConfig['Zonelist'][eachTuple][1]
         elif self.getConfig['Zonelist'][eachTuple][0] == 'ipaddress':
             self.change['ipaddress'] = self.getConfig['Zonelist'][eachTuple][1]
         elif self.getConfig['Zonelist'][eachTuple][0] == 'port':
             self.change['port'] = int(self.getConfig['Zonelist'][eachTuple][1])
         elif self.getConfig['Zonelist'][eachTuple][0] == 'dbname':
             self.change['dbname'] = self.getConfig['Zonelist'][eachTuple][1]
         elif self.getConfig['Zonelist'][eachTuple][0] == 'tablename':
             self.change['tablename'] = self.getConfig['Zonelist'][eachTuple][1]
     
     (conn, cursor) = Connect().create(self.change)
     
     sql = 'select * from %s' % self.change['tablename']
     cursor.execute(sql)
     result=cursor.fetchall()
     for i in result:
         print i
コード例 #2
0
ファイル: orcl.py プロジェクト: qbaoma/web
    def Recovery(self):
        
        localAsset = DBSession.query(ASSET).all()

        if len(localAsset) > 100:
            for eachAsset in range(len(localAsset)):
                DBSession.delete(localAsset[eachAsset])
            DBSession.commit()
            
            self.flush(self.cursor)
        else:
            self.flush(self.cursor)
            
        self.cursor.close() 
        self.OracleConn.close()
コード例 #3
0
class DbHelper:

    def __init__(self):
        self.session = DBSession()

    # Method retrieves all countries from database.
    def get_countries(self):
        return self.session.query(Country)

    # Method retrieves a specific country by its ID.
    def get_country_by_id(self, country_id):
        return self.session.query(Country).filter_by(id=country_id).first()

    # Method retrieves all attractions associated to a specific country.
    def get_attractions(self, country_id):
        return self.session.query(Attraction).filter_by(
            country_id=country_id).all()

    # Method retrieves a specific attractions by its ID.
    def get_attraction_by_id(self, attraction_id):
        return self.session.query(Attraction).filter_by(id=attraction_id) \
            .first()

    # Method adds entry to the database.
    def add_to_db(self, element):
        self.session.add(element)
        self.session.commit()

    # Method removes an entry from the database,
    def delete_from_database(self, element):
        self.session.delete(element)
        self.session.commit()

    # Method removes all attractions associated to a specific country.
    def delete_attractions_by_country_id(self, country_id):
        self.session.query(Attraction).filter_by(
            country_id=country_id).delete()
        self.session.commit()

    # Method retrieves a specific user by its e-mail.
    def get_user_by_email(self, email):
        return self.session.query(User).filter_by(email=email).first()
コード例 #4
0
ファイル: flushtables.py プロジェクト: qbaoma/web
    def getFlushoftable(self, signal='ALL'):
        
        # No.1 clear table of gamename
        localGameName = DBSession.query(Gameinform).all()
        
        if len(localGameName) != 0:
            for eachGamename in range(len(localGameName)):
                DBSession.delete(localGameName[eachGamename])
        
        DBSession.commit()
       
        # No.2 get each Game information & fill in table
       
        self.flush = Urlex().getInformationMultiple(signal)
    
        for key,value in self.flush.items():
            if key != 'NULL':
                DBSession.add(Gameinform(self.count, key, value['ipaddress'], value['port'], value['dbname']))
                self.count += 1

        DBSession.commit()
コード例 #5
0
ファイル: oidDetail.py プロジェクト: qbaoma/web
    def DetailforEachOid(self, name, message):
        
        # Oid = 1.1
        if name == 'insert':
            
            ''' Step 1. All information about input detail '''
            tmpProjectName = ""
            tmpProjectFunc = ""
            tmpKernel = ""
            tmpCpuCoreNum = ""
            tmpSerialNum = ""
            tmpZCBM = ""
            tmpMemory = ""
            tmpCpuType = ""
            tmpModel = ""
            tmpHostName = ""
            tmpOS = ""
            tmpManufacturer = ""
            tmpEthInfo = {}
            tmpTimestamp = int(round(time.time()))
            Resultofbody = {}
            
            for key,value in message.items():
                if key == 'Status':
                    if value != 'Success':
                        return dict(Status='False', msg='Message check Failed.')
            
            if type(message['Result']).__name__ == 'str':
                Resultofbody = changeDict().strtodict(message['Result'])
            else:
                Resultofbody = message['Result']
 
            for keys,values in Resultofbody.items():
                if keys == 'Project':
                    for K,V in Resultofbody[keys].items():
                        if K == 'Name':
                            tmpProjectName = self.changestr(V)
                        elif K == 'Func':
                            tmpProjectFunc = self.changestr(V)
                    
                elif keys == 'HwInfo':
                    for KK,VV in Resultofbody[keys].items():
                        if KK == 'Kernel':
                            tmpKernel = self.changestr(VV)
                        elif KK == 'CpuCoreNum':
                            tmpCpuCoreNum = self.changestr(VV)
                        elif KK == 'SN':
                            tmpSerialNum = self.changestr(VV)
                        elif KK == 'ZCBM':
                            tmpZCBM = self.changestr(VV)
                        elif KK == 'Memory':
                            tmpMemory = self.changestr(VV)
                        elif KK == 'CpuType':
                            tmpCpuType = self.changestr(VV)
                        elif KK == 'Model':
                            tmpModel = self.changestr(VV)
                        elif KK == 'HostName':
                            tmpHostName = self.changestr(VV)
                        elif KK == 'OS':
                            tmpOS = self.changestr(VV)
                        elif KK == 'Manufacturer':
                            tmpManufacturer = self.changestr(VV)
                            
                    
                elif keys == 'EthInfo':
                    
                    for eachline in Resultofbody[keys]:
                        tmpStatus = ''
                        tmpip = ''
                        tmpmask = ''
                        tmpethname = ''
                        for KKK, VVV in eachline.items():
                            if KKK == 'status':
                                tmpStatus = self.changestr(VVV)
                            elif KKK == 'ip':
                                tmpip = self.changestr(VVV)
                            elif KKK == 'mask':
                                tmpmask = self.changestr(VVV)
                            elif KKK == 'ethname':
                                tmpethname = self.changestr(VVV)
                                
                        tmpEthInfo[tmpethname] = dict(status=tmpStatus, ip=tmpip, mask=tmpmask)

            if tmpZCBM == '':
                return dict(Status='False', msg='Input Server has not ZCBM.')

            ''' get eth detail '''
            tmpEthDict = {}
            for key,value in tmpEthInfo.items():
                if key == 'eth0':
                    getSearchofeth = DBSession.query(Ethdetail).filter(Ethdetail.ip == value['ip'], Ethdetail.mask == value['mask']).first()
                    if getSearchofeth:
                        tmpEthDict['eth0'] = getSearchofeth.eid
                    else:
                        getethcount = DBSession.query(Ethdetail).count()
                        getethcount = (getethcount + 1)
                        DBSession.add(Ethdetail(getethcount,value['status'],value['ip'],value['mask'],'eth0'))
                        tmpEthDict['eth0'] = getethcount
                elif key == 'eth1':
                    getSearchofethone = DBSession.query(Ethdetail).filter(Ethdetail.ip == value['ip'], Ethdetail.mask == value['mask']).first()
                    if getSearchofethone:
                        tmpEthDict['eth1'] = getSearchofethone.eid
                    else:
                        getethcountone = DBSession.query(Ethdetail).count()
                        getethcountone = (getethcountone + 1)
                        DBSession.add(Ethdetail(getethcountone,value['status'],value['ip'],value['mask'],'eth1'))
                        tmpEthDict['eth1'] = getethcountone

            ''' Step 2. check server information exist. '''
            getSearchofHardware = DBSession.query(AssetForAgent).filter(AssetForAgent.ZCBM == tmpZCBM).first()
            if getSearchofHardware:
                try:
                    if int(getSearchofHardware.Timestamp) < message['SendTime']:

                        DBSession.delete(getSearchofHardware)
                        DBSession.commit()
                        
                        tmpeth0 = ""
                        tmpeth1 = ""
                        
                        for key,value in tmpEthDict.items():
                            if key == 'eth0':
                                tmpeth0 = value
                            elif key == 'eth1':
                                tmpeth1 = value
                        getCountofeth = DBSession.query(EthInfo).count()
                        getCountofeth = (getCountofeth + 1)
                        DBSession.add(EthInfo(getCountofeth,tmpeth0,tmpeth1,'None','None'))
                        
                        DBSession.add(AssetForAgent(tmpProjectName, tmpProjectFunc, tmpKernel, tmpCpuCoreNum, tmpSerialNum, tmpZCBM, tmpMemory, tmpCpuType, tmpModel, tmpHostName, tmpOS, tmpManufacturer, message['SendTime']))
                        DBSession.commit()
                        
                        getTmpid = DBSession.query(AssetForAgent).filter_by(ZCBM = tmpZCBM).first()
                        if getTmpid:
                            Tmpid = getTmpid.Hid
                        else:
                            DBSession.rollback()
                            return dict(Status='False', msg='flush assetforagent Error.')
                        
                        getCountofrelation = DBSession.query(AssetidtoEid).count()
                        getCountofrelation = int(getCountofrelation + 1)
                        DBSession.add(AssetidtoEid(getCountofrelation, Tmpid, getCountofeth))
                        
                        DBSession.commit()
                        return dict(Status='Success')
                        
                    else:
                        return dict(Status='Success', msg='Input Hostname Need not fresh.')
                    
                except Exception, e:
                    DBSession.commit()
                    return dict(Status='False', msg=str(e))
            else:
                try:
                    tmpHidforinsert = ""
                    
                    ''' insert into table'''
                    DBSession.add(AssetForAgent(tmpProjectName, tmpProjectFunc, tmpKernel, tmpCpuCoreNum, tmpSerialNum, tmpZCBM, tmpMemory, tmpCpuType, tmpModel, tmpHostName, tmpOS, tmpManufacturer, message['SendTime']))
                    DBSession.commit()
                    
                    getHid = DBSession.query(AssetForAgent).filter_by(ZCBM = tmpZCBM).first()
                    if getHid:
                        tmpHidforinsert = getHid.Hid
                    else:
                        DBSession.rollback()
                        return dict(Status='False', msg='insert into assetforagent error.')
                    
                    for key,value in tmpEthDict.items():
                        if key == 'eth0':
                            tmpeth0 = value
                        elif key == 'eth1':
                            tmpeth1 = value
                    getCountofeth = DBSession.query(EthInfo).count()
                    getCountofeth = (getCountofeth + 1)
                    DBSession.add(EthInfo(getCountofeth,tmpeth0,tmpeth1,'None','None'))
                    
                    getCountofrelation = DBSession.query(AssetidtoEid).count()
                    getCountofrelation = int(getCountofrelation + 1)
                    DBSession.add(AssetidtoEid(getCountofrelation, tmpHidforinsert, getCountofeth))
                
                except Exception, e:
                    DBSession.rollback()
                    return dict(Status='False', msg=str(e))
                
                DBSession.commit()
                return dict(Status='Success')