40

来源:互联网 发布:php 转换为字符串 编辑:程序博客网 时间:2024/04/28 05:43
        real_db_tool.CloseDBCon();
        simu_db_tool.CloseDBCon();
        return -1,-1;
    iResult,str_real_ip = m_port_manager.GetInstance().GetRealIPBySimuIP(str_simu_ip);
    if (oErrorBase.base_succeed != iResult):
        PrintLog('m_port_manager GetRealIPBySimuIP failed',bprint);
        PrintLog('str_simu_ip = ' + str_simu_ip,bprint);
        real_db_tool.CloseDBCon();
        simu_db_tool.CloseDBCon();
        return -1,-1,
    iResult,int_real_id = real_db_tool.GetDevIDByDevIP(str_real_ip);
    if (oErrorBase.base_succeed != iResult):
        PrintLog('real GetDevIDByDevIP failed',bprint);
        PrintLog('str_real_ip = ' + str_real_ip,bprint);
        real_db_tool.CloseDBCon();
        simu_db_tool.CloseDBCon();
        return -1,-1;
    inter_match_manager.GetInstance().GetInterMatchFileDictByIP(str_real_ip);
    iResult,str_real_if_desc = inter_match_manager.GetInstance().GetRealIfDescBySIFromDic(str_simu_if_desc);
    if (oErrorBase.base_succeed != iResult):
        PrintLog('inter_match_manager GetRealIfDescBySIFromDic failed',bprint);
        PrintLog('str_simu_if_desc = ' + str_simu_if_desc,bprint);
        real_db_tool.CloseDBCon();
        simu_db_tool.CloseDBCon();
        return -1,-1;
    iResult,int_real_if_index = real_db_tool.GetIfIndexByIfDesc(int_real_id,str_real_if_desc);
    if (oErrorBase.base_succeed != iResult):
        PrintLog('simu GetIfIndexByIfDesc failed',bprint);
        PrintLog('int_real_id = ' + str(int_real_id),bprint);
        PrintLog('str_real_if_desc = ' + str_real_if_desc,bprint);
        real_db_tool.CloseDBCon();
        simu_db_tool.CloseDBCon();
        return -1,-1;
    if (int_real_if_index == -1):
        str_real_if_desc = str_real_if_desc + '(E1)';
        iResult,int_real_if_index = real_db_tool.GetIfIndexByIfDesc(int_real_id,str_real_if_desc);
        if (oErrorBase.base_succeed != iResult):
            PrintLog('simu GetIfIndexByIfDescE1 failed',bprint);
            PrintLog('int_real_id = ' + str(int_real_id),bprint);
            PrintLog('str_real_if_desc = ' + str_real_if_desc,bprint);
            real_db_tool.CloseDBCon();
            simu_db_tool.CloseDBCon();
            return -1,-1;
    real_db_tool.CloseDBCon();
    simu_db_tool.CloseDBCon();
    #os.chdir('./');
    PrintLog ('end to exec GetRealIfIndexBySimuInfo',bprint);
    return int_real_id, int_real_if_index;


def BIsFirstSync():
    file_sysparam = None;
    try:
        file_sysparam = open(dir.user_config_file_dir +'sys_param_tool.GetInstance().param.cfg','r');
    except Exception,e:
        print 'open sys_param_tool.GetInstance().param file failed';
        return oErrorBase.base_failed,False;
    str_line = file_sysparam.readline();
    if ('' == str_line):
        print 'sys_param_tool.GetInstance().param file has no content';
        file_sysparam.close();
        return oErrorBase.base_failed,False;
    if (1 == int(str_line)):
        file_sysparam.close();
        return oErrorBase.base_succeed,True;
    else:
        file_sysparam.close();
        return oErrorBase.base_succeed,False;


def ChangeFirstSync():
    file_sysparam = None;
    try:
        file_sysparam = open(dir.user_config_file_dir +'sys_param_tool.GetInstance().param.cfg','w');
    except Exception,e:
        print 'open sys_param_tool.GetInstance().param file failed';
        return oErrorBase.base_failed;
    file_sysparam.write('0');
    file_sysparam.close();
    return oErrorBase.base_succeed;


def ReadParamFromXml(p_str_param,p_file_name = 'sys_param.xml',p_str_param_type = 'int'):
    dom = None;
    try:
        dom = xml.dom.minidom.parse(dir.user_config_file_dir + p_file_name);
        root = dom.documentElement;
        oParam = root.getElementsByTagName(p_str_param);
        if ('int' == p_str_param_type):
            return int(oParam[0].childNodes[0].nodeValue);
        else:
            return str(oParam[0].childNodes[0].nodeValue);
    except Exception,e:
        print str(e);
        return 0;


def SetParamValueForXml(p_str_param,p_value,p_file_name = 'sys_param.xml'):
    try:
        dom = xml.dom.minidom.parse(dir.user_config_file_dir + p_file_name);
        root = dom.documentElement;
        oParam = root.getElementsByTagName(p_str_param);
        oParam[0].childNodes[0].nodeValue = p_value;
        writeFile = open(dir.user_config_file_dir + p_file_name, 'w+')
        writeFile.write(dom.toxml('utf-8'));
        writeFile.close();
    except Exception,e:
        print str(e);
        return oErrorBase.base_failed;
    return oErrorBase.base_succeed;




#*************************公共rest接口****************************
#类说明:rest操作通用工具类
#使用例子:my_resttool = PublicRestTool();
#my_resttool.InitRestInfo();
#my_resttool.PutIfStatus(3,203,'up');
#my_resttool.PutIfStatus(5,197,'down');
class PublicRestTool:


    def __init__(self):
        pass;
    
#方法说明:设置rest参数信息,在进行多次rest操作时需先调用一次
#参数:1.无
#返回值:无
    def InitRestInfo(self):
        PrintLog ('PublicRestTool:begin to exec InitRestInfo',bprint);
        #rest_tools.GetInstance().SetRestInfo(param_tool.GetInstance().param_rest_simulation.m_str_imc_user,param_tool.GetInstance().param_rest_simulation.m_str_imc_pw,param_tool.GetInstance().param_rest_simulation.m_str_imc_url);
        #rest_tools.GetInstance().SetRestInfo(param_tool.GetInstance().m_str_simu_imc_server_user,param_tool.GetInstance().m_str_simu_imc_server_pw,param_tool.GetInstance().m_str_simu_imc_server_ip + ':8080');
        #rest_tools.GetInstance().SetRestInfo('admin','admin','127.0.0.1:8080');
        PrintLog ('PublicRestTool:end to exec InitRestInfo',bprint);


    def InitRestInfoTest(self,user,pw,url):
        rest_tools.GetInstance().SetRestInfo(user,pw,url);


#方法说明:改变模拟设备接口状态
#参数:1.模拟设备ID,模拟设备接口索引,接口状态('up'或者'down')
#返回值:无
    def PutIfStatus(self,p_int_dev_id,p_int_if_index,p_str_if_status):
        PrintLog ('PublicRestTool:begin to exec PutIfStatus',bprint);
        str_api_url = '/imcrs/plat/res/device/' + str(p_int_dev_id) + '/interface/' + str(p_int_if_index) + '/' + p_str_if_status;
        rest_tools.GetInstance().SendRestOperation('PUT',str_api_url,'');
        PrintLog ('PublicRestTool:end to exec PutIfStatus',bprint);


    def GetDevCfg(self,p_int_dev_id):
        result = None;
        str_api_url = '/imcrs/icc/deviceCfg/' + str(p_int_dev_id) + '/currentStart';
        result,str_info =rest_tools.GetInstance().SendRestOperation('GET',str_api_url,'');
        return result,str_info;


    def AddDevToiMC(self,p_str_dev_ip):
        result = None;
        str_api_url = '/imcrs/plat/res/device';
        str_data =  {"ip":p_str_dev_ip,"nameOrIp":p_str_dev_ip};
        data_json = json.dumps(str_data);
        result,str_info = rest_tools.GetInstance().SendRestOperation('POST',str_api_url,data_json,'application/json');
        return result,str_info;


    def CreateViewWithDevs(self,p_hcl_view_id,p_str_view_name,p_dict_id_ip):
        result = None;
        str_api_url = '/imcrs/plat/res/view/custom';
        list_dict = [];
        for key in p_dict_id_ip:
            map_name = {};
0 0
原创粉丝点击