1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
 
import pymongo
from Common import (mylog, CommFuncEx)
from DBCommon import (error)
DBConfig = __import__('Config.DBConfig')
 
 
    
def mongodbCheck(ip, port, expectVersion, expectBits):
    '''¼ì²âmongodb°æ±¾'''
    mylog.info('checking mongodb at %s:%s'%(ip, port))
    testCon = pymongo.Connection(ip, port)
    db_server_info = testCon.server_info()
    mylog.debug('db server_info:%s'%db_server_info)
    version = db_server_info['version']     
    if version < expectVersion:
        msg = error.formatMsg('fatal', error.ERROR_NO_3, 'mongodb version %s required!'%expectVersion)
        mylog.DeployError(msg, True)
        return
 
    
    bits = db_server_info['bits']
    if not (bits == expectBits):
        msg = error.formatMsg('fatal', error.ERROR_NO_4, 'mongodb %s-bits version required!'%expectBits)
        mylog.DeployError(msg, True)
        return
 
        
    mylog.info('check mongodb ok!')
       
def EnvCheck():
    mylog.info('-------------------------------------------------------------------------------------')
    mylog.info('checking environment....')
    
    mongodbCheck(DBConfig.USER_DB_IP, DBConfig.USER_DB_PORT, DBConfig.MongoDB_Ver, DBConfig.MongoDB_Bits)    
    
    mylog.info('check environment ok!')
    mylog.info('-------------------------------------------------------------------------------------')