38

来源:互联网 发布:php安装教程 编辑:程序博客网 时间:2024/04/29 13:49
        log_manager.GetInstance().CoutLog('param_tool:begin to exec CreateTopoIPRelationFile',Com_user_param_manager);
        simu_db_tool = db_tools();
        simu_db_tool.SetDBInfo(self.m_str_simu_db_ip,self.m_str_simu_db_user,self.m_str_simu_db_pw);
        iResult = simu_db_tool.OpenDBCon('config_db');
        if (oErrorBase.base_succeed != iResult):
            return iResult;
        real_db_tool = db_tools();
        real_db_tool.SetDBInfo(self.m_str_real_db_ip,self.m_str_real_db_user,self.m_str_real_db_pw);
        iResult = real_db_tool.OpenDBCon('config_db');
        if (oErrorBase.base_succeed != iResult):
            return iResult;
        t_list_str_route = self.m_list_str_route;
        t_str_manager_net = '';
        t_str_manager_net_mask = self.m_str_manager_net_mask;
        iResult,t_list_real_ip = real_db_tool.GetDevIPListByTopoName(self.m_str_real_topo_name.encode('iso8859-1'));
        if (oErrorBase.base_succeed != iResult):
            log_manager.GetInstance().CoutLog('get real ip list from db failed',Com_user_param_manager);
            return iResult;
        t_dic_ip_relation = {};
        common_tools.GetInstance().GetIPRelationDic(t_dic_ip_relation,t_list_real_ip,self.m_str_start_ip,self.m_str_end_ip,t_str_manager_net_mask);
        print 't_dic_ip_relation = ';
        print t_dic_ip_relation;
        my_file = None;
        try:
            my_file = open ((dir.output_config_file_dir + self.m_str_real_topo_name.decode('UTF-8').encode('iso8859-1') + 'm_port_info.cfg'),'w+');
        except Exception, e:
            log_manager.GetInstance().CoutLog(('output_config/' + self.m_str_real_topo_name + 'm_port_info.cfg').decode('GBK'),Com_user_param_manager);
            return oErrorBase.base_failed;
        if my_file:
            for elem in t_list_str_route:
                my_file.write('route:'+ elem + '\n');
            my_file.write('mask:' + t_str_manager_net_mask +  '\n');
            for key in t_dic_ip_relation:
                my_file.write(key + ' ' + t_dic_ip_relation[key] + '\n');
            my_file.close();
        log_manager.GetInstance().CoutLog('param_tool:end to exec CreateTopoIPRelationFile',Com_user_param_manager);
        return oErrorBase.base_succeed;


    def BasicParamInit(self):
    #老数据库参数
        self.param_db_real.m_str_db_ip = self.m_str_real_db_ip;
        self.param_db_real.m_str_db_user = self.m_str_real_db_user;
        self.param_db_real.m_str_db_pw = self.m_str_real_db_pw;
        self.param_db_real.m_str_db_topo_name = self.m_str_real_topo_name.encode('iso8859-1');


        self.param_db_simulation.m_str_db_ip = self.m_str_simu_db_ip;
        self.param_db_simulation.m_str_db_user = self.m_str_simu_db_user;
        self.param_db_simulation.m_str_db_pw = self.m_str_simu_db_pw;
        self.param_db_simulation.m_str_db_topo_name = self.m_str_real_topo_name.encode('iso8859-1');


    #HCL配置文件信息
        self.param_hcl.m_list_hcl_param = self.m_list_hcl_param;


    #新iMC rest接口参数
        self.param_rest_simulation.m_str_imc_url = self.m_str_simu_imc_server_ip + ':8080';
        self.param_rest_simulation.m_str_imc_user = self.m_str_simu_imc_server_user;
        self.param_rest_simulation.m_str_imc_pw = self.m_str_simu_imc_server_pw;




**********************************


文件名:scdllib.py
**********************************
# -*- coding: utf-8 -*-


#版本1.00
#更新日期:2016.1.14
#更新内容:
#1.文件底部增加了rest操作类,实现了rest操作接口状态
#2.增加了内部使用的简单日志函数


#**********四川电力通用外部接口**********
#使用方法:放到自己的工作目录下,在需要使用的文件中from scdllib import *
import os;
from conf_modify.db_tools import *;
from conf_modify.m_port_manager import *;
from conf_modify.inter_match_manager import *;
from conf_modify.rest_tools import *;
from conf_modify.error_manager import *;
from conf_modify.data_struct_manager import *;
import json;
import xml.dom.minidom;


#********************工具内部使用的方法和全局参数*************************
bprint = 1;#是否打印日志,1为打印,其他为不打印


#方法说明:输出日志,限本文件内部使用
#参数:1.日志内容,是否输出
#返回值:无
def PrintLog(p_str_log,p_int_bprint):
    if (1 == p_int_bprint):
        print p_str_log;
#*************************************************************


#方法说明:获取模拟设备的设备ID
#参数:1.真实设备ID
#返回值:模拟设备ID
def GetSimuDevIDByRealDevID(p_int_dev_id):
    iResult = oErrorBase.base_succeed;
    PrintLog ('begin to exec GetSimuDevIDByRealDevID',bprint);
    #os.chdir('./conf_modify/');
    m_port_manager.GetInstance().DateInitFromFile(param_tool.GetInstance().param_db_real.m_str_db_topo_name + 'm_port_info.cfg');
    real_db_tool = db_tools();
    simu_db_tool = db_tools();
    real_db_tool.SetDBInfo(param_tool.GetInstance().param_db_real.m_str_db_ip,param_tool.GetInstance().param_db_real.m_str_db_user,param_tool.GetInstance().param_db_real.m_str_db_pw);
    simu_db_tool.SetDBInfo(param_tool.GetInstance().param_db_simulation.m_str_db_ip,param_tool.GetInstance().param_db_simulation.m_str_db_user,param_tool.GetInstance().param_db_simulation.m_str_db_pw);
    real_db_tool.OpenDBCon('config_db');
    simu_db_tool.OpenDBCon('config_db');
    iResult,str_dev_ip = real_db_tool.GetDevIPByDevID(p_int_dev_id);
    if (oErrorBase.base_succeed != iResult):
        PrintLog ('real GetDevIPByDevID failed',bprint);
        PrintLog ('dev_id = ' + str(p_int_dev_id),bprint);
        real_db_tool.CloseDBCon();
        simu_db_tool.CloseDBCon();
        return -1;
    str_simu_ip = m_port_manager.GetInstance().GetMPort(str_dev_ip);
    if ('' != iResult):
        PrintLog('m_port_manager GetMPort failed',bprint);
        PrintLog('str_dev_ip = ' +str_dev_ip,bprint);
        real_db_tool.CloseDBCon();
        simu_db_tool.CloseDBCon();
        return -1;
    iResult,int_simu_id = simu_db_tool.GetDevIDByDevIP(str_simu_ip);
    if (oErrorBase.base_succeed != iResult):
        PrintLog('simu GetDevIDByDevIP failed',bprint);
        PrintLog('str_simu_ip = ' + str_simu_ip,bprint);
        real_db_tool.CloseDBCon();
        simu_db_tool.CloseDBCon();
        return -1;
    real_db_tool.CloseDBCon();
    simu_db_tool.CloseDBCon();
    #os.chdir('./');
    PrintLog ('end to exec GetSimuDevIDByRealDevID',bprint);
    return int_simu_id;


#方法说明:获取模拟设备的IP
#参数:1.真实设备IP
#返回值:模拟设备IP
def GetSimuDevIPByRealDevIP(p_str_dev_ip):
    PrintLog ('begin to exec GetSimuDevIPByRealDevIP',bprint);
    m_port_manager.GetInstance().DateInitFromFile(param_tool.GetInstance().param_db_real.m_str_db_topo_name + 'm_port_info.cfg');
    str_simu_ip = m_port_manager.GetInstance().GetMPort(p_str_dev_ip);
    PrintLog ('end to exec GetSimuDevIPByRealDevIP',bprint);
    return str_simu_ip;


#方法说明:获取模拟设备的接口索引
#参数:1.真实设备ID,真实接口索引
#返回值:模拟设备索引
def GetSimuIfIndexByRealInfo(p_int_dev_id,p_int_if_index):
    PrintLog ('begin to exec GetSimuIfIndexByRealInfo',bprint);
    iResult = oErrorBase.base_succeed;
    m_port_manager.GetInstance().DateInitFromFile(param_tool.GetInstance().param_db_real.m_str_db_topo_name + 'm_port_info.cfg');
    real_db_tool = db_tools();
    simu_db_tool = db_tools();
0 0
原创粉丝点击