Beispiel #1
0
def test_script(obj):
    """
    obj = MsgWorklistExecute
    default function name= test_script    
    """
    ret_worklist = ERR_FAIL  # default
    ret_rpc = ERR_FAIL
    ret_datas = ""
    sn = obj.sn
    # data传参
    ParameterNames = [
        "InternetGatewayDevice.DeviceInfo.X_CT-COM_TeleComAccount.Password"
    ]

    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            log.app_info("Auto process get parameter values: %s " %
                         ParameterNames)
            ret_rpc, ret_data = u1.get_parameter_values(
                ParameterNames=ParameterNames)

            if (ret_rpc == ERR_SUCCESS):
                log.app_info("success:%s" % ret_data)

                # {'ParameterList': [{'Value_type': 'string', 'Name': 'InternetGatewayDevice.DeviceInfo.X_CT-COM_TeleComAccount.Password', 'Value': 'admin'}]}
                parameter_list = ret_data.get("ParameterList")
                d0 = parameter_list[0]
                ret_datas = d0.get("Value")
            else:
                ret_datas = str(ret_data)  # fail, is dict
                log.app_err("fail:%s" % ret_data)
                break

            ret_worklist = ERR_SUCCESS

        except Exception, e:
            log.app_err(e)
            break
Beispiel #2
0
def test_script(obj):
    """
    obj = MsgWorklistExecute
    default function name= test_script    
    """

    ret_worklist = ERR_FAIL  # 工单执行结果,默认为FAIL
    ret_rpc = ERR_FAIL  # RPC方法执行结果,默认为FAIL
    ret_datas = ""  # 初始化执行成功的返回信息
    sn = obj.sn

    # 根路径,在该路径下查找上网账号和密码的节点全路径
    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    # 上网账号和密码的正则表达式
    regex_user_name_path = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice\.\d+\.WANPPPConnection\.\d+\.Username"
    regex_password_path = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice\.\d+\.WANPPPConnection\.\d+\.Password"
    find_user_name_path = False  # 是否找到上网账号节点路径的标志,默认为False
    find_password_path = False  # 是否找到上网密码节点路径的标志,默认为False
    user_name_path = ""  # 用于保存上网账号节点路径
    password_path = ""  # 用于保存上网密码几多路径

    for nwf in [1]:

        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            # reboot_Yes = 0

            # 第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_datas += info

            ret_rpc, ret_data = u1.get_parameter_names(ParameterPath=ROOT_PATH)
            if (ret_rpc == ERR_SUCCESS):
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_datas += info

                # 从查询结果中筛选上网账号和密码的路径
                for tmp_dict in ret_data['ParameterList']:

                    if re.search(regex_user_name_path,
                                 tmp_dict['Name']) is not None:
                        find_user_name_path = True
                        user_name_path = tmp_dict['Name']

                    if re.search(regex_password_path,
                                 tmp_dict['Name']) is not None:
                        find_password_path = True
                        password_path = tmp_dict['Name']

                    if find_user_name_path and find_password_path:
                        break
                else:
                    # 没有找到匹配的路径,说明没有相应的节点,直接返回
                    info = u"没有找到上网账号和密码的节点路径.\n"
                    log.app_info(info)
                    ret_datas += info
                    break

                # 找到相应的节点路径,获取节点路径的值
                list_path = [user_name_path, password_path]
                ret_rpc, ret_data = u1.get_parameter_values(
                    ParameterNames=list_path)
                if (ret_rpc == ERR_SUCCESS):
                    # TODO:如果以后需要返回查询到的值,可以返回ret_data进行解析
                    info = u"查询终端上网账号和密码成功. %s\n" % ret_data
                    log.app_info(info)
                    ret_datas += info
                    ret_datas += str(ret_data)

                    obj.dict_ret["str_result"] = ret_datas
                else:
                    info = u"查询终端上网账号和密码失败.\n %s \n" % ret_data
                    log.app_err(info)
                    ret_datas += info
                    break
            else:
                # 对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data
                log.app_err(info)
                ret_datas += info
                break

            ret_worklist = ERR_SUCCESS

        except Exception, e:
            log.app_err(e)
            break
Beispiel #3
0
def WANSetUP(obj,
             sn,
             WANEnable_Switch,
             DeviceType,
             AccessMode,
             PVC_OR_VLAN,
             dict_wanlinkconfig={},
             dict_wanpppconnection={},
             dict_wanipconnection={},
             change_account=1,
             rollbacklist=[]):
    ret_res = ERR_FAIL  # 返回成功或失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            # 第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info
            # sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=1)
            if ret_root == ERR_SUCCESS:
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                # 对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 第二步:逐个查找
            path2 = ''  # 保存查到有相同的PVC或关键参数值的WAN连接路径
            path2_1 = ''  # 保存WANPPPConnection或WANIPConnection节点路径保存,后面修改参数时有用
            # 是否有查到已存在的类似WAN连接的状态位,符合以下标识,桥只关心PVC,其他的只关心X_CU_ServiceList
            # 0 Username和X_CU_ServiceList均相同
            # 1 Username和X_CU_ServiceList均不相同
            # 2 Username相同,X_CU_ServiceList不相同
            # 3 Username不相同,X_CU_ServiceList相同
            WAN_Flag = None
            # 如果是桥连接,则只查PVC,其他的查X_CU_ServiceList是否有相同的
            if AccessMode == 'PPPoE' or AccessMode == 'DHCP' or AccessMode == 'Static' or AccessMode == 'PPPoE_Bridged':
                # 注意是调GetParameterNames,不同于桥时直接调GetParameterValues查值
                ret_tmp_path2 = []
                for i in xrange(len(ret_data_root['ParameterList'])):
                    # 不同的WAN连接模式,其节点路径不同
                    if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                        tmp_path2 = ret_data_root['ParameterList'][i][
                            'Name'] + 'WANPPPConnection.'
                        X_CU_COM_ServiceList = dict_wanpppconnection[
                            'X_CU_ServiceList'][1]
                        ConnectionType = dict_wanpppconnection[
                            'ConnectionType'][1]
                        info = u"开始调用GetParameterNames查找第%s条WAN连接WANPPPConnection实例\n" % str(
                            i + 1)
                    elif AccessMode == 'DHCP' or AccessMode == 'Static':
                        tmp_path2 = ret_data_root['ParameterList'][i][
                            'Name'] + 'WANIPConnection.'
                        X_CU_COM_ServiceList = dict_wanipconnection[
                            'X_CU_ServiceList'][1]
                        ConnectionType = dict_wanipconnection[
                            'ConnectionType'][1]
                        info = u"开始调用GetParameterNames查找第%s条WAN连接WANIPConnection实例\n" % str(
                            i + 1)
                    log.app_info(info)
                    ret_data_scr += info
                    # sleep(3)
                    ret2, ret_data2 = u1.get_parameter_names(
                        ParameterPath=tmp_path2, NextLevel=1)
                    if ret2 == ERR_SUCCESS:
                        info = u"查找第%s条WAN连接实例成功\n" % str(i + 1)
                        log.app_info(info)
                        ret_data_scr += info
                        # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                        ret_data2 = DelOwnParameterNames(ret_data2, tmp_path2)

                        if ret_data2['ParameterList']:
                            for tmp_index in xrange(
                                    len(ret_data2['ParameterList'])):
                                ret_tmp_path2.append(ret_data2['ParameterList']
                                                     [tmp_index]['Name'])
                    else:
                        # 对于失败的情况,直接退出
                        info = u"查找第%s条WAN连接实例失败,错误信息: %s\n" % (str(i + 1),
                                                                ret_data2)
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
                # 第2.2步,对于PPPOE查找X_CU_ServiceList和Username值.
                # 由于贝曼有些版本只查X_CU_ServiceList,或者查到Username相同与否不影响判断结果,
                # 所以目前只支持查X_CU_ServiceList
                for i in xrange(len(ret_tmp_path2)):
                    info = u"开始调用GetParameterValues查找第%s个WAN连接实例下的X_CU_ServiceList值\n" % str(
                        i + 1)
                    log.app_info(info)
                    ret_data_scr += info

                    tmp_path2_2 = []
                    tmp_path2_2.append(ret_tmp_path2[i] + 'X_CU_ServiceList')
                    # GCW 20130410对桥模式单独处理,避免修改PPPOE INTERNET为桥 INTERNET的情况
                    tmp_path2_2.append(ret_tmp_path2[i] + 'ConnectionType')
                    # sleep(3)
                    ret2_2, ret_data2_2 = u1.get_parameter_values(
                        ParameterNames=tmp_path2_2)
                    if ret2_2 == ERR_SUCCESS:
                        info = u"查找第%s个WAN连接实例下的X_CU_ServiceList和ConnectionType值成功,返回:%s\n" % (
                            str(i + 1), ret_data2_2)
                        log.app_info(info)
                        ret_data_scr += info
                        # 判断值是否相等,相等(或被包含)则只修改linkconfig节点的值即可,否则需走后面的正常流程新建WAN连接
                        if AccessMode == "PPPoE_Bridged":
                            ConnectionType = "PPPoE_Bridged"
                        else:
                            ConnectionType = "IP_Routed"

                        # GCW 20130417 路由对路由比较,桥对桥的比较才更合理
                        if ConnectionType == ret_data2_2['ParameterList'][0]['Value'] or \
                           ConnectionType == ret_data2_2['ParameterList'][1]['Value']:
                            # 如果非完全不相等,则需做特殊处理
                            if (ret_data2_2['ParameterList'][0]['Value'] in X_CU_COM_ServiceList \
                                    or ret_data2_2['ParameterList'][1]['Value'] in X_CU_COM_ServiceList) \
                                or (X_CU_COM_ServiceList in ret_data2_2['ParameterList'][0]['Value'] \
                                    or X_CU_COM_ServiceList in ret_data2_2['ParameterList'][1]['Value']):
                                # GCW 20130408 判断X_CU_ServiceList包含与被包含的关系做区分处理.
                                if (ret_data2_2['ParameterList'][0]['Value'] in X_CU_COM_ServiceList \
                                  or ret_data2_2['ParameterList'][1]['Value'] in X_CU_COM_ServiceList):
                                    info = u"当前CPE中的X_CU_ServiceList值包含于工单中要求的X_CU_ServiceList值:%s,\n" % X_CU_COM_ServiceList
                                    info += u"走修改WAN连接的流程,且重新下发X_CU_ServiceList值的修改\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 0  # 表示CPE当前值包含于工单,走修改WAN流程,且X_CU_ServiceList需下发
                                else:
                                    info = u"当前工单中的X_CU_ServiceList值:%s包含于CPE中的X_CU_ServiceList值,\n" % X_CU_COM_ServiceList
                                    info += u"走修改WAN连接流程,但不下发对X_CU_ServiceList值的修改.\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 3  # 表示工单中的值包含于当前CPE中,走修改WAN流程,但X_CU_ServiceList不需下发
                                path2_1 = ret_tmp_path2[i]
                                # 将上一层路径保存并退出循环,留给下一步直接修改linkconfig参数
                                # ret_tmp_path2[i]类似于InternetGatewayDevice.WANDevice.1.WANConnectionDevice.3.WANPPPConnection.1.
                                a = ret_tmp_path2[i].split('.')
                                for i in xrange(len(a) - 3):
                                    path2 += a[i]
                                    path2 += '.'  # 将当前的WANConnectionDevice.节点路径保存,后面修改参数时有用
                                break
                            else:
                                continue
                        else:
                            continue
                    else:
                        info = u"查找第%s个WAN连接实例下的X_CU_ServiceList值失败,返回:%s\n" % (
                            str(i + 1), ret_data2_2)
                        log.app_info(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
                if WAN_Flag == None:
                    info = u"查找不到匹配 %s 模式的WAN连接\n" % X_CU_COM_ServiceList
                    log.app_info(info)
                    ret_data_scr += info
                    WAN_Flag = 1
            else:
                info = u"输入的AccessMode参数不合法,请检查!\n"
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            # 0 均相同,只修改LinkConfig.(参考a.1包)
            # 1 两者均不相同的情况下:等同于查到是空的情况,后续新建WAN连接参考a.2包)
            # 2 部分相同,而且关键点X_CU_ServiceList不相同的情况下:等同于查到是空的情况,后续新建WAN连接(参考a.3包)
            # 3 部分相同,而且关键点X_CU_ServiceList相同的情况下:等同于查到均相同的情况,只修改LinkConfig.(参考a.4包)
            if WAN_Flag == 1 or WAN_Flag == 2:
                # 第三--一步:新建WANConnectionDevice实例
                info = u"走X_CU_ServiceList不相同的流程(新建WAN连接).\n"
                log.app_info(info)
                ret_data_scr += info

                # 解决用户新建tr069WAN连接导致CPE与ACS通讯异常的问题,强制不准新建包含TR0069的WAN连接

                if (("tr069" in X_CU_COM_ServiceList)
                        or ("TR069" in X_CU_COM_ServiceList)):
                    info = u"工单失败:为避免新建包含tr069模式的WAN连接对原有tr069WAN连接产生影响,所以不再新建.\n"
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                info = u"开始调用AddObject新建WANConnectionDevice实例\n"
                log.app_info(info)
                ret_data_scr += info

                Classpath = ROOT_PATH
                # sleep(3)  # must be ;otherwise exception
                ret3, ret_data3 = u1.add_object(ObjectName=Classpath)
                if ret3 == ERR_SUCCESS:
                    instanceNum1 = ret_data3["InstanceNumber"]
                    info = u"新建WANConnectionDevice实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    tmp_path3 = Classpath + instanceNum1 + '.'
                    # GCW 20130327 增加回退机制
                    rollbacklist.append(tmp_path3)
                    rebootFlag = int(ret_data3["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"新建WANConnectionDevice实例失败,错误原因:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--二步:新建WANIPConnection或WANPPPConnection实例
                # 只有是桥模式和路由PPPOE时,才新建WANPPPConnection实例
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    path4 = ROOT_PATH + instanceNum1 + '.WANPPPConnection.'
                    info = u"开始调用AddObject新建WAN连接的WANPPPConnection实例\n"
                else:
                    path4 = ROOT_PATH + instanceNum1 + '.WANIPConnection.'
                    info = u"开始调用AddObject新建WAN连接的WANIPConnection实例\n"
                log.app_info(info)
                ret_data_scr += info

                # sleep(3)  # must be ;otherwise exception
                ret4, ret_data4 = u1.add_object(ObjectName=path4)

                if ret4 == ERR_SUCCESS:
                    instanceNum1 = ret_data4["InstanceNumber"]
                    tmp_path4 = path4 + instanceNum1
                    info = u"新建实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data4["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"新建实例实例失败,退出执行,错误原因:%s\n" % ret_data4
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--三步:调用SetParameterValues设置linkconfig参数:
                """
                if DeviceType == 'ADSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n"
                elif DeviceType == 'LAN':
                    path5 = tmp_path3 + 'WANEthernetLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANEthernetLinkConfig参数\n"
                elif DeviceType == 'EPON':
                    path5 = tmp_path3 + 'X_CU_WANEponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANEponLinkConfig参数\n"
                elif DeviceType == 'VDSL':
                    path5 = tmp_path3 + 'X_CU_WANVdslLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANVdslLinkConfig参数\n"
                elif DeviceType == 'GPON':
                    path5 = tmp_path3 + 'X_CU_WANGponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANGponLinkConfig参数\n"
                else:
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n"
                log.app_info(info)
                ret_data_scr += info
                """
                info = u"开始调用SetParameterValues设置参数\n"
                log.app_info(info)
                ret_data_scr += info
                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        tmp_path = tmp_path3 + i
                        para_list5.append(
                            dict(Name=tmp_path,
                                 Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    ret_data = u"参数列表为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                # sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(
                    ParameterList=para_list5)
                if ret5 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s\n" % ret_data5
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                log.app_info(info)
                ret_data_scr += info

                # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = tmp_path4 + '.'
                para_list6 = []
                WAN_Enable = []
                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        # 如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    ret_data = u"参数列表为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if ret6 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 将WAN连接使能单独下发
                if WAN_Enable:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    # sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if ret_wan_enable == ERR_SUCCESS:
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if rebootFlag == 1:
                            reboot_Yes = 1
                    else:
                        # 对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            elif WAN_Flag == 0 or WAN_Flag == 3:
                # 当查到有相匹配的X_CU_ServiceList和Username值时的处理流程,不需要新建,只需更改WANIPConnection或WANPPPConnection节点下的参数即可
                # 第三--三步:调用SetParameterValues设置linkconfig参数:
                """
                if DeviceType == 'ADSL':
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                elif DeviceType == 'LAN':
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANEthernetLinkConfig参数\n"
                    path5 = path2 + 'WANEthernetLinkConfig.'
                elif DeviceType == 'EPON':
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CU_WANEponLinkConfig参数\n"
                    path5 = path2 + 'X_CU_WANEponLinkConfig.'                
                elif DeviceType == 'VDSL':
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CU_WANVdslLinkConfig参数\n"
                    path5 = path2 + 'X_CU_WANVdslLinkConfig.'
                elif DeviceType == 'GPON':
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CU_WANGponLinkConfig参数\n"
                    path5 = path2 + 'X_CU_WANGponLinkConfig.'
                else:
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                log.app_info (info)
                ret_data_scr += info
                """
                info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改参数\n"
                log.app_info(info)
                ret_data_scr += info
                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        # 对于Linkconfig的PVC或VLAN节点删除,不做修改
                        # GCW 20130418 修改WAN连接参数时,对X_CU_Mode节点也不修改
                        if i == 'DestinationAddress' or i == 'VLANIDMark' or \
                           i == 'X_CU_VLAN' or i == "X_CU_Mode":
                            continue
                        tmp_path = path2 + i
                        para_list5.append(
                            dict(Name=tmp_path,
                                 Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    info = u"参数列表为空,请检查\n"
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                # sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(
                    ParameterList=para_list5)
                if ret5 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s\n" % ret_data5
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 修改SetParameterValues设置WANPPPConnection参数
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                    log.app_info(info)
                    ret_data_scr += info

                # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = path2_1
                para_list6 = []
                WAN_Enable = []

                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        # GCW 20130408 判断X_CU_ServiceList包含与被包含的关系做区分处理.
                        # 标志位0表示X_CU_ServiceList值需以工单中的为准,重新下发,3表示不下发
                        if WAN_Flag == 0:
                            pass
                        else:
                            if i == 'X_CU_ServiceList':
                                continue
                        # 如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    return ret_res, ret_data_scr

                # sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if ret6 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 将WAN连接使能单独下发
                if WAN_Enable:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    # sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if ret_wan_enable == ERR_SUCCESS:
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if rebootFlag == 1:
                            reboot_Yes = 1
                    else:
                        # 对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if reboot_Yes == 1:

                # sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if ret != ERR_SUCCESS:
                    ret_data_scr += ret_data
                    break

            # 第七步:调用修改联通维护密码,目前密码固定为CUAdmin
            ret, ret_data = ChangeAccount_CU(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Beispiel #4
0
def AddAnIPTV(obj,
              sn,
              WANEnable_Switch,
              DeviceType,
              AccessMode,
              PVC_OR_VLAN,
              dict_root,
              dict_wanpppconnection,
              dict_wanipconnection,
              change_account=1,
              rollbacklist=[]):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0
            #第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=1)
            if (ret_root == ERR_SUCCESS):
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                #对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第二步:逐个查找,对于A上行,查PVC,其他的则查VLAN
            #path2 = []
            path2 = ''  # 保存查到有相同的PVC或关键参数值的WAN连接路径
            path2_1 = ''  # 保存WANPPPConection或WANIPConection节点路径保存,后面修改参数时有用
            PVC_Flag = None
            #直接调GetParameterValues  查PVC或VLAN
            for i in xrange(len(ret_data_root['ParameterList'])):
                tmp_path2 = ret_data_root['ParameterList'][i]['Name']
                #A上行是关心PVC,LAN上行是关心VLAN,PON上行也是关心VLAN
                if DeviceType == 'ADSL':
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(
                        i + 1)
                elif DeviceType == 'LAN':
                    tmp_path2 = tmp_path2 + 'WANEthernetLinkConfig.X_CT-COM_VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CT-COM_VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'EPON':
                    tmp_path2 = tmp_path2 + 'X_CT-COM_WANEponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'VDSL':
                    tmp_path2 = tmp_path2 + 'X_CT-COM_WANVdslLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'GPON':
                    tmp_path2 = tmp_path2 + 'X_CT-COM_WANGponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                else:
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(
                        i + 1)
                log.app_info(info)
                ret_data_scr += info

                #sleep(3)
                ret2, ret_data2 = u1.get_parameter_values(
                    ParameterNames=tmp_path2)
                if (ret2 == ERR_SUCCESS):
                    info = u"查询成功,返回:%s\n" % ret_data2
                    log.app_info(info)
                    ret_data_scr += info
                    # 当返回的PVC与要绑定的相同时,标记PVC_Flag,走修改流程
                    if ret_data2['ParameterList'] == []:
                        pass
                    else:
                        # 如果查到PVC或VLAN相同,则标记
                        if ret_data2['ParameterList'] != []:
                            if ret_data2['ParameterList'][0][
                                    'Value'] == PVC_OR_VLAN:
                                # 查到有匹配PVC
                                PVC_Flag = 0
                                path2 = ret_data_root['ParameterList'][i][
                                    'Name']
                                break
                            else:
                                # 查不到匹配的PVC
                                continue
                        else:
                            continue
                else:
                    #对于失败的情况,直接返回错误
                    info = u"查询失败,错误信息%s\n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            WAN_Flag = None
            if PVC_Flag == 0:

                ret_tmp_path2 = []

                # 不同的WAN连接模式,其节点路径不同
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_path2 = path2 + 'WANPPPConnection.'
                    X_CT_COM_ServiceList = dict_wanpppconnection[
                        'X_CT-COM_ServiceList'][1]
                    ConnectionType = dict_wanpppconnection['ConnectionType'][1]
                    info = u"开始调用GetParameterNames查找第%s条WAN连接WANPPPConnection实例\n" % str(
                        i + 1)
                elif AccessMode == 'DHCP' or AccessMode == 'Static':
                    tmp_path2 = path2 + 'WANIPConnection.'
                    X_CT_COM_ServiceList = dict_wanipconnection[
                        'X_CT-COM_ServiceList'][1]
                    ConnectionType = dict_wanipconnection['ConnectionType'][1]
                    info = u"开始调用GetParameterNames查找第%s条WAN连接WANIPConnection实例\n" % str(
                        i + 1)

                log.app_info(info)
                ret_data_scr += info
                ret_tmp_path2 = []
                #sleep(3)
                ret2, ret_data2 = u1.get_parameter_names(
                    ParameterPath=tmp_path2, NextLevel=1)
                if (ret2 == ERR_SUCCESS):
                    info = u"查找WAN连接实例成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                    ret_data2 = DelOwnParameterNames(ret_data2, tmp_path2)

                    if ret_data2['ParameterList'] != []:
                        for tmp_index in xrange(len(
                                ret_data2['ParameterList'])):
                            ret_tmp_path2.append(
                                ret_data2['ParameterList'][tmp_index]['Name'])
                else:
                    #对于失败的情况,直接退出
                    info = u"查找WAN连接实例失败,错误信息: %s\n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第2.2步,对于PPPOE查找X_CT-COM_ServiceList和Username值.
                # 由于贝曼有些版本只查X_CT-COM_ServiceList,或者查到Username相同与否不影响判断结果,
                # 所以目前只支持查X_CT-COM_ServiceList
                for i in xrange(len(ret_tmp_path2)):
                    info = u"开始调用GetParameterValues查找第%s个WAN连接实例下的X_CT-COM_ServiceList值\n" % str(
                        i + 1)
                    log.app_info(info)
                    ret_data_scr += info

                    tmp_path2_2 = []
                    tmp_path2_2.append(ret_tmp_path2[i] +
                                       'X_CT-COM_ServiceList')
                    # GCW 20130410对桥模式单独处理,避免修改PPPOE INTERNET为桥 INTERNET的情况
                    tmp_path2_2.append(ret_tmp_path2[i] + 'ConnectionType')
                    #sleep(3)
                    ret2_2, ret_data2_2 = u1.get_parameter_values(
                        ParameterNames=tmp_path2_2)
                    if (ret2_2 == ERR_SUCCESS):
                        info = u"查找第%s个WAN连接实例下的X_CT-COM_ServiceList和ConnectionType值成功,返回:%s\n" % (
                            str(i + 1), ret_data2_2)
                        log.app_info(info)
                        ret_data_scr += info
                        # 判断值是否相等,相等(或被包含)则只修改linkconfig节点的值即可,否则需走后面的正常流程新建WAN连接
                        if AccessMode == "PPPoE_Bridged":
                            ConnectionType = "PPPoE_Bridged"
                        else:
                            ConnectionType = "IP_Routed"

                        # GCW 20130417 路由对路由比较,桥对桥的比较才更合理
                        if ConnectionType == ret_data2_2['ParameterList'][0]['Value'] or \
                           ConnectionType == ret_data2_2['ParameterList'][1]['Value']:
                            # 如果非完全不相等,则需做特殊处理
                            if (ret_data2_2['ParameterList'][0]['Value'] in X_CT_COM_ServiceList \
                                    or ret_data2_2['ParameterList'][1]['Value'] in X_CT_COM_ServiceList) \
                                or (X_CT_COM_ServiceList in ret_data2_2['ParameterList'][0]['Value'] \
                                    or X_CT_COM_ServiceList in ret_data2_2['ParameterList'][1]['Value']):
                                # GCW 20130408 判断X_CT-COM_ServiceList包含与被包含的关系做区分处理.
                                if (ret_data2_2['ParameterList'][0]['Value'] in X_CT_COM_ServiceList \
                                  or ret_data2_2['ParameterList'][1]['Value'] in X_CT_COM_ServiceList):
                                    info = u"当前CPE中的X_CT-COM_ServiceList值包含于工单中要求的X_CT-COM_ServiceList值:%s,\n" % X_CT_COM_ServiceList
                                    info += u"走修改WAN连接的流程,且重新下发X_CT-COM_ServiceList值的修改\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 0  #表示CPE当前值包含于工单,走修改WAN流程,且X_CT-COM_ServiceList需下发
                                else:
                                    info = u"当前工单中的X_CT-COM_ServiceList值:%s包含于CPE中的X_CT-COM_ServiceList值,\n" % X_CT_COM_ServiceList
                                    info += u"走修改WAN连接流程,但不下发对X_CT-COM_ServiceList值的修改.\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 3  #表示工单中的值包含于当前CPE中,走修改WAN流程,但X_CT-COM_ServiceList不需下发
                                path2_1 = ret_tmp_path2[i]
                                #将上一层路径保存并退出循环,留给下一步直接修改linkconfig参数
                                #ret_tmp_path2[i]类似于InternetGatewayDevice.WANDevice.1.WANConnectionDevice.3.WANPPPConnection.1.
                                a = ret_tmp_path2[i].split('.')
                                for i in xrange(len(a) - 3):
                                    path2 += a[i]
                                    path2 += '.'  # 将当前的WANConnectionDevice.节点路径保存,后面修改参数时有用
                                break
                            else:
                                continue
                        else:
                            continue
                    else:
                        info = u"查找第%s个WAN连接实例下的X_CT-COM_ServiceList值失败,返回:%s\n" % (
                            str(i + 1), ret_data2_2)
                        log.app_info(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

                if WAN_Flag == None:
                    info = u"查找不到匹配 %s 模式的WAN连接\n" % X_CT_COM_ServiceList
                    log.app_info(info)
                    ret_data_scr += info
                    WAN_Flag = 1

            else:
                #对于未查找到相同PVC的,直接返回错误
                info = u"未查找到PVC或VLAN为 %s 的连接,请确认!" % PVC_OR_VLAN
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            if WAN_Flag == 1 or WAN_Flag == 2:
                #第三--一步:新建WANConnectionDevice实例
                info = u"走X_CT-COM_ServiceList不相同的流程(新建WAN连接).\n"
                log.app_info(info)
                ret_data_scr += info

                # 解决用户新建tr069WAN连接导致CPE与ACS通讯异常的问题,强制不准新建包含TR0069的WAN连接

                if (("tr069" in X_CT_COM_ServiceList)
                        or ("TR069" in X_CT_COM_ServiceList)):
                    info = u"工单失败:为避免新建包含tr069模式的WAN连接对原有tr069WAN连接产生影响,所以不再新建.\n"
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 如果查找到相同的PVC,则在该PVC/VLAN下新建一个IPTV连接
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':

                    tmp_path3 = path2 + 'WANPPPConnection.'
                    info = u"查到匹配的PVC或VLAN,开始在该PVC或VLAN下新建一条实例。\n"

                elif AccessMode == 'DHCP' or AccessMode == 'Static':

                    tmp_path3 = path2 + 'WANIPConnection.'
                    info = u"查到匹配的PVC或VLAN,开始在该PVC或VLAN下新建一条实例。\n"
                log.app_info(info)
                ret_data_scr += info

                #sleep(3)  # must be ;otherwise exception
                ret3, ret_data3 = u1.add_object(ObjectName=tmp_path3)

                if (ret3 == ERR_SUCCESS):
                    instanceNum1 = ret_data3["InstanceNumber"]
                    tmp_path4 = tmp_path3 + instanceNum1 + '.'
                    info = u"新建实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    rollbacklist.append(tmp_path4)
                    rebootFlag = int(ret_data3["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"新建实例失败,错误原因:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                log.app_info(info)
                ret_data_scr += info

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                para_list6 = []
                WAN_Enable = []
                for j in tmp_values:
                    if tmp_values[j][0] == 1:
                        #如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and j == 'Enable':
                            WAN_Enable.append(
                                dict(Name=tmp_path4 + j,
                                     Value=tmp_values[j][1]))
                            continue

                        tmp_path = tmp_path4 + j
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[j][1]))

                if para_list6 == []:
                    info = u"参数为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if (ret6 == ERR_SUCCESS):
                    info = u"调用SetParameterValues设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"调用SetParameterValues设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #将WAN连接使能单独下发
                if WAN_Enable != []:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    #sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if (ret_wan_enable == ERR_SUCCESS):
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,如何处理?
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            elif WAN_Flag == 0 or WAN_Flag == 3:
                """
                #当查到有相匹配的X_CT-COM_ServiceList和Username值时的处理流程,不需要新建,只需更改WANIPConnection或WANPPPConnection节点下的参数即可
                #第三--三步:调用SetParameterValues设置linkconfig参数:
                if DeviceType == 'ADSL':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                elif DeviceType == 'LAN':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANEthernetLinkConfig参数\n"
                    path5 = path2 + 'WANEthernetLinkConfig.'
                elif DeviceType == 'EPON':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CT-COM_WANEponLinkConfig参数\n"
                    path5 = path2 + 'X_CT-COM_WANEponLinkConfig.'                
                elif DeviceType == 'VDSL':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CT-COM_WANVdslLinkConfig参数\n"
                    path5 = path2 + 'X_CT-COM_WANVdslLinkConfig.'
                elif DeviceType == 'GPON':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CT-COM_WANGponLinkConfig参数\n"
                    path5 = path2 + 'X_CT-COM_WANGponLinkConfig.'
                else:
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                log.app_info (info)
                ret_data_scr += info
                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        #对于Linkconfig的PVC或VLAN节点删除,不做修改
                        # GCW 20130418 修改WAN连接参数时,对X_CT-COM_Mode节点也不修改
                        if i == 'DestinationAddress' or i == 'VLANIDMark' or \
                           i == 'X_CT-COM_VLANIDMark' or i == "X_CT-COM_Mode":
                            continue
                        tmp_path = path5 + i
                        para_list5.append(dict(Name=tmp_path, Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    info = u"参数列表为空,请检查\n"
                    log.app_info (info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                #sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(ParameterList=para_list5)
                if (ret5 == ERR_SUCCESS):
                    info = u"设置参数成功\n"
                    log.app_info (info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s\n" % ret_data5
                    log.app_err (info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                """
                # 修改SetParameterValues设置WANPPPConnection参数
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                    log.app_info(info)
                    ret_data_scr += info

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = path2_1
                para_list6 = []
                WAN_Enable = []

                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        # GCW 20130408 判断X_CT-COM_ServiceList包含与被包含的关系做区分处理.
                        # 标志位0表示X_CT-COM_ServiceList值需以工单中的为准,重新下发,3表示不下发
                        if WAN_Flag == 0:
                            pass
                        else:
                            if i == 'X_CT-COM_ServiceList':
                                continue
                        #如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if (ret6 == ERR_SUCCESS):
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #将WAN连接使能单独下发
                if WAN_Enable != []:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    #sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if (ret_wan_enable == ERR_SUCCESS):
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            #第七步:调用SetParameterValues设置X_CT-COM_IPTV参数:
            para_list7 = []
            path = 'InternetGatewayDevice.Services.X_CT-COM_IPTV.'
            for i in dict_root:
                if dict_root[i][0] == 1:
                    tmp_path = path + i
                    para_list7.append(
                        dict(Name=tmp_path, Value=dict_root[i][1]))
            if para_list7 == []:
                info = u"X_CT-COM_IPTV参数为空,请检查\n"
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            info = u"开始调用SetParameterValues设置X_CT-COM_IPTV节点参数\n"
            log.app_info(info)
            ret_data_scr += info

            #sleep(3)  # must be ;otherwise exception
            ret7, ret_data7 = u1.set_parameter_values(ParameterList=para_list7)
            if (ret7 == ERR_SUCCESS):
                info = u"设置参数成功\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data7["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                #对于失败的情况,如何处理?
                info = u"设置参数失败,错误原因:%s\n" % ret_data7
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Beispiel #5
0
def WAN(obj,
        sn,
        DeviceType,
        AccessMode,
        change_or_enable,
        dict_pvcorvlan,
        change_account=1):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."

    # 将传参数过来的字典中有效的PVC或VLAN提取出来
    tmp_pvcorvlan = []
    for i in dict_pvcorvlan:
        if dict_pvcorvlan[i][0] == 1:
            tmp_pvcorvlan.append([dict_pvcorvlan[i][1], dict_pvcorvlan[i][2]])
    if tmp_pvcorvlan == []:
        info = u"工单传参数错误,请检查\n"
        log.app_info(info)
        ret_data_scr += info
        return ret_res, ret_data_scr

    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            #第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=1)

            if (ret_root == ERR_SUCCESS):
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                #对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第二步:逐个查找
            path2 = []
            para_list = []

            for i in xrange(len(ret_data_root['ParameterList'])):
                tmpflag = None
                tmp_path2 = ret_data_root['ParameterList'][i]['Name']
                #下面的临时变量可以根据上行方式,WAN连接类型进行修改
                if DeviceType == 'ADSL':
                    tmp_path2_1 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(
                        i + 1)
                elif DeviceType == 'LAN':
                    tmp_path2_1 = tmp_path2 + 'WANEthernetLinkConfig.X_CT-COM_VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CT-COM_VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'EPON':
                    tmp_path2_1 = tmp_path2 + 'X_CT-COM_WANEponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'VDSL':
                    tmp_path2_1 = tmp_path2 + 'WANDSLLinkConfig.X_CT-COM_VLAN'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CT-COM_VLAN值\n" % str(
                        i + 1)
                elif DeviceType == 'GPON':
                    tmp_path2_1 = tmp_path2 + 'X_CT-COM_WANGponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                else:
                    tmp_path2_1 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(
                        i + 1)
                log.app_err(info)
                ret_data_scr += info

                #sleep(3)
                ret2, ret_data2 = u1.get_parameter_values(
                    ParameterNames=tmp_path2_1)
                if (ret2 == ERR_SUCCESS):
                    info = u"查询成功,返回:%s \n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    #当返回的PVC或VLAN与需要查找的相等时,处理;查到为空则继续往下
                    if ret_data2['ParameterList'] != []:
                        for j in xrange(len(tmp_pvcorvlan)):
                            #如果查到PVC相同,则标记;
                            if ret_data2['ParameterList'][0][
                                    'Value'] == tmp_pvcorvlan[j][0]:
                                #查到有匹配PVC
                                tmpflag = True
                                tmp_enable_or_change_value = tmp_pvcorvlan[j][
                                    1]
                                #将相应的PVC和Enable状态值删除
                                tmp_pvcorvlan.remove(tmp_pvcorvlan[j])
                                break
                            else:
                                #查不到匹配的PVC
                                tmpflag = False

                        if tmpflag != None:
                            # 查实例号.
                            if AccessMode == 'PPPoE' or AccessMode == "PPPoE_Bridged":
                                tmp_path2_2 = tmp_path2 + 'WANPPPConnection.'
                                info = u"开始调用GetParameterValues查找WANPPPConnection节点下的实例号\n"
                            else:
                                tmp_path2_2 = tmp_path2 + 'WANIPConnection.'
                                info = u"开始调用GetParameterValues查找WANIPConnection节点下的实例号\n"
                            log.app_info(info)
                            ret_data_scr += info

                            #sleep(3)
                            ret3, ret_data3 = u1.get_parameter_names(
                                ParameterPath=tmp_path2_2, NextLevel=1)
                            if (ret3 == ERR_SUCCESS):
                                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                                ret_data3 = DelOwnParameterNames(
                                    ret_data3, tmp_path2_2)

                                #当返回的PVC或VLAN与要绑定的相同时,待完善
                                # GCW 20130410 解决当查到为空时,无tmp_path2_3值而导致异常
                                tmp_path2_3 = []
                                if ret_data3['ParameterList'] == []:
                                    info = u"查找成功,返回为空。\n"
                                else:
                                    #如果查到PVC相同,则标记,(手动可能多实例的情况)
                                    #tmp_path2_3 = []  # 移到外层定义,避免在if中无定义上起后面问题
                                    for i in xrange(
                                            len(ret_data3['ParameterList'])):
                                        tmp_path2_3.append(
                                            ret_data3['ParameterList'][i]
                                            ['Name'])
                                    info = u"查找成功,返回为:%s \n" % tmp_path2_3
                                log.app_info(info)
                                ret_data_scr += info
                        if tmpflag == True:
                            # 如果是启用禁用PVC,则将使能路径和值追加,如果是修改PVC,则将WAN实例和PVC值追加
                            if change_or_enable == 'Enable':
                                for i in xrange(len(tmp_path2_3)):
                                    para_list.append(
                                        dict(Name=tmp_path2_3[i] + 'Enable',
                                             Value=tmp_enable_or_change_value))
                            elif change_or_enable == 'Change':
                                para_list.append(
                                    dict(Name=tmp_path2_1,
                                         Value=tmp_enable_or_change_value))
                            else:
                                info = u"参数错误.目前只支持启用禁用PVC(VLAN)或修改PVC(VLAN).\n"
                                log.app_info(info)
                                ret_data_scr += info
                                return ret_res, ret_data_scr
                else:
                    #对于失败的情况,直接返回错误
                    info = u"查询失败,错误信息%s \n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            #只要还有一个PVC没有查到,则失败,退出
            if len(tmp_pvcorvlan) != 0:
                info = u"有未查到的PVC或VLAN,请检查\n"
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第四步,禁用或启用相应的PVC
            info = u"开始调用SetParameterValues设置相应WAN连接的参数\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)
            ret4, ret_data4 = u1.set_parameter_values(ParameterList=para_list)
            if (ret4 == ERR_SUCCESS):
                info = u"设置参数成功\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data4["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                #对于失败的情况,直接返回错误
                info = u"设置参数失败,错误原因:%s\n" % ret_data4
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            # 调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Beispiel #6
0
def WANDisable(obj, sn, DeviceType, AccessMode,
               PVC_OR_VLAN,
               dict_wanpppconnection,
               dict_wanipconnection,
               change_account=1):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn, ip=worklistcfg.AGENT_HTTP_IP, port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE, sender=KEY_SENDER_WORKLIST, worklist_id=obj.id_)
            reboot_Yes = 0

            # 第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info

            # sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(ParameterPath=ROOT_PATH, NextLevel=1)
            if ret_root == ERR_SUCCESS:
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                # 对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 第二步:逐个查找,对于A上行,查PVC,其他的则查VLAN
            # path2 = []
            path2 = ''  # 保存查到有相同的PVC或关键参数值的WAN连接路径
            path2_1 = ''  # 保存WANPPPConnection或WANIPConnection节点路径保存,后面修改参数时有用
            WAN_Flag = None
            # 直接调GetParameterValues  查PVC或VLAN
            for i in xrange(len(ret_data_root['ParameterList'])):
                tmp_path2 = ret_data_root['ParameterList'][i]['Name']
                # A上行是关心PVC,LAN上行是关心VLAN,PON上行也是关心VLAN
                if DeviceType == 'ADSL':
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(i + 1)
                elif DeviceType == 'LAN':
                    tmp_path2 = tmp_path2 + 'WANEthernetLinkConfig.X_CU_VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CU_VLANIDMark值\n" % str(i + 1)
                elif DeviceType == 'EPON':
                    tmp_path2 = tmp_path2 + 'X_CU_VLAN'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CU_VLAN值\n" % str(i + 1)
                elif DeviceType == 'VDSL':
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.X_CU_VLAN'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CU_VLAN值\n" % str(i + 1)
                elif DeviceType == 'GPON':
                    tmp_path2 = tmp_path2 + 'X_CU_VLAN'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CU_VLAN值\n" % str(i + 1)
                else:
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(i + 1)
                log.app_info(info)
                ret_data_scr += info

                # sleep(3)
                ret2, ret_data2 = u1.get_parameter_values(ParameterNames=tmp_path2)
                if ret2 == ERR_SUCCESS:
                    info = u"查询成功,返回:%s\n" % ret_data2
                    log.app_info(info)
                    ret_data_scr += info
                    # 当返回的PVC与要绑定的相同时,标记WAN_Flag,走修改流程
                    if ret_data2['ParameterList'] == []:
                        pass
                    else:
                        # 如果查到PVC或VLAN相同,则标记
                        if ret_data2['ParameterList']:
                            if ret_data2['ParameterList'][0]['Value'] == PVC_OR_VLAN:
                                # 查到有匹配PVC
                                WAN_Flag = 0
                                path2 = ret_data_root['ParameterList'][i]['Name']
                                break
                            else:
                                # 查不到匹配的PVC
                                continue
                        else:
                            continue
                else:
                    # 对于失败的情况,直接返回错误
                    info = u"查询失败,错误信息%s\n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            # 如果一直没有查到相同的,则没有对WAN_Flag标志位做过修改,则说明没有匹配的WAN连接实例
            if WAN_Flag == None:
                WAN_Flag = 1

            # 查不到匹配的PVC或VLAN,不做任何事情
            if WAN_Flag == 1:
                info = u"查不到匹配的PVC或VLAN,不执行删除WANConnectionDevice实例的操作\n"
                log.app_info(info)
                ret_data_scr += info
                pass
            elif WAN_Flag == 0:
                # 当查到有相匹配的PVC时的处理流程,则还需查WANPPPConnection下的三个节点是否一致
                # 如果完全一致,直接删除WAN连接实例,否则待完善
                # 不同的WAN连接模式,其节点路径不同
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    info = u"开始调用GetParameterNames查询WANPPPConnection实例\n"
                    tmp_path3 = path2 + 'WANPPPConnection.'
                    # GCW 20130418 应该只区分是路由还是桥接
                    if AccessMode == "PPPoE_Bridged":
                        tmp_ConnectionType = "PPPoE_Bridged"
                    else:
                        tmp_ConnectionType = "IP_Routed"
                    tmp_X_CU_LanInterface = dict_wanpppconnection['X_CU_LanInterface'][1]
                    tmp_X_CU_ServiceList = dict_wanpppconnection['X_CU_ServiceList'][1]
                elif AccessMode == 'DHCP' or AccessMode == 'Static':
                    info = u"开始调用GetParameterNames查询WANIPConnection实例\n"
                    tmp_path3 = path2 + 'WANIPConnection.'
                    # GCW 20130418 应该只区分是路由还是桥接
                    tmp_ConnectionType = "IP_Routed"
                    tmp_X_CU_LanInterface = dict_wanipconnection['X_CU_LanInterface'][1]
                    tmp_X_CU_ServiceList = dict_wanipconnection['X_CU_ServiceList'][1]
                log.app_info(info)
                ret_data_scr += info

                # sleep(3)
                ret_tmp_path3 = []
                ret3, ret_data3 = u1.get_parameter_names(ParameterPath=tmp_path3, NextLevel=1)
                if ret3 == ERR_SUCCESS:
                    info = u"查询成功,返回%s\n" % ret_data3
                    log.app_info(info)
                    ret_data_scr += info
                    # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                    ret_data3 = DelOwnParameterNames(ret_data3, tmp_path3)
                    # 返回有路径,则保存
                    if ret_data3['ParameterList']:
                        for tmp_index in xrange(len(ret_data3['ParameterList'])):
                            ret_tmp_path3.append(ret_data3['ParameterList'][tmp_index]['Name'])
                else:
                    # 对于失败的情况,直接退出
                    info = u"查询失败,返回错误信息:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                # 第2.2步,对于PPPOE查找X_CU_ServiceList和Username值.
                # 由于贝曼有些版本只查X_CU_ServiceList,或者查到Username相同与否不影响判断结果,
                # 所以目前只支持查X_CU_ServiceList
                for i in xrange(len(ret_tmp_path3)):
                    info = u"开始调用GetParameterValues查找第%s个WAN连接实例下的参数值\n" % str(i + 1)
                    log.app_err(info)
                    ret_data_scr += info

                    tmp_path3_2 = []
                    tmp_path3_2.append(ret_tmp_path3[i] + 'ConnectionType')
                    tmp_path3_2.append(ret_tmp_path3[i] + 'X_CU_ServiceList')

                    if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':

                        if dict_wanpppconnection['X_CU_LanInterface'][0] == 1:
                            tmp_path3_2.append(ret_tmp_path3[i] + 'X_CU_LanInterface')

                    elif AccessMode == 'DHCP' or AccessMode == 'Static':

                        if dict_wanipconnection['X_CU_LanInterface'][0] == 1:
                            tmp_path3_2.append(ret_tmp_path3[i] + 'X_CU_LanInterface')

                    # sleep(3)
                    ret3_2, ret_data3_2 = u1.get_parameter_values(ParameterNames=tmp_path3_2)
                    if ret3_2 == ERR_SUCCESS:
                        info = u"查找第%s个WAN连接实例下的参数值成功,返回:%s\n" % (str(i + 1), ret_data3_2)
                        log.app_info(info)
                        ret_data_scr += info

                        # 判断值是否相等,相等则直接删除WAN实例,否则就返回错误
                        WAN_Flag_1 = 0

                        for j in xrange(len(tmp_path3_2)):

                            if 'ConnectionType' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                                if ret_data3_2['ParameterList'][j]['Value'] == tmp_ConnectionType:
                                    WAN_Flag_1 = 1
                                else:
                                    WAN_Flag_1 = 0
                                    break
                            elif 'X_CU_LanInterface' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                                # 只要包含关系,就可认为是查到相等
                                # GCW 20130410 解决页面删除了绑定的LAN后导致此节点值为空的情况,不能执行split
                                # tmp_value = []
                                # tmp_value = ret_data3_2['ParameterList'][j]['Value'].split(',')
                                tmp_value = ret_data3_2['ParameterList'][j]['Value']
                                # GCW 20130413 手动页面删除绑定或工单中传参绑定为空时的异常处理。
                                if tmp_value == "" or tmp_value == None:
                                    if tmp_X_CU_LanInterface == "":
                                        # 两者均为空,则匹配成功
                                        WAN_Flag_1 = 1
                                    else:
                                        # 两者只要有一个不为空,则匹配为不相等
                                        WAN_Flag_1 = 0
                                        break
                                else:
                                    if tmp_X_CU_LanInterface == "":
                                        # 两者只要有一个不为空,则匹配为不相等
                                        WAN_Flag_1 = 0
                                        break
                                    else:
                                        if tmp_X_CU_LanInterface in tmp_value:
                                            WAN_Flag_1 = 1
                                        else:
                                            WAN_Flag_1 = 0
                                            break
                            elif 'X_CU_ServiceList' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                                # 只要包含关系,就可认为是查到相等
                                # tmp_value = []
                                # tmp_value = ret_data3_2['ParameterList'][j]['Value'].split(',')
                                tmp_value = ret_data3_2['ParameterList'][j]['Value']
                                if tmp_X_CU_ServiceList in tmp_value:
                                    WAN_Flag_1 = 1
                                else:
                                    WAN_Flag_1 = 0
                                    break
                        # 如果有一个不匹配,则认为没有开通IGMP的WAN连接,无法删除
                        if WAN_Flag_1 == 0:
                            info = u"查到与工单中有不匹配的参数,无法删除WAN连接实例\n"
                            log.app_err(info)
                            ret_data_scr += info
                            # GCW 20130419 IPTV取消工单,如果查不到匹配的WAN连接也可以认为成功
                            # return ret_res, ret_data_scr
                        else:
                            # 删除WAN连接实例
                            info = u"准备删除WANConnectionDevice实例\n"
                            log.app_info(info)
                            ret_data_scr += info

                            tmp_path = ret_tmp_path3[i].split('.')
                            path = ''
                            for i in xrange(len(tmp_path) - 3):
                                path = path + tmp_path[i] + '.'

                            # sleep(3)  # must be ;otherwise exception
                            ret3, ret_data3 = u1.delete_object(
                                ObjectName=path)
                            if ret3 == ERR_SUCCESS:
                                info = u"删除WANConnectionDevice实例成功\n"
                                log.app_info(info)
                                ret_data_scr += info

                                rebootFlag = int(ret_data3["Status"])
                                if rebootFlag == 1:
                                    reboot_Yes = 1
                            else:
                                # 对于失败的情况,直接退出
                                info = u"删除WANConnectionDevice实例失败,错误原因:%s\n" % ret_data3
                                log.app_err(info)
                                ret_data_scr += info
                                return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if reboot_Yes == 1:

                # sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if ret != ERR_SUCCESS:
                    ret_data_scr += ret_data
                    break

            # 第七步:调用修改联通维护密码,目前密码固定为CUAdmin
            ret, ret_data = ChangeAccount_CU(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Beispiel #7
0
def Eagleeyes(obj,
              sn,
              DeviceType,
              AccessMode,
              PortMappingEnabled,
              dict_PortMapping,
              change_account=1,
              rollbacklist=[]):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            #第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=1)

            if (ret_root == ERR_SUCCESS):
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                #对于失败的情况,直接返回错误
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第二步:逐个查找
            path2 = []
            for i in xrange(len(ret_data_root['ParameterList'])):
                tmp_path2 = ret_data_root['ParameterList'][i]['Name']
                #如果需绑定到PPPoE,则查WANPPPConnection节点。同理,如果以后是想绑定到静态WAN连接,则可以查另外的节点,可开放
                #A上行是关心PVC,LAN上行是关心VLAN,PON上行也是关心VLAN
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_path2 = tmp_path2 + 'WANPPPConnection.'
                    info = u"开始调用GetParameterNames查找第%s条WAN连接WANPPPConnection实例\n" % str(
                        i + 1)
                elif AccessMode == 'DHCP' or AccessMode == 'Static':
                    tmp_path2 = tmp_path2 + 'WANIPConnection.'
                    info = u"开始调用GetParameterNames查找第%s条WAN连接WANIPConnection实例\n" % str(
                        i + 1)
                else:
                    info = u"参数错误,目前只支持PPPoE_Bridged\PPPoE\DHCP\Static\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                log.app_info(info)
                ret_data_scr += info
                #sleep(3)
                ret2, ret_data2 = u1.get_parameter_names(
                    ParameterPath=tmp_path2, NextLevel=1)
                if (ret2 == ERR_SUCCESS):
                    info = u"查找第%s条WAN连接实例成功\n" % str(i + 1)
                    log.app_info(info)
                    ret_data_scr += info
                    # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                    ret_data2 = DelOwnParameterNames(ret_data2, tmp_path2)
                    #以下是只考虑返回值只有一个的情况.当然,空的时候则是什么也不做
                    if ret_data2['ParameterList'] == []:
                        pass
                    else:
                        for tmp_index in xrange(len(
                                ret_data2['ParameterList'])):
                            path2.append(
                                ret_data2['ParameterList'][tmp_index]['Name'])
                else:
                    #对于失败的情况,直接返回错误
                    info = u"查找第%s条WAN连接实例失败,错误信息: %s\n" % (str(i + 1),
                                                            ret_data2)
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
            #如果查到当前的WAN连接下,均没有WANPPPConnection实例,则说明不能绑定到PPPOE下,退出。
            #同理,如果是绑定到静态WAN连接,而WAN连接下没有实例号,则退出
            if path2 == []:
                info = u"遍历WAN连接实例结束,但无发现可用的Connection实例号,请检查\n"
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            else:
                pass

            #第三步,然后对path2中的值进行循环查找,只要一查到INTERNET,则退出
            INTERNET_FLAG = False
            for i in xrange(len(path2)):
                info = u"开始调用GetParameterValues查找第%s个WAN连接实例下的ConnectionType和X_CT-COM_ServiceList值\n" % str(
                    i + 1)
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130418 增加是路由还是桥的查找判断
                tmp_path3 = []
                tmp_path3.append(path2[i] + 'ConnectionType')
                tmp_path3.append(path2[i] + 'X_CT-COM_ServiceList')
                #sleep(3)
                ret3, ret_data3 = u1.get_parameter_values(
                    ParameterNames=tmp_path3)
                if (ret3 == ERR_SUCCESS):
                    info = u"查找第%s个WAN连接实例下的ConnectionType和X_CT-COM_ServiceList值成功,返回:%s\n" % (
                        str(i + 1), ret_data3)
                    log.app_info(info)
                    ret_data_scr += info
                    #如果查到有INTERNET,同退出当前循环
                    # GCW 20130410 修改为包含于的关系即可
                    # GCW 20130418 增加对路由或桥的判断
                    if AccessMode == "PPPoE_Bridged":
                        ConnectionType = "PPPoE_Bridged"
                    else:
                        ConnectionType = "IP_Routed"
                    # 只有桥对桥,路由对路由对比才有意义。
                    if ConnectionType == ret_data3['ParameterList'][0]['Value'] or \
                       ConnectionType == ret_data3['ParameterList'][1]['Value']:
                        # 全球眼固定是绑定到包含INTERNET的WAN连接的
                        if 'INTERNET' in ret_data3['ParameterList'][0]['Value'] or \
                           'INTERNET' in ret_data3['ParameterList'][1]['Value']:
                            INTERNET_FLAG = True
                            #记录包含INTERNET的节点路径
                            path3 = path2[i]
                            break
                else:
                    #对于失败的情况,直接返回错误
                    info = u"查找第%s个WAN连接实例下的X_CT-COM_ServiceList值失败,返回:%s\n" % (
                        str(i + 1), ret_data3)
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            #如果一直都没有查到,怎么办?目前是直接返回失败
            if INTERNET_FLAG == False:
                info = u"经遍历查找,查无匹配的X_CT-COM_ServiceList包含INTERNET值的%s 连接,执行失败.\n" % AccessMode
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第四步,调用GetParameterNames方法,查找端口映射中是否有实例
            info = u"开始调用GetParameterNames方法,查找端口映射中是否有实例\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)
            PortMapping_flag = 0
            GetParameterNames_path4 = path3 + 'PortMapping.'
            ret4, ret_data4 = u1.get_parameter_names(
                ParameterPath=GetParameterNames_path4, NextLevel=1)
            if (ret4 == ERR_SUCCESS):
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data4 = DelOwnParameterNames(ret_data4,
                                                 GetParameterNames_path4)
                #如果查到有实例,则需查找是否所有参数一致,一致则不做任何修改,不一致则修改
                if ret_data4['ParameterList'] == []:
                    info = u"端口映射中没有实例\n"
                    log.app_info(info)
                    ret_data_scr += info
                    PortMapping_flag = 0  # 表示查无实例,后面需要新建
                else:
                    # 查到有实例,还需要判断是否与工单参数中的相同,相同才删除实例,否则也是不删
                    info = u"端口映射中已有实例\n"
                    log.app_info(info)
                    ret_data_scr += info
                    for j in xrange(len(ret_data4['ParameterList'])):
                        path = ret_data4['ParameterList'][j]['Name']
                        #sleep(3)
                        info = u"查找%s 下的参数,检查端口映射规则是否与工单中的完全一致\n" % path
                        log.app_info(info)
                        ret_data_scr += info
                        # 将字典中的追加,查找值然后进行比对
                        tmp_path = []  # 保存路径
                        tmp_Value = []  # 保存成对的参数,值

                        for k in dict_PortMapping:
                            if dict_PortMapping[k][0] == 1:
                                tmp_path.append(path + k)
                                tmp_Value.append([k, dict_PortMapping[k][1]])

                        ret4_2, ret_data4_2 = u1.get_parameter_values(
                            ParameterNames=tmp_path)
                        if (ret4_2 == ERR_SUCCESS):
                            tmp = len(ret_data4_2['ParameterList'])

                            # 判断所有值是否相等
                            for k in xrange(len(ret_data4_2['ParameterList'])):
                                tmpaa = ret_data4_2['ParameterList'][k]['Name']
                                for l in xrange(len(tmp_Value)):
                                    if tmp_Value[l][0] in ret_data4_2[
                                            'ParameterList'][k]['Name'].split(
                                                "."):
                                        if ret_data4_2['ParameterList'][k][
                                                'Value'] == tmp_Value[l][1]:
                                            PortMapping_flag = 1
                                            break
                                        else:
                                            PortMapping_flag = 0
                                            break
                                # GCW 20130410 参数不一致时,仍认为端口映射规则相同的问题
                                if PortMapping_flag == 0:
                                    break
                        else:
                            info = u"查找失败,退出工单执行\n"
                            log.app_info(info)
                            ret_data_scr += info
                            return ret_res, ret_data_scr
                        if PortMapping_flag == 1:
                            info = u"查找成功,且所有参数一致\n"
                            log.app_info(info)
                            ret_data_scr += info
                            path_4 = ret_data4['ParameterList'][j]['Name']
                            break
                        else:
                            info = u"查找成功,但此端口映射中的规则与工单中要求的不一致。\n"
                            log.app_info(info)
                            ret_data_scr += info
            else:
                #对于失败的情况,直接返回错误
                info = u"查找端口映射中是否有实例失败,错误信息:%s\n" % ret_data4
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 如果是开通业务,则需新增实例并下发参数,如果是取消业务,则直接删除实例
            if PortMappingEnabled == 'Enable':
                #第五步,调用AddObject新建实例
                if PortMapping_flag == 0:
                    info = u"本工单是开通业务,且端口映射中查无实例或实例中参数不等,开始调用AddObject新建实例\n"
                    log.app_info(info)
                    ret_data_scr += info
                    path5 = GetParameterNames_path4
                    #sleep(3)  # must be ;otherwise exception
                    ret5, ret_data5 = u1.add_object(ObjectName=path5)
                    if (ret5 == ERR_SUCCESS):
                        instanceNum1 = ret_data5["InstanceNumber"]
                        info = u"新建端口映射实例成功,返回实例号:%s\n" % instanceNum1
                        log.app_info(info)
                        ret_data_scr += info
                        # GCW 20130327 增加回退机制
                        rollbacklist.append(path5 + instanceNum1 + '.')
                        rebootFlag = int(ret_data5["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"新建端口映射实例失败,错误原因:%s\n" % ret_data5
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

                    #第六步:调用SetParameterValues设置参数
                    info = u"开始调用SetParameterValues设置端口映射参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    path6 = path5 + instanceNum1 + '.'
                    para_list6 = []
                    for i in dict_PortMapping:
                        if dict_PortMapping[i][0] == 1:
                            tmp_path = path6 + i
                            para_list6.append(
                                dict(Name=tmp_path,
                                     Value=dict_PortMapping[i][1]))
                    if para_list6 == []:
                        return ret_res, ret_data_scr
                    #sleep(3)  # must be ;otherwise exception
                    ret6, ret_data6 = u1.set_parameter_values(
                        ParameterList=para_list6)

                    if (ret6 == ERR_SUCCESS):
                        info = u"设置端口映射参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data6["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"设置端口映射参数失败,错误信息:%s\n" % ret_data6
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
                else:
                    info = u"本工单是开通业务,但已有端口映射规则且所有参数均相等。不再新建。\n"
                    log.app_info(info)
                    ret_data_scr += info
            elif PortMappingEnabled == 'Disable':
                #第五步,调用删除实例
                if PortMapping_flag == 1:
                    # 删除WAN连接实例
                    #log.app_info (u"删除PortMapping实例\n")
                    info = u"本工单是取消业务,在端口映射中查到实例且参数完全一致,开始调用DelObject删除PortMapping实例\n"
                    log.app_info(info)
                    ret_data_scr += info
                    path = path_4
                    #sleep(3)  # must be ;otherwise exception
                    ret5, ret_data5 = u1.delete_object(ObjectName=path)
                    if (ret5 == ERR_SUCCESS):
                        info = u"删除PortMapping实例成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data5["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接退出
                        info = u"删除PortMapping实例失败,错误原因:%s\n" % ret_data5
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
                else:
                    info = u"本工单是取消业务,但查无所有参数均相等的实例可删除。\n"
                    log.app_info(info)
                    ret_data_scr += info
            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Beispiel #8
0
def IPTVEnable(obj, sn, WANEnable_Switch, DeviceType,
               AccessMode, PVC_OR_VLAN,
               dict_root, dict_wanlinkconfig,
               dict_wanpppconnection,
               dict_wanipconnection,
               change_account=1,
               rollbacklist=[]):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn, ip=worklistcfg.AGENT_HTTP_IP, port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE, sender=KEY_SENDER_WORKLIST, worklist_id=obj.id_)
            reboot_Yes = 0
            # 第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info
            # sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(ParameterPath=ROOT_PATH, NextLevel=1)
            if ret_root == ERR_SUCCESS:
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                # 对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 第二步:逐个查找,对于A上行,查PVC,其他的则查VLAN
            # path2 = []
            path2 = ''  # 保存查到有相同的PVC或关键参数值的WAN连接路径
            path2_1 = ''  # 保存WANPPPConnection或WANIPConnection节点路径保存,后面修改参数时有用
            WAN_Flag = None
            # 直接调GetParameterValues  查PVC或VLAN
            for i in xrange(len(ret_data_root['ParameterList'])):
                tmp_path2 = ret_data_root['ParameterList'][i]['Name']
                # A上行是关心PVC,LAN上行是关心VLAN,PON上行也是关心VLAN
                """
                if DeviceType == 'ADSL':
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(i+1)
                elif DeviceType == 'LAN':
                    tmp_path2 = tmp_path2 + 'WANEthernetLinkConfig.X_CU_VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CU_VLANIDMark值\n" % str(i+1)
                elif DeviceType == 'EPON':
                    tmp_path2 = tmp_path2 + 'X_CU_WANEponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(i+1)
                elif DeviceType == 'VDSL':
                    tmp_path2 = tmp_path2 + 'X_CU_WANVdslLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(i+1)
                elif DeviceType == 'GPON':
                    tmp_path2 = tmp_path2 + 'X_CU_WANGponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(i+1)
                else:
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(i+1)
                log.app_info (info)
                ret_data_scr += info
                """
                tmp_path2 = tmp_path2 + 'X_CU_VLAN'
                info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点值\n" % str(i + 1)
                ret_data_scr += info
                # sleep(3)
                ret2, ret_data2 = u1.get_parameter_values(ParameterNames=tmp_path2)
                if ret2 == ERR_SUCCESS:
                    info = u"查询成功,返回:%s\n" % ret_data2
                    log.app_info(info)
                    ret_data_scr += info
                    # 当返回的PVC与要绑定的相同时,标记WAN_Flag,走修改流程
                    if ret_data2['ParameterList'] == []:
                        pass
                    else:
                        # 如果查到PVC或VLAN相同,则标记
                        if ret_data2['ParameterList']:
                            if ret_data2['ParameterList'][0]['Value'] == PVC_OR_VLAN:
                                # 查到有匹配PVC
                                WAN_Flag = 0
                                path2 = ret_data_root['ParameterList'][i]['Name']
                                break
                            else:
                                # 查不到匹配的PVC
                                continue
                        else:
                            continue
                else:
                    # 对于失败的情况,直接返回错误
                    info = u"查询失败,错误信息%s\n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            # 如果一直没有查到相同的,则没有对WAN_Flag标志位做过修改,则走新建流程
            if WAN_Flag == None:
                WAN_Flag = 1

            # 查不到匹配的PVC或VLAN,则走新建流程,否则还需再查WANPPPConnection节点下的值
            if WAN_Flag == 0:
                # 当查到有相匹配的PVC时的处理流程,则还需查WANPPPConnection下的三个节点是否一致
                # 如果完全一致,则直接使能IGMP,否则需重新设置WANPPPConnection下的值(注意原有是INTERNET,重新下发是INTERNET,OTHER的情况)
                # return ret_res

                # 不同的WAN连接模式,其节点路径不同
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_path3 = path2 + 'WANPPPConnection.'
                    # GCW 20130418 应该只区分是路由还是桥接
                    if AccessMode == "PPPoE_Bridged":
                        tmp_ConnectionType = "PPPoE_Bridged"
                    else:
                        tmp_ConnectionType = "IP_Routed"
                    tmp_X_CU_LanInterface = dict_wanpppconnection['X_CU_LanInterface'][1]
                    tmp_X_CU_ServiceList = dict_wanpppconnection['X_CU_ServiceList'][1]
                    info = u"查到匹配的PVC或VLAN,开始调用GetParameterNames查询WANPPPConnection节点参数\n"
                elif AccessMode == 'DHCP' or AccessMode == 'Static':
                    tmp_path3 = path2 + 'WANIPConnection.'
                    # GCW 20130418 应该只区分是路由还是桥接
                    tmp_ConnectionType = "IP_Routed"
                    tmp_X_CU_LanInterface = dict_wanipconnection['X_CU_LanInterface'][1]
                    tmp_X_CU_ServiceList = dict_wanipconnection['X_CU_ServiceList'][1]
                    info = u"查到匹配的PVC或VLAN,开始调用GetParameterNames查询WANIPConnection节点参数\n"
                log.app_info(info)
                ret_data_scr += info

                # sleep(3)
                ret_tmp_path3 = []
                ret3, ret_data3 = u1.get_parameter_names(ParameterPath=tmp_path3, NextLevel=1)
                if ret3 == ERR_SUCCESS:
                    info = u"查询成功,返回:%s\n" % ret_data3
                    log.app_info(info)
                    ret_data_scr += info
                    # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                    ret_data3 = DelOwnParameterNames(ret_data3, tmp_path3)
                    # 返回有路径,则保存
                    if ret_data3['ParameterList']:
                        for tmp_index in xrange(len(ret_data3['ParameterList'])):
                            ret_tmp_path3.append(ret_data3['ParameterList'][tmp_index]['Name'])
                else:
                    # 对于失败的情况,直接退出
                    info = u"查询失败,返回:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                # 第2.2步,对于PPPOE查找X_CU_ServiceList和Username值.
                # 由于贝曼有些版本只查X_CU_ServiceList,或者查到Username相同与否不影响判断结果,
                # 所以目前只支持查X_CU_ServiceList
                for i in xrange(len(ret_tmp_path3)):
                    info = u"开始调用GetParameterValues查询第%s个WAN连接的参数\n" % str(i + 1)
                    log.app_info(info)
                    ret_data_scr += info

                    tmp_path3_2 = []
                    tmp_path3_2.append(ret_tmp_path3[i] + 'ConnectionType')
                    tmp_path3_2.append(ret_tmp_path3[i] + 'X_CU_LanInterface')
                    tmp_path3_2.append(ret_tmp_path3[i] + 'X_CU_ServiceList')
                    # sleep(3)
                    ret3_2, ret_data3_2 = u1.get_parameter_values(ParameterNames=tmp_path3_2)
                    if ret3_2 == ERR_SUCCESS:
                        info = u"查询成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        # 判断值是否相等,相等则不修改,直接走IGMP使能
                        # 解决部分CPE不按顺序返回ConnectionType\X_CU_LanInterface\X_CU_ServiceList节点值的情况 gcw 20130516
                        WAN_Flag_1 = 1
                        for j in xrange(3):

                            if 'ConnectionType' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                                if ret_data3_2['ParameterList'][j]['Value'] == tmp_ConnectionType:
                                    # WAN_Flag_1 = 1
                                    pass
                                else:
                                    # 路由和桥的区别时,需重新走新建WAN连接流程  GCW 20130506
                                    WAN_Flag_1 = 3
                                    break
                            elif 'X_CU_LanInterface' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                                if ret_data3_2['ParameterList'][j]['Value'] == tmp_X_CU_LanInterface:
                                    # WAN_Flag_1 = 1
                                    pass
                                else:
                                    WAN_Flag_1 = 0
                                    # break
                            elif 'X_CU_ServiceList' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                                if ret_data3_2['ParameterList'][j]['Value'] == tmp_X_CU_ServiceList:
                                    # WAN_Flag_1 = 1
                                    pass
                                else:
                                    WAN_Flag_1 = 0
                                    # break
                        # 如果有一个不匹配,则修改WANPPPConnection节点下的值
                        if WAN_Flag_1 == 0:
                            # 对于查到是INTERNET,而待下发的是OTHER的话,贝曼的处理是重新修改为"INTERNET,OTHER"
                            # GCW 20130401 以下处理虽然符合贝曼,但不合理.重新定义为以传参为准.
                            # for j in xrange(3):
                            #    if 'X_CU_ServiceList' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                            #        if ret_data3_2['ParameterList'][j]['Value'] != tmp_X_CU_ServiceList:
                            #            tmp_X_CU_ServiceList = 'INTERNET,OTHER'

                            if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                                tmp_values = dict_wanpppconnection
                                info = u"查询到的值与用户工单中传参过来的有不相等情况,开始调用SetParameterValues修改WANPPPConnection参数\n"
                            else:
                                tmp_values = dict_wanipconnection
                                info = u"查询到的值与用户工单中传参过来的有不相等情况,开始调用SetParameterValues修改WANIPConnection参数\n"
                            log.app_info(info)
                            ret_data_scr += info

                            # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                            path6 = ret_tmp_path3[i]
                            para_list6 = []
                            WAN_Enable = []
                            for j in tmp_values:
                                if tmp_values[j][0] == 1:
                                    # 如果WAN连接使能需单独下发,则将使能的动作单独保存
                                    if WANEnable_Switch == False and j == 'Enable':
                                        WAN_Enable.append(dict(Name=path6 + j, Value=tmp_values[j][1]))
                                        continue

                                    tmp_path = path6 + j
                                    # 如果是X_CU_ServiceList,则用修改后的值
                                    if j == 'X_CU_ServiceList':
                                        para_list6.append(dict(Name=tmp_path, Value=tmp_X_CU_ServiceList))
                                    else:
                                        para_list6.append(dict(Name=tmp_path, Value=tmp_values[j][1]))
                            if para_list6 == []:
                                info = u"参数为空,请检查\n"
                                log.app_err(info)
                                ret_data_scr += info
                                return ret_res, ret_data_scr

                            # sleep(3)  # must be ;otherwise exception
                            ret6, ret_data6 = u1.set_parameter_values(ParameterList=para_list6)
                            if ret6 == ERR_SUCCESS:
                                info = u"修改参数成功\n"
                                log.app_info(info)
                                ret_data_scr += info
                                rebootFlag = int(ret_data6["Status"])
                                if rebootFlag == 1:
                                    reboot_Yes = 1
                            else:
                                # 对于失败的情况,直接返回失败
                                info = u"修改参数失败,错误原因:%s\n" % ret_data6
                                log.app_err(info)
                                ret_data_scr += info
                                return ret_res, ret_data_scr

                            # 将WAN连接使能单独下发
                            if WAN_Enable:
                                info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                                log.app_info(info)
                                ret_data_scr += info
                                # sleep(3)  # must be ;otherwise exception
                                ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(ParameterList=WAN_Enable)
                                if ret_wan_enable == ERR_SUCCESS:
                                    info = u"设置WAN连接使能参数成功\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    rebootFlag = int(ret_data_wan_enable["Status"])
                                    if rebootFlag == 1:
                                        reboot_Yes = 1
                                else:
                                    # 对于失败的情况,如何处理?
                                    info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                                    log.app_err(info)
                                    ret_data_scr += info
                                    return ret_res, ret_data_scr
                        elif WAN_Flag_1 == 3:
                            WAN_Flag = 1  # 重置WAN_Flag标志位,走新建WAN连接流程
                        else:
                            info = u"查询到的值与用户工单中传参过来的相等,无需修改WAN连接参数\n"
                            log.app_info(info)
                            ret_data_scr += info
                    else:
                        info = u"查询失败,请检查\n"
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            if WAN_Flag == 1:
                # 第三--一步:新建WANConnectionDevice实例
                info = u"查不到匹配的PVC(VLAN)、或ConnectionType(模式)不匹配,走新建WAN连接。\n"
                log.app_info(info)
                ret_data_scr += info

                info = u"开始调用AddObject新建WANConnectionDevice实例。\n"
                log.app_info(info)
                ret_data_scr += info

                Classpath = ROOT_PATH
                # sleep(3)  # must be ;otherwise exception
                ret3, ret_data3 = u1.add_object(
                    ObjectName=Classpath)
                if ret3 == ERR_SUCCESS:
                    instanceNum1 = ret_data3["InstanceNumber"]
                    info = u"新建实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    tmp_path3 = Classpath + instanceNum1 + '.'
                    # GCW 20130327 增加回退机制
                    rollbacklist.append(tmp_path3)
                    rebootFlag = int(ret_data3["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"新建实例失败,错误原因:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--二步:新建WANIPConnection或WANPPPConnection实例
                # 只有是桥模式和路由PPPOE时,才新建WANPPPConnection实例.暂时不考虑桥
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    path4 = ROOT_PATH + instanceNum1 + '.WANPPPConnection.'
                    info = u"开始调用AddObject新建WANPPPConnection实例\n"
                    log.app_info(info)
                    ret_data_scr += info
                else:
                    path4 = ROOT_PATH + instanceNum1 + '.WANIPConnection.'
                    info = u"开始调用AddObject新建WANIPConnection实例\n"
                    log.app_info(info)
                    ret_data_scr += info

                # sleep(3)  # must be ;otherwise exception
                ret4, ret_data4 = u1.add_object(
                    ObjectName=path4)

                if ret4 == ERR_SUCCESS:
                    instanceNum1 = ret_data4["InstanceNumber"]
                    tmp_path4 = path4 + instanceNum1
                    info = u"新建实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info

                    rebootFlag = int(ret_data4["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接退出
                    info = u"新建实例失败,错误原因:%s\n" % ret_data4
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--三步:调用SetParameterValues设置linkconfig参数:
                """
                if DeviceType == 'ADSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n"
                elif DeviceType == 'LAN':
                    path5 = tmp_path3 + 'WANEthernetLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANEthernetLinkConfig参数\n"
                elif DeviceType == 'EPON':
                    path5 = tmp_path3 + 'X_CU_WANEponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANEponLinkConfig参数\n"
                elif DeviceType == 'VDSL':
                    path5 = tmp_path3 + 'X_CU_WANVdslLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANVdslLinkConfig参数\n"
                elif DeviceType == 'GPON':
                    path5 = tmp_path3 + 'X_CU_WANGponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANGponLinkConfig参数\n"
                else:
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n"
                log.app_info (info)
                ret_data_scr += info
                """
                info = u"开始调用SetParameterValues设置参数\n"
                log.app_info(info)
                ret_data_scr += info
                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        tmp_path = tmp_path3 + i
                        para_list5.append(dict(Name=tmp_path, Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    info = u"参数为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                # sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(ParameterList=para_list5)
                if ret5 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s\n" % ret_data5
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                log.app_info(info)
                ret_data_scr += info
                # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = tmp_path4 + '.'
                para_list6 = []
                WAN_Enable = []
                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        # 如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    info = u"参数为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(ParameterList=para_list6)
                if ret6 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 将WAN连接使能单独下发
                if WAN_Enable:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info

                    # sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(ParameterList=WAN_Enable)
                    if ret_wan_enable == ERR_SUCCESS:
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if rebootFlag == 1:
                            reboot_Yes = 1
                    else:
                        # 对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            # 第七步:调用SetParameterValues设置X_CU_IPTV参数:
            para_list7 = []
            path = 'InternetGatewayDevice.X_CU_Function.IGMP.'
            for i in dict_root:
                if dict_root[i][0] == 1:
                    tmp_path = path + i
                    para_list7.append(dict(Name=tmp_path, Value=dict_root[i][1]))
            if para_list7 == []:
                info = u"X_CU_IPTV参数为空,请检查\n"
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            info = u"开始调用SetParameterValues设置X_CU_IPTV节点参数\n"
            log.app_info(info)
            ret_data_scr += info

            # sleep(3)  # must be ;otherwise exception
            ret7, ret_data7 = u1.set_parameter_values(ParameterList=para_list7)
            if ret7 == ERR_SUCCESS:
                info = u"设置参数成功\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data7["Status"])
                if rebootFlag == 1:
                    reboot_Yes = 1
            else:
                # 对于失败的情况,如何处理?
                info = u"设置参数失败,错误原因:%s\n" % ret_data7
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if reboot_Yes == 1:

                # sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if ret != ERR_SUCCESS:
                    ret_data_scr += ret_data
                    break

            # 第七步:调用修改联通维护密码,目前密码固定为CUAdmin
            ret, ret_data = ChangeAccount_CU(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr