def process_config(msg, obj): """ request = user request """ ret = None cpe = None obj_database = obj # default msg_rsp = msg + 2 for nwf in [1]: if msg == EV_WAIT_EVENTCODE_INIT_RQST: ret, msg_rsp, obj_database = on_rx_user_wait_eventcode_init( msg, obj) elif msg == EV_WAIT_EVENTCODE_START_RQST: ret, msg_rsp, obj_database = on_rx_user_wait_eventcode_start( msg, obj) elif msg == EV_WAIT_EVENTCODE_STOP_RQST: ret, msg_rsp, obj_database = on_rx_user_wait_eventcode_stop( msg, obj) elif msg == EV_WAIT_EVENTCODE_QUERY_RQST: ret, msg_rsp, obj_database = on_rx_user_wait_eventcode_query( msg, obj) elif msg == EV_INIT_ALARM_RQST: ret, msg_rsp, obj_database = on_rx_user_init_alarm(msg, obj) elif msg == EV_START_ALARM_RQST: ret, msg_rsp, obj_database = on_rx_user_start_alarm(msg, obj) elif msg == EV_STOP_ALARM_RQST: ret, msg_rsp, obj_database = on_rx_user_stop_alarm(msg, obj) elif msg == EV_GET_ALARM_PARAMETER_RQST: ret, msg_rsp, obj_database = on_rx_user_get_alarm_parameter( msg, obj) elif msg == EV_INIT_MONITOR_RQST: ret, msg_rsp, obj_database = on_rx_user_init_monitor(msg, obj) elif msg == EV_START_MONITOR_RQST: ret, msg_rsp, obj_database = on_rx_user_start_monitor(msg, obj) elif msg == EV_STOP_MONITOR_RQST: ret, msg_rsp, obj_database = on_rx_user_stop_monitor(msg, obj) elif msg == EV_GET_MONITOR_PARAMETER_RQST: ret, msg_rsp, obj_database = on_rx_user_get_monitor_parameter( msg, obj) elif msg == EV_QUERY_ALARM_RQST: ret, msg_rsp, obj_database = on_rx_query_alarm_status(msg, obj) elif msg == EV_QUERY_MONITOR_RQST: ret, msg_rsp, obj_database = on_rx_query_monitor_status( msg, obj) else: ret = ERR_FATAL desc = "msg(%s) is not recognize" % msg log.app_err(desc) break return ret, msg_rsp, obj_database
def WLANEnable(obj, sn, dict_ssid, change_account=1, rollbacklist=[]): """ """ ret_res = ERR_FAIL # 脚本返回值,成功或失败.缺省失败 ret_data_scr = "" # 返回结果日志 # 入参处理 tmp_ssid = [] for i in dict_ssid: if dict_ssid[i][0] == 1: tmp_ssid.append([dict_ssid[i][1], dict_ssid[i][2]]) if tmp_ssid == []: info = u"工单传参数错误,请检查\n" log.app_info (info) ret_data_scr += info return ret_res, ret_data_scr WLAN_ROOT_PATH = "InternetGatewayDevice.LANDevice.1.WLANConfiguration." 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方法,查找当前有几个无线实例 info = u"开始调用GetParameterNames方法,查找当前无线实例个数\n" log.app_info (info) ret_data_scr += info para_list = [] path = WLAN_ROOT_PATH ret_root, ret_data1_root = u1.get_parameter_names(ParameterPath=path, NextLevel='1') #sleep(2) # must be ;otherwise exception if (ret_root == ERR_SUCCESS): info = u"查找当前无线实例个数成功。\n" log.app_info (info) ret_data_scr += info # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除 ret_data1_root = DelOwnParameterNames(ret_data1_root, path) else: #对于失败的情况,直接返回失败 info = u"查找当前无线实例失败.失败信息:%s \n。" % ret_data1_root log.app_err (info) ret_data_scr += info return ret_res, ret_data_scr para_list = [] # 判断当前要启用或禁用的无线实例(SSID)是否存在,不存在则报错退出 for i in xrange(len(tmp_ssid)): tmp_para_path = path + tmp_ssid[i][0] tmp_flag = False for j in xrange(len(ret_data1_root['ParameterList'])): if ret_data1_root['ParameterList'][j]['Name'] in tmp_para_path: para_list.append(dict(Name=tmp_para_path, Value=tmp_ssid[i][1])) tmp_flag = True break if tmp_flag == False: #对于失败的情况,直接返回失败 info = u"未查找到节点为 %s 的无线实例,请确认。\n" % tmp_para_path log.app_err (info) ret_data_scr += info return ret_res, ret_data_scr info = u"开始调用SetParameterValues设置无线实例启用或禁用。。。\n" log.app_info (info) ret_data_scr += info #设置值 ret_root, ret_data_root = u1.set_parameter_values(ParameterList=para_list) #sleep(2) # must be ;otherwise exception if (ret_root == ERR_SUCCESS): info = u"设置无线实例启用或禁用成功。\n" log.app_info (info) ret_data_scr += info rebootFlag = int(ret_data_root["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: # 对于失败的情况,直接返回错误 info = u"设置无线实例启用或禁用失败,详细信息: \n" % ret_data_root 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
if (not v_obj): log.app_err("dict KEY_OBJECT missing(%s)." %(KEY_OBJECT)) break try: strio = StringIO(v_obj) obj_reserve = pickle.load(strio) except Exception,e: log.app_err("dict KEY_OBJECT pick load fail.") break # match status obj_database = restore_acs_part_worklist(obj_reserve.id_) if (not obj_database): log.app_err("worklist id(%s) not in acs" %obj_reserve.id_) break if (int(msg) - EV_WORKLIST_EXECUTE_RQST == 1): ret_worklist = ERR_SUCCESS return ret_worklist @staticmethod def wait_worklist_exec_finish(obj_database): """ """ ret = ERR_FAIL err_message = ""
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
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
def _find_wan_server_and_connecttype(sn_obj, AccessMode, dict_wanpppconnection, dict_wanipconnection, ret_data_root, ret_data_scr): ret_res = ERR_FAIL path2_1_list = [] if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged': reg_LanInterface = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANPPPConnection.\d+\.X_CT-COM_LanInterface$" reg_X_CT_COM_ServiceList = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANPPPConnection.\d+\.X_CT-COM_ServiceList$" reg_ConnectionType = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANPPPConnection.\d+\.ConnectionType$" elif AccessMode == 'DHCP' or AccessMode == 'Static': reg_LanInterface = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANIPConnection.\d+\.X_CT-COM_LanInterface$" reg_X_CT_COM_ServiceList = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANIPConnection.\d+\.X_CT-COM_ServiceList$" reg_ConnectionType = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANIPConnection.\d+\.ConnectionType$" ret_connectiontype = [] ret_serverlist = [] serverlist_items = [] # 保存查询到的serverlist 路径值 connect_type_items = [] # 保存查询到的connecttype 路径值 for i in xrange(len(ret_data_root['ParameterList'])): tmp_path_getvalue = ret_data_root['ParameterList'][i]['Name'] m_interface = re.match(reg_LanInterface, tmp_path_getvalue) m_serverlist = re.match(reg_X_CT_COM_ServiceList, tmp_path_getvalue) m_connectiontype = re.match(reg_ConnectionType, tmp_path_getvalue) if m_interface is not None: path2_1_list.append(tmp_path_getvalue) if m_serverlist is not None: path2_1_list.append(tmp_path_getvalue) ret_serverlist.append(tmp_path_getvalue) if m_connectiontype is not None: path2_1_list.append(tmp_path_getvalue) ret_connectiontype.append(tmp_path_getvalue) if len(ret_connectiontype) != len(ret_serverlist): info = u"GetParameterNames查找到WAN连接的X_CT_COM_ServiceList和ConnectionType节点个数不等,工单异常退出。\n" log.app_info(info) ret_data_scr += info return ret_res, serverlist_items, connect_type_items, ret_data_scr ret_data_getvalue = [] if path2_1_list != []: info = u"开始调用GetParameterValues查找WAN连接实例下的X_CT-COM_ServiceList、X_CT-COM_LanInterface和ConnectionType值。\n" log.app_info(info) ret_data_scr += info ret_get_value, ret_data_getvalue = sn_obj.get_parameter_values( ParameterNames=path2_1_list) if (ret_get_value == ERR_SUCCESS): info = u"查找WAN连接实例下的X_CT-COM_ServiceList、X_CT-COM_LanInterface和ConnectionType值成功,返回:%s 。\n" % ret_data_getvalue log.app_info(info) ret_data_scr += info else: info = u"获取WAN连接实例下的X_CT-COM_ServiceList、X_CT-COM_LanInterface和ConnectionType值失败,错误信息:%s 。\n" % ret_data_getvalue log.app_err(info) ret_data_scr += info return ret_res, serverlist_items, connect_type_items, ret_data_scr else: pass if ret_data_getvalue != []: getvalue_list = ret_data_getvalue["ParameterList"] else: getvalue_list = [] for item in getvalue_list: tmp_m_serverlist = re.match(reg_X_CT_COM_ServiceList, item['Name']) tmp_m_connecttype = re.match(reg_ConnectionType, item['Name']) if tmp_m_serverlist is not None: serverlist_items.append(item) if tmp_m_connecttype is not None: connect_type_items.append(item) return ERR_SUCCESS, serverlist_items, connect_type_items, ret_data_scr
def WLAN(obj, sn, Num, dict_root, dict_WEPKey, dict_PreSharedKey, change_account=1, rollbacklist=[]): """ """ ret_res = ERR_FAIL # 脚本返回值,成功或失败.缺省失败 ret_data_scr = "" # 返回结果日志 WLAN_ROOT_PATH = "InternetGatewayDevice.LANDevice.1.WLANConfiguration." 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方法,查找当前有几个无线实例 info = u"开始调用GetParameterNames方法,查找当前无线实例个数\n" log.app_info(info) ret_data_scr += info para_list = [] path = WLAN_ROOT_PATH ret_root, ret_data1_root = u1.get_parameter_names( ParameterPath=path, NextLevel='1') # sleep(2) # must be ;otherwise exception if ret_root == ERR_SUCCESS: info = u"查找当前无线实例个数成功\n" log.app_info(info) ret_data_scr += info # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除 ret_data1_root = DelOwnParameterNames(ret_data1_root, path) else: # 对于失败的情况,直接返回失败 info = u"查找当前无线实例失败.失败信息:%s\n" % ret_data1_root log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr # 第二步:判断是否需要增加实例,如果不需要,则直接进入下一步的修改设置 para_list = [] path = WLAN_ROOT_PATH path2 = [] # 将查到的实例号路径追加到列表中 for i in xrange(len(ret_data1_root['ParameterList'])): path2.append(ret_data1_root['ParameterList'][i]['Name']) # 新建实例个数等于传参进来的个数减去查到已经存在的个数,但如要Num为0或者小于已有实例个数,则不需新建 if int(Num) > len(ret_data1_root['ParameterList']): info = u"开始调用AddObject,增加无线实例\n" log.app_info(info) ret_data_scr += info for i in xrange( int(Num) - len(ret_data1_root['ParameterList'])): ret_addobject, ret_data_addobject = u1.add_object( ObjectName=path) # sleep(2) # must be ;otherwise exception if ret_addobject == ERR_SUCCESS: instanceNum1 = ret_data_addobject["InstanceNumber"] path2.append(path + instanceNum1 + '.') info = u"增加无线实例成功,返回实例号:%s\n" % instanceNum1 log.app_info(info) ret_data_scr += info # GCW 20130327 增加回退机制 rollbacklist.append(path + instanceNum1 + '.') rebootFlag = int(ret_data_addobject["Status"]) if rebootFlag == 1: reboot_Yes = 1 else: # 对于失败的情况,直接返回失败 info = u"增加无线实例失败,失败信息:%s\n" % ret_data_addobject log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr else: info = u"已经开通的无线实例个数大于或等于 %s\n" % str(Num) log.app_info(info) ret_data_scr += info # 第三步:对队列各个参数进行配置 for i in xrange(len(path2)): info = u"开始调用SetParameterValues对第%s个无线实例进行配置\n" % str(i + 1) log.app_info(info) ret_data_scr += info if dict_root['BeaconType'][1] == 'None': # 不加密的情况 para_list = [] path = path2[i] for j in dict_root: if dict_root[j][0] == 1: tmp_path = path + j para_list.append( dict(Name=tmp_path, Value=dict_root[j][1])) if para_list == []: return ret_res, ret_data_scr elif dict_root['BeaconType'][1] == 'Basic': # WEP加密的情况 para_list = [] path = path2[i] for j in dict_root: if dict_root[j][0] == 1: tmp_path = path + j para_list.append( dict(Name=tmp_path, Value=dict_root[j][1])) if para_list == []: return ret_res, ret_data_scr elif dict_root['BeaconType'][1] == 'WPA': # WPA加密的情况 para_list = [] path = path2[i] for j in dict_root: if dict_root[j][0] == 1: tmp_path = path + j para_list.append( dict(Name=tmp_path, Value=dict_root[j][1])) # dict_PreSharedKey节点下的密钥也一起下发 path_PreSharedKey = path + 'PreSharedKey.1.' for j in dict_PreSharedKey: if dict_PreSharedKey[j][0] == 1: tmp_path = path_PreSharedKey + j para_list.append( dict(Name=tmp_path, Value=dict_PreSharedKey[j][1])) if para_list == []: info = u"选择了WPA加密,但没有使能密钥的传参\n" log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr else: # 其它的待完善.同时,需考虑在elif中兼容其它的方式 pass # 设置值 ret_root, ret_data_root = u1.set_parameter_values( ParameterList=para_list) # sleep(2) # must be ;otherwise exception if ret_root == ERR_SUCCESS: info = u"第%s个无线实例的参数配置成功\n" % str(i + 1) log.app_info(info) ret_data_scr += info rebootFlag = int(ret_data_root["Status"]) if rebootFlag == 1: reboot_Yes = 1 else: # 对于失败的情况,直接返回错误 info = u"第%s个无线实例的参数配置失败,失败信息:%s\n" % (str(i + 1), ret_data_root) log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr # 如果是WEP加密,则还需要设置KEY if dict_root['BeaconType'][1] == 'Basic': info = u"开始调用SetParameterValues对第%s个无线实例的WEP密钥进行配置\n" % str( i + 1) log.app_info(info) ret_data_scr += info if dict_root['WEPKeyIndex'][0] != 1: ret_data_scr += u"选择了WEP加密,但没有使能KEY索引的传参\n" return ret_res, ret_data_scr # KEY索引没有打开,不建议再判断索引值范围。 path_WEPKey = path2[i] + 'WEPKey.' + dict_root[ 'WEPKeyIndex'][1] + '.WEPKey' para_list = [] para_list.append( dict(Name=path_WEPKey, Value=dict_WEPKey['WEPKey'][1])) # 设置值 ret_WEPKey, ret_data_WEPKey = u1.set_parameter_values( ParameterList=para_list) # sleep(1) # must be ;otherwise exception if ret_WEPKey == ERR_SUCCESS: info = u"对第%s个无线实例的WEP密钥进行配置成功\n" % str(i + 1) log.app_info(info) ret_data_scr += info rebootFlag = int(ret_data_WEPKey["Status"]) if rebootFlag == 1: reboot_Yes = 1 else: # 对于失败的情况,直接返回错误 info = u"对第%s个无线实例的WEP密钥进行配置失败,失败信息:%s\n" % ( str(i + 1), ret_data_WEPKey) 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
def _find_wan_server_and_connecttype(sn_obj, DeviceType, AccessMode, dict_wanpppconnection, dict_wanipconnection, ret_data_root, ret_data_scr): ret_res = ERR_FAIL path2_1_list = [] if DeviceType == 'ADSL': reg_VLAN = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANDSLLinkConfig.DestinationAddress$" elif DeviceType == 'LAN': reg_VLAN = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANEthernetLinkConfig.X_CT-COM_VLANIDMark$" elif DeviceType == 'EPON': reg_VLAN = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.X_CT-COM_WANEponLinkConfig.VLANIDMark$" elif DeviceType == 'VDSL': reg_VLAN = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANDSLLinkConfig.X_CT-COM_VLAN$" elif DeviceType == 'GPON': reg_VLAN = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.X_CT-COM_WANGponLinkConfig.VLANIDMark$" else: reg_VLAN = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANDSLLinkConfig.DestinationAddress$" if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged': reg_Username = "******" reg_X_CT_COM_ServiceList = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANPPPConnection.\d+\.X_CT-COM_ServiceList$" reg_ConnectionType = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANPPPConnection.\d+\.ConnectionType$" elif AccessMode == 'DHCP' or AccessMode == 'Static': reg_Username = "******" reg_X_CT_COM_ServiceList = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANIPConnection.\d+\.X_CT-COM_ServiceList$" reg_ConnectionType = "InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice.\d+\.WANIPConnection.\d+\.ConnectionType$" ret_pvcorvlan = [] ret_connectiontype = [] ret_serverlist = [] ret_username = [] pvcorvlan_items = [] laninterface_items = [] # 保存查询到的serverlist 路径值 serverlist_items = [] # 保存查询到的serverlist 路径值 connect_type_items = [] # 保存查询到的connecttype 路径值 for i in xrange(len(ret_data_root['ParameterList'])): tmp_path_getvalue = ret_data_root['ParameterList'][i]['Name'] m_pvcorvlan = re.match(reg_VLAN, tmp_path_getvalue) m_username = re.match(reg_Username, tmp_path_getvalue) m_serverlist = re.match(reg_X_CT_COM_ServiceList, tmp_path_getvalue) m_connectiontype = re.match(reg_ConnectionType, tmp_path_getvalue) if m_pvcorvlan is not None: path2_1_list.append(tmp_path_getvalue) ret_pvcorvlan.append(tmp_path_getvalue) if m_username is not None: path2_1_list.append(tmp_path_getvalue) ret_username.append(tmp_path_getvalue) if m_serverlist is not None: path2_1_list.append(tmp_path_getvalue) ret_serverlist.append(tmp_path_getvalue) if m_connectiontype is not None: path2_1_list.append(tmp_path_getvalue) ret_connectiontype.append(tmp_path_getvalue) if len(ret_connectiontype) != len(ret_serverlist) and len( ret_connectiontype) != len(ret_username): info = u"GetParameterNames查找到WAN连接的X_CT_COM_ServiceList,ConnectionType和Username节点个数不等,工单异常退出。\n" log.app_info(info) ret_data_scr += info return ret_res, pvcorvlan_items, serverlist_items, connect_type_items, ret_data_scr ret_data_getvalue = [] if path2_1_list != []: info = u"开始调用GetParameterValues查找WAN连接实例下的VLANID、X_CT_COM_ServiceList,ConnectionType和Username值。\n" log.app_info(info) ret_data_scr += info ret_get_value, ret_data_getvalue = sn_obj.get_parameter_values( ParameterNames=path2_1_list) if (ret_get_value == ERR_SUCCESS): info = u"查找WAN连接实例下的VLANID、X_CT_COM_ServiceList,ConnectionType和Username值成功。\n" log.app_info(info) ret_data_scr += info else: info = u"获取WAN连接实例下的VLANID、X_CT_COM_ServiceList,ConnectionType和Username值失败,错误信息:%s 。\n" % ret_data_getvalue log.app_err(info) ret_data_scr += info return ret_res, serverlist_items, connect_type_items, laninterface_items, ret_data_scr else: pass if ret_data_getvalue != []: getvalue_list = ret_data_getvalue["ParameterList"] else: getvalue_list = [] for item in getvalue_list: tmp_m_serverlist = re.match(reg_X_CT_COM_ServiceList, item['Name']) tmp_m_connecttype = re.match(reg_ConnectionType, item['Name']) tmp_m_username = re.match(reg_Username, item['Name']) tmp_m_pvcorvlan = re.match(reg_VLAN, item['Name']) if tmp_m_serverlist is not None: serverlist_items.append(item) if tmp_m_connecttype is not None: connect_type_items.append(item) if tmp_m_username is not None: laninterface_items.append(item) if tmp_m_pvcorvlan is not None: pvcorvlan_items.append(item) return ERR_SUCCESS, pvcorvlan_items, serverlist_items, connect_type_items, laninterface_items, ret_data_scr
try: msg_obj = request_message.get(event.KEY_OBJECT) strio = StringIO(msg_obj) recv_data_obj = pickle.load(strio) except Exception, e: err_info = "keepalive_request_response: Unpickle event.KEY_OBJECT occurs error:%s" % e log.debug_err(err_info) request_message[event.KEY_MESSAGE] = message_type + 2 #发送响应消息 ResponseClientHandle.handle_send_response(request_message, conn) return True if not (isinstance(recv_data_obj, event.MsgQueryIsHang)): #构造错误的返回消息 error_info = "keepalive_request_response: Request message obj is not MsgQueryIsHang" log.app_err(error_info) request_message[event.KEY_MESSAGE] = message_type + 2 else: #构造正常响应消息 request_message[event.KEY_MESSAGE] = message_type + 1 #发送响应消息 ResponseClientHandle.handle_send_response(request_message, conn) return True
def WLANMultiWANSetUP(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 WAN_Flag = 1 # 强制新建 if WAN_Flag == 1 or WAN_Flag == 2: #第三--一步:新建WANConnectionDevice实例 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实例 #log.app_info (u"第四步:增加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_CT-COM_WANEponLinkConfig.' info = u"开始调用SetParameterValues设置X_CT-COM_WANEponLinkConfig参数\n" elif DeviceType == 'VDSL': path5 = tmp_path3 + 'X_CT-COM_WANVdslLinkConfig.' info = u"开始调用SetParameterValues设置X_CT-COM_WANVdslLinkConfig参数\n" elif DeviceType == 'GPON': path5 = tmp_path3 + 'X_CT-COM_WANGponLinkConfig.' info = u"开始调用SetParameterValues设置X_CT-COM_WANGponLinkConfig参数\n" else: path5 = tmp_path3 + 'WANDSLLinkConfig.' info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n" log.app_info(info) ret_data_scr += info para_list5 = [] for i in dict_wanlinkconfig: if dict_wanlinkconfig[i][0] == 1: tmp_path = path5 + 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参数: #log.app_info (u"第六步:调用SetParameterValues设置参数") 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 # 如果需要重启,则下发Reboot方法,目前采用静等待130S if (reboot_Yes == 1): # nwf 2013-07-12 #sleep(130) ret, ret_data = u1.wait_next_inform( sn, worklistcfg.REBOOT_WAIT_NEXT_INFORM_TIMEOUT) ret_data_scr += ret_data if ret != ERR_SUCCESS: 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
def AddAnWAN(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=0) 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 if AccessMode == 'PPPoE' or AccessMode == 'DHCP' or AccessMode == 'Static' or AccessMode == 'PPPoE_Bridged': if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged': X_CT_COM_ServiceList = dict_wanpppconnection[ 'X_CT-COM_ServiceList'][1] elif AccessMode == 'DHCP' or AccessMode == 'Static': X_CT_COM_ServiceList = dict_wanipconnection[ 'X_CT-COM_ServiceList'][1] ret_find, pvcorvlan_items, serverlist_items, connect_type_items, laninterface_items, ret_data_find = _find_wan_server_and_connecttype( u1, DeviceType, AccessMode, dict_wanpppconnection, dict_wanipconnection, ret_data_root, ret_data_scr) if ret_find == ERR_SUCCESS: ret_data_scr = ret_data_find else: ret_data_scr = ret_data_find return ret_res, ret_data_find if AccessMode == "PPPoE_Bridged": ConnectionType = "PPPoE_Bridged" else: ConnectionType = "IP_Routed" else: info = u"输入的AccessMode参数不合法,请检查!\n" log.app_info(info) ret_data_scr += info return ret_res, ret_data_scr WAN_Flag = None WAN_PVC = None # 是否找到PVC path2 = '' # 保存查到有相同的PVC或关键参数值的WAN连接路径 for i_pvcorvlan in pvcorvlan_items: if i_pvcorvlan['Value'] == PVC_OR_VLAN: WAN_PVC = 0 path2 = i_pvcorvlan['Name'] tmp_link_list = path2.split('.')[0:-2] path2 = '.'.join(tmp_link_list) break else: # 查不到匹配的PVC continue if WAN_PVC == None: # 如果一直没有查到相同的,则没有对WAN_Flag标志位做过修改,则走新建流程 #对于未查找到相同PVC的,直接返回错误 info = u"未查找到PVC或VLAN为 %s 的连接,请确认!" % PVC_OR_VLAN log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr #第二步:逐个查找 # 是否有查到已存在的类似WAN连接的状态位,符合以下标识,桥只关心PVC,其他的只关心X_CT-COM_ServiceList modify_path = "" for i_connect in connect_type_items: tmp_ppp_list = i_connect['Name'].split('.')[0:-1] tmp_ppp_path = '.'.join( tmp_ppp_list) # 保存XXXX.WANPPPConnection.i.路径 # 确定WAN,是否修改 for j_serverlist in serverlist_items: tmp_serverlist = j_serverlist['Name'] # 同一条WAN连接下进行比较 if tmp_ppp_path in tmp_serverlist: # 桥对桥,路由对路由 if ConnectionType in i_connect['Value']: if X_CT_COM_ServiceList in j_serverlist[ 'Value'] or j_serverlist[ 'Value'] in X_CT_COM_ServiceList: modify_path = j_serverlist['Name'] if j_serverlist[ '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 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 break else: continue #0 均相同,只修改LinkConfig.(参考a.1包) #1 两者均不相同的情况下:等同于查到是空的情况,后续新建WAN连接参考a.2包) #2 部分相同,而且关键点X_CT-COM_ServiceList不相同的情况下:等同于查到是空的情况,后续新建WAN连接(参考a.3包) #3 部分相同,而且关键点X_CT-COM_ServiceList相同的情况下:等同于查到均相同的情况,只修改LinkConfig.(参考a.4包) if WAN_Flag == None: #第三--一步:新建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 """ info = u"开始调用AddObject新建WANConnectionDevice实例。\n" log.app_info (info) ret_data_scr += info """ #第三--二步:新建WANIPConnection或WANPPPConnection实例 #只有是桥模式和路由PPPOE时,才新建WANPPPConnection实例 if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged': path4 = path2 + '.WANPPPConnection.' info = u"开始调用AddObject新建WAN连接的WANPPPConnection实例。\n" else: path4 = path2 + '.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 # 同一PVC下两条WAN连接不需要设置link层: """ 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_CT-COM_WANEponLinkConfig.' info = u"开始调用SetParameterValues设置X_CT-COM_WANEponLinkConfig参数。\n" elif DeviceType == 'VDSL': path5 = tmp_path3 + 'WANDSLLinkConfig.' info = u"开始调用SetParameterValues设置VDSL/ADSL兼容网关的WANDSLLinkConfig参数。\n" elif DeviceType == 'GPON': path5 = tmp_path3 + 'X_CT-COM_WANGponLinkConfig.' info = u"开始调用SetParameterValues设置X_CT-COM_WANGponLinkConfig参数。\n" else: path5 = tmp_path3 + 'WANDSLLinkConfig.' info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数。\n" log.app_info (info) ret_data_scr += info para_list5 = [] for i in dict_wanlinkconfig: if dict_wanlinkconfig[i][0] == 1: tmp_path = path5 + 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 else: #第三--三步:调用SetParameterValues设置linkconfig参数: path2_list = modify_path.split('.')[0:-3] path2_1_list = modify_path.split('.')[0:-1] path2 = '.'.join(path2_list) + '.' path2_1 = '.'.join(path2_1_list) + '.' #当查到有相匹配的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修改VDSL/ADSL兼容网关的WANDSLLinkConfig参数。\n" path5 = path2 + 'WANDSLLinkConfig.' 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 # 第七步:调用修改电信维护密码,目前密码固定为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
def IPV6IPTVEnable(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=0) 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 if AccessMode == 'PPPoE' or AccessMode == 'DHCP' or AccessMode == 'Static' or AccessMode == 'PPPoE_Bridged': if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged': X_CU_ServiceList = dict_wanpppconnection[ 'X_CU_ServiceList'][1] elif AccessMode == 'DHCP' or AccessMode == 'Static': X_CU_ServiceList = dict_wanipconnection[ 'X_CU_ServiceList'][1] ret_find, pvcorvlan_items, serverlist_items, connect_type_items, laninterface_items, ret_data_find = _find_wan_server_and_connecttype( u1, DeviceType, AccessMode, dict_wanpppconnection, dict_wanipconnection, ret_data_root, ret_data_scr) if ret_find == ERR_SUCCESS: ret_data_scr = ret_data_find else: ret_data_scr = ret_data_find return ret_res, ret_data_find if AccessMode == "PPPoE_Bridged": ConnectionType = "PPPoE_Bridged" else: ConnectionType = "IP_Routed" else: info = u"输入的AccessMode参数不合法,请检查!\n" log.app_info(info) ret_data_scr += info return ret_res, ret_data_scr WAN_Flag = None path2 = '' # 保存查到有相同的PVC或关键参数值的WAN连接路径 path2_1 = '' # 保存WANPPPConnection或WANIPConnection节点路径保存,后面修改参数时有用 for i_pvcorvlan in pvcorvlan_items: if i_pvcorvlan['Value'] == PVC_OR_VLAN: WAN_Flag = 0 path2 = i_pvcorvlan['Name'] break else: # 查不到匹配的PVC continue # 如果一直没有查到相同的,则没有对WAN_Flag标志位做过修改,则走新建流程 if WAN_Flag == None: WAN_Flag = 1 # 查不到匹配的PVC或VLAN,则走新建流程,否则还需再查WANPPPConnection节点下的值 if WAN_Flag == 0: # 不同的WAN连接模式,其节点路径不同 if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged': # 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': # 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] tmp_link_list = path2.split('.')[0:-2] tmp_link_path = '.'.join( tmp_link_list) # 保存XXXX.WANPPPConnection.i.路径 WAN_Flag_server = 1 WAN_Flag_connect = 1 WAN_Flag_interface = 1 if serverlist_items != []: # 查找到pvc及对应连接方式的serverlist,connecttype以及interface # X_CU_ServiceList for i_serverlist in serverlist_items: if tmp_link_path in i_serverlist['Name']: if i_serverlist['Value'] == tmp_X_CU_ServiceList: pass else: tmp_path3_list = i_serverlist['Name'].split( '.')[0:-1] ret_tmp_path3 = '.'.join(tmp_path3_list) + "." WAN_Flag_server = 0 # ConnectionType for i_connect_type in connect_type_items: if tmp_link_path in i_connect_type['Name']: if i_connect_type['Value'] == tmp_ConnectionType: pass else: # 路由和桥的区别时,需重新走新建WAN连接流程 GCW 20130506 WAN_Flag_connect = 3 break # X_CU_LanInterface for i_laninterface in laninterface_items: if tmp_link_path in i_laninterface['Name']: if i_laninterface[ 'Value'] == tmp_X_CU_LanInterface: pass else: tmp_path3_list = i_laninterface['Name'].split( '.')[0:-1] ret_tmp_path3 = '.'.join(tmp_path3_list) + "." WAN_Flag_interface = 0 else: # 查找到pvc但是没有对应连接方式的serverlist,connecttype以及interface,此时需要走新建流程 WAN_Flag_connect = 3 if WAN_Flag_connect != 3: # 如果有一个不匹配,则修改WANPPPConnection节点下的值 if WAN_Flag_interface == 0 or WAN_Flag_server == 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' info = u"查找到匹配的PVC(VLAN)但参数不匹配,走修改WAN连接。\n" log.app_info(info) ret_data_scr += info if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged': tmp_values = dict_wanpppconnection info = u"查询到的值与用户工单中传参过来的有不相等情况,开始调用SetParameterValues修改参数。\n" else: tmp_values = dict_wanipconnection info = u"查询到的值与用户工单中传参过来的有不相等情况,开始调用SetParameterValues修改参数。\n" log.app_info(info) ret_data_scr += info # 第三--四步:调用SetParameterValues设置WANPPPConnection参数: # 同时下发IGMP参数; path6 = ret_tmp_path3 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])) # IGMP参数 path = 'InternetGatewayDevice.Services.X_CU_IPTV.' for i in dict_root: if dict_root[i][0] == 1: tmp_path = path + i para_list6.append( dict(Name=tmp_path, Value=dict_root[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 else: info = u"查询到的值与用户工单中传参过来的相等,无需修改WAN连接参数 。\n" log.app_info(info) ret_data_scr += info else: WAN_Flag = 1 # 重置WAN_Flag标志位,走新建WAN连接流程 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,WANPPPConnection(或WANIPConnection)及IGMP参数。\n" elif DeviceType == 'LAN': path5 = tmp_path3 + 'WANEthernetLinkConfig.' info = u"开始调用SetParameterValues设置WANEthernetLinkConfig,WANPPPConnection(或WANIPConnection)及IGMP参数。\n" elif DeviceType == 'EPON': path5 = tmp_path3 info = u"开始调用SetParameterValues设置X_CU_VLAN,WANPPPConnection(或WANIPConnection)及IGMP参数。\n" elif DeviceType == 'VDSL': path5 = tmp_path3 + 'WANDSLLinkConfig.' info = u"开始调用SetParameterValues设置VDSL/ADSL兼容网关的WANDSLLinkConfig,WANPPPConnection(或WANIPConnection)及IGMP参数。\n" elif DeviceType == 'GPON': path5 = tmp_path3 info = u"开始调用SetParameterValues设置X_CU_VLAN,WANPPPConnection(或WANIPConnection)及IGMP参数。\n" else: path5 = tmp_path3 + 'WANDSLLinkConfig.' info = u"开始调用SetParameterValues设置WANDSLLinkConfig,WANPPPConnection(或WANIPConnection)及IGMP参数。\n" log.app_info(info) ret_data_scr += info # 添加link层 para_list5 = [] for i in dict_wanlinkconfig: if dict_wanlinkconfig[i][0] == 1: tmp_path = path5 + 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 # 添加ppp或ip层 if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged': tmp_values = dict_wanpppconnection else: tmp_values = dict_wanipconnection path6 = tmp_path4 + '.' 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_list5.append( dict(Name=tmp_path, Value=tmp_values[i][1])) # 添加IGMP # IGMP参数 path = 'InternetGatewayDevice.X_CU_Function.IGMP.' for i in dict_root: if dict_root[i][0] == 1: tmp_path = path + i para_list5.append( dict(Name=tmp_path, Value=dict_root[i][1])) 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 # 将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
def SmartTV(obj,sn, X_CT_COM_Mode, X_CT_COM_VLAN, IPTV_Interface, change_account=1): """ 开通智能电视,即,将LAN侧(除绑定IPTV外的接口)与IPTV WAN连接的VLAN绑定 """ ret_res = ERR_FAIL # 返回成功或失败 ret_data_scr = "" # 返回结果日志 Lan_Interface_Path = "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig." for i 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 ret, lan_iptv = ParseLANName(IPTV_Interface) if ret == ERR_FAIL: info = u'输入的X_CT_COM_LanInterface参数错误' log.app_err (info) ret_data_scr += info return ret_res, ret_data_scr info = u"开始调用GetParameterNames方法,查询LANEthernetInterfaceConfig信息。\n" log.app_info (info) ret_data_scr += info ret_lan_device, ret_data_lan_device = u1.get_parameter_names(ParameterPath=Lan_Interface_Path, NextLevel=0) if (ret_lan_device == ERR_SUCCESS): info = u"查询LANEthernetInterfaceConfig信息成功。\n" log.app_info (info) ret_data_scr += info ret_data_lan_device = DelOwnParameterNames(ret_data_lan_device, Lan_Interface_Path) else: #对于失败的情况,直接返回失败 info = u"查询LANEthernetInterfaceConfig信息失败,错误信息:%s 。\n" % ret_data_device_info log.app_err (info) ret_data_scr += info return ret_res, ret_data_scr reg_LAN_Mode = "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.[1-9]+.X_CT-COM_Mode" reg_LAN_VLAN = "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.[1-9]+.X_CT-COM_VLAN" bind_lan_list = [] for i in xrange(len(ret_data_lan_device['ParameterList'])): tmp_lan_path = ret_data_lan_device['ParameterList'][i]['Name'] m_Mode = re.match(reg_LAN_Mode,tmp_lan_path) m_VLAN = re.match(reg_LAN_VLAN,tmp_lan_path) if (m_Mode is not None) and (lan_iptv not in tmp_lan_path): bind_lan_list.append(dict(Name=tmp_lan_path,Value=X_CT_COM_Mode)) if (m_VLAN is not None) and (lan_iptv not in tmp_lan_path): bind_lan_list.append(dict(Name=tmp_lan_path,Value=X_CT_COM_VLAN)) if bind_lan_list == []: info = u"未查找到LAN侧的X_CT-COM_Mode和X_CT-COM_Vlan节点。" log.app_err (info) ret_data_scr += info return ret_res, ret_data_scr info = u"开始调用SetParameterValues设置LAN侧的X_CT-COM_Mode和X_CT-COM_VLAN。\n" log.app_info (info) ret_data_scr += info ret, ret_data = u1.set_parameter_values(ParameterList=bind_lan_list) if (ret == ERR_SUCCESS): info = u"设置参数成功。\n" log.app_info (info) ret_data_scr += info rebootFlag = int(ret_data["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,直接返回失败 info = u"设置参数失败,错误原因:%s 。\n" % ret_data 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
def start_alarm_worklist(cpe, obj_alarm): """ obj_alarm is MsgAlarmInform """ ret = ERR_FAIL err_message = "" sn = cpe.get_sn() for nwf in [1]: # physic worklist --------------- dict_data = { "parameterlist": obj_alarm.parameterlist, "limit_max": obj_alarm.limit_max, "limit_min": obj_alarm.limit_min, "timelist": obj_alarm.timelist, "mode": obj_alarm.mode } obj = MsgWorklistBuild("Inform_Monitor_Alarm_Start", dict_data) obj_database = EventCode.auto_build_bind_physic_worklist(cpe, obj) # save_id2worklistid(obj_alarm.id_, obj_database.id_) try: ret, err_message = EventCode.tx_worklist_exec(obj_database) ret = EventCode.rx_worklist_exec(ret, err_message) if (ret == ERR_SUCCESS): ret, err_message = EventCode.wait_worklist_exec_finish( obj_database) if ret == ERR_SUCCESS: desc = "start_alarm_worklist(id=%s) success." % ( obj_database.id_) log.app_info(desc) obj_alarm.dict_ret["str_result"] = desc else: # worklist(id=worklist_2014-07-08_11:48:15.781_82424709) status is not success(fail) # nwf 2014-07-08; +worklist fail obj_db = restore_acs_worklist(obj_database.id_) err_message = err_message + "\n" + obj_db.dict_ret[ "str_result"] log.app_err(err_message) obj_alarm.dict_ret["str_result"] = err_message break else: log.app_err(err_message) obj_alarm.dict_ret["str_result"] = err_message break except Exception, e: print_trace(e) obj_alarm.dict_ret["str_result"] = e break ret = ERR_SUCCESS
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
log.app_info("Auto process get rpc methods") ret_rpc, ret_data = u1.get_rpc_methods() ret_datas = ret_datas + "\n" + str(ret_data) if ret_rpc == ERR_SUCCESS: info = "success:%s" % ret_data log.app_info(info) else: info = "fail:%s" % ret_data log.app_err(info) break ret_worklist = ERR_SUCCESS except Exception, e: info = str(e) log.app_err(info) ret_datas = ret_datas + "\n" + info break obj.dict_ret["str_result"] = ret_datas return ret_worklist if __name__ == '__main__': log_dir = g_prj_dir log.start(name="nwf", directory=log_dir, level="DebugWarn") log.set_file_id(testcase_name="tr069") obj = MsgWorklistExecute(id_="1") obj.sn = "2013012901" test_script(obj)
def IPV6VOIP(obj, sn, WANEnable_Switch, DeviceType, AccessMode, PVC_OR_VLAN, dict_voiceservice, dict_wanlinkconfig={}, dict_wanpppconnection={}, dict_wanipconnection={}, change_account=1, rollbacklist=[]): """ """ ret_res = ERR_FAIL # 脚本返回值,成功或失败.缺省失败 ret_data_scr = "" # 返回结果日志 ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice." voiceservice_path = "InternetGatewayDevice.Services.VoiceService.1." 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=0) 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 if AccessMode == 'PPPoE' or AccessMode == 'DHCP' or AccessMode == 'Static' or AccessMode == 'PPPoE_Bridged': if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged': X_CT_COM_ServiceList = dict_wanpppconnection[ 'X_CT-COM_ServiceList'][1] elif AccessMode == 'DHCP' or AccessMode == 'Static': X_CT_COM_ServiceList = dict_wanipconnection[ 'X_CT-COM_ServiceList'][1] ret_find, serverlist_items, connect_type_items, ret_data_find = _find_wan_server_and_connecttype( u1, AccessMode, dict_wanpppconnection, dict_wanipconnection, ret_data_root, ret_data_scr) if ret_find == ERR_SUCCESS: ret_data_scr = ret_data_find else: ret_data_scr = ret_data_find return ret_res, ret_data_find if AccessMode == "PPPoE_Bridged": ConnectionType = "PPPoE_Bridged" else: ConnectionType = "IP_Routed" else: info = u"输入的AccessMode参数不合法,请检查!\n" log.app_info(info) ret_data_scr += info return ret_res, ret_data_scr WAN_Flag = None modify_path = None for i_connect in connect_type_items: tmp_ppp_list = i_connect['Name'].split('.')[0:-1] tmp_ppp_path = '.'.join( tmp_ppp_list) # 保存XXXX.WANPPPConnection.i.路径 # 确定WAN,是否修改 for j_serverlist in serverlist_items: tmp_serverlist = j_serverlist['Name'] # 同一条WAN连接下进行比较 if tmp_ppp_path in tmp_serverlist: # 桥对桥,路由对路由 if ConnectionType in i_connect['Value']: if X_CT_COM_ServiceList in j_serverlist[ 'Value'] or j_serverlist[ 'Value'] in X_CT_COM_ServiceList: modify_path = j_serverlist['Name'] if j_serverlist[ '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 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 break else: continue if WAN_Flag == None: info = u"查找不到匹配 %s 模式的WAN连接。" % X_CT_COM_ServiceList log.app_info(info) ret_data_scr += info WAN_Flag = 1 # 下发VOIP参数 voipflag = "Enabled" #开通或取消VOIP工单的状态标识位 para_list = [] for i in dict_voiceservice: if dict_voiceservice[i][0] == 1: tmp_path = voiceservice_path + i # 根据传参进来字典中来查找是VOIP开通还是取消, # 设置状态位来决定后面不要再走新建或修改WAN连接的流程 if "VoiceProfile.1.Line.1.Enable" == i: voipflag = dict_voiceservice[i][1] para_list.append( dict(Name=tmp_path, Value=dict_voiceservice[i][1])) # 如果是VOIP取消工单,但又没有找到相等或包含X_CT-COM_ServiceList的WAN连接,则退出报成功 if voipflag == "Disabled" and (WAN_Flag == 1 or WAN_Flag == 2): info = u"取消VOIP工单,但查不到%s 的WAN连接。\n" % X_CT_COM_ServiceList log.app_info(info) ret_data_scr += info ret_res = ERR_SUCCESS return ret_res, ret_data_scr info = u"开始调用SetParameterValues设置VOIP参数。\n" log.app_info(info) ret_data_scr += info #sleep(3) # must be ;otherwise exception ret5, ret_data5 = u1.set_parameter_values(ParameterList=para_list) 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 #0 均相同,只修改LinkConfig.(参考a.1包) #1 两者均不相同的情况下:等同于查到是空的情况,后续新建WAN连接参考a.2包) #2 部分相同,而且关键点X_CT-COM_ServiceList不相同的情况下:等同于查到是空的情况,后续新建WAN连接(参考a.3包) #3 部分相同,而且关键点X_CT-COM_ServiceList相同的情况下:等同于查到均相同的情况,只修改LinkConfig.(参考a.4包) if (WAN_Flag == 1 or WAN_Flag == 2) and voipflag == "Enabled": #第三--一步:新建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: info = u"工单失败:为避免新建包含tr069模式的WAN连接对原有tr069WAN连接产生影响,所以不再新建。\n" log.app_info(info) ret_data_scr += info return ret_res, ret_data_scr 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_CT-COM_WANEponLinkConfig.' info = u"开始调用SetParameterValues设置X_CT-COM_WANEponLinkConfig参数。\n" elif DeviceType == 'VDSL': path5 = tmp_path3 + 'WANDSLLinkConfig.' info = u"开始调用SetParameterValues设置VDSL/ADSL兼容网关的WANDSLLinkConfig参数。\n" elif DeviceType == 'GPON': path5 = tmp_path3 + 'X_CT-COM_WANGponLinkConfig.' info = u"开始调用SetParameterValues设置X_CT-COM_WANGponLinkConfig参数。\n" else: path5 = tmp_path3 + 'WANDSLLinkConfig.' info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数。\n" log.app_info(info) ret_data_scr += info para_list5 = [] for i in dict_wanlinkconfig: if dict_wanlinkconfig[i][0] == 1: tmp_path = path5 + 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) and voipflag == "Enabled": #第三--三步:调用SetParameterValues设置linkconfig参数: path2_list = modify_path.split('.')[0:-3] path2_1_list = modify_path.split('.')[0:-1] path2 = '.'.join(path2_list) + '.' path2_1 = '.'.join(path2_1_list) + '.' #当查到有相匹配的X_CT-COM_ServiceList和Username值时的处理流程,不需要新建,只需更改WANIPConnection或WANPPPConnection节点下的参数即可 #第三--三步:调用SetParameterValues设置linkconfig参数: # 针对v6工单,修改流程时不下发link层的修改 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修改VDSL/ADSL兼容网关的WANDSLLinkConfig参数。\n" path5 = path2 + 'WANDSLLinkConfig.' 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 = [] for i in tmp_values: if tmp_values[i][0] == 1: # GCW 20130408 判断X_CT-COM_ServiceList包含与被包含的关系做区分处理. # 标志位0表示X_CT-COM_ServiceList值需以工单中的为准,重新下发,3(即else)表示不下发 if WAN_Flag == 0: pass else: if i == 'X_CT-COM_ServiceList': 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 # 如果需要重启,则下发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
def bind_cu(cpe, user_name=None, user_id=None): """ in thread """ ret = ERR_FAIL err_message = "" logic_worklists = [] status_value = 0 # default success status_result = 0 # default success # nwf 2013-06-28 -------------------------------------------------- no_rpc_name = webservercfg.LOGIC_WORKLIST_NO_RPC_NAME no_rpc_id = webservercfg.LOGIC_WORKLIST_NO_RPC_ID if ((no_rpc_name.upper() == user_name.upper()) and (no_rpc_id.upper() == user_id.upper())): return bind_no_rpc_cu(cpe, user_name, user_id) # ---------------------------------------------------------- sn = cpe.get_sn() for nwf in [1]: status_value, logic_worklists = bind_get_status_worklists( cpe, user_name, user_id) desc = "step1: InternetGatewayDevice.X_CU_UserInfo.Status = %s" % ( status_value) log.app_info(desc) node_name = "InternetGatewayDevice.X_CU_UserInfo.Status" ret = bind_set_status(cpe, status_value, node_name) if (ret != ERR_SUCCESS): break # continue? if (status_value != 0): desc = "step1: InternetGatewayDevice.X_CU_UserInfo.Status = %s(!=0, stopped)" % ( status_value) log.app_err(desc) break # 重置双向DIGEST认证账号终端维护账号密码 --added by lana 20131209 ret = reset_digest_account_and_telecom_account_cu(cpe) if ret != ERR_SUCCESS: break # change the sn to hold for obj in logic_worklists: obj.sn = sn # mysql update_acs_worklist(obj, "SN", obj.sn) update_acs_worklist(obj, "CPE_ID", cpe.get_cpe_id()) # sort logic_worklists by time_bind logic_worklists = sorted(logic_worklists, key=attrgetter('time_bind')) node_name = "InternetGatewayDevice.X_CU_UserInfo.Result" ret = bind_set_result(cpe, "0", node_name) if (ret != ERR_SUCCESS): break status_result = bind_do_worklists(logic_worklists) ret = bind_set_result(cpe, status_result, node_name) return ret
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
def bootstrap_cu(cpe): """ in thread """ ret = ERR_FAIL err_message = "" sn = cpe.get_sn() for nwf in [1]: # 获取上网账号和密码 # 组建工单参数 dict_data = {} # 组建工单消息,下发工单执行命令 obj = MsgWorklistBuild("Auto_GetPPPConnectionAccount", dict_data) obj_database = EventCode.auto_build_bind_physic_worklist(cpe, obj) try: ret, err_message = EventCode.tx_worklist_exec(obj_database) ret = EventCode.rx_worklist_exec(ret, err_message) if (ret == ERR_SUCCESS): ret, err_message = EventCode.wait_worklist_exec_finish( obj_database) if ret == ERR_SUCCESS: desc = "worklist(Auto_GetPPPConnectionAccount) execute success." log.app_info(desc) else: log.app_err(err_message) # 忽略查询结果 # break else: desc = "worklist(Auto_GetPPPConnectionAccount) execute fail." log.app_err(desc) break except Exception, e: print_trace(e) break # physic worklist --------------- obj = MsgWorklistBuild("Auto_GetRPCMethods", {}) obj_database = EventCode.auto_build_bind_physic_worklist(cpe, obj) try: ret, err_message = EventCode.tx_worklist_exec(obj_database) ret = EventCode.rx_worklist_exec(ret, err_message) if (ret == ERR_SUCCESS): ret, err_message = EventCode.wait_worklist_exec_finish( obj_database) if ret == ERR_SUCCESS: desc = "worklist(Auto_GetRPCMethods) execute success." log.app_info(desc) else: log.app_err(err_message) break else: desc = "worklist(Auto_GetRPCMethods) execute fail." log.app_err(desc) break except Exception, e: print_trace(e) break
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
def reset_digest_account_and_telecom_account_cu(cpe): """ 重置联通双向的DIGEST认证账号和终端维护账号密码 """ ret = ERR_FAIL err_message = "" for i in [1]: # 新的双向的DIGEST认证账号的生成规则为:old+8为随机数 user_name = get_random_8str(cpe.cpe_property.get_cpe2acs_loginname()) password = get_random_8str( cpe.cpe_property.get_cpe2acs_loginpassword()) connection_request_user_name = get_random_8str( cpe.cpe_property.get_acs2cpe_loginname()) connection_request_password = get_random_8str( cpe.cpe_property.get_acs2cpe_loginpassword()) # 新的电信维护账号密码的生成规则为 “cutelecomadmin” + 8位随机数 tele_com_account_password = get_random_8str("cuadmin") # 组建所有要设置的节点参数 dict_data = { "ParameterList": [ dict(Name="InternetGatewayDevice.ManagementServer.Username", Value=user_name), dict(Name="InternetGatewayDevice.ManagementServer.Password", Value=password), dict( Name= "InternetGatewayDevice.ManagementServer.ConnectionRequestUsername", Value=connection_request_user_name), dict( Name= "InternetGatewayDevice.ManagementServer.ConnectionRequestPassword", Value=connection_request_password), dict(Name= "InternetGatewayDevice.X_CU_Function.Web.AdminPassword", Value=tele_com_account_password) ] } # 组建工单消息,下发工单执行命令 obj = MsgWorklistBuild("Auto_SetParameterValue", dict_data) obj_database = EventCode.auto_build_bind_physic_worklist(cpe, obj) try: ret, err_message = EventCode.tx_worklist_exec(obj_database) ret = EventCode.rx_worklist_exec(ret, err_message) if (ret == ERR_SUCCESS): ret, err_message = EventCode.wait_worklist_exec_finish( obj_database) if ret == ERR_SUCCESS: cpe.cpe_property.set_cpe2acs_loginname(user_name) cpe.cpe_property.set_cpe2acs_loginpassword(password) cpe.cpe_property.set_acs2cpe_loginname( connection_request_user_name) cpe.cpe_property.set_acs2cpe_loginpassword( connection_request_password) log.app_info( "worklist(Auto_SetParameterValue) execute success.") log.app_info( "update InternetGatewayDevice.ManagementServer.Username success: %s" % user_name) log.app_info( "update InternetGatewayDevice.ManagementServer.Password success: %s" % password) log.app_info( "update InternetGatewayDevice.ManagementServer.ConnectionRequestUsername success: %s" % connection_request_user_name) log.app_info( "update InternetGatewayDevice.ManagementServer.ConnectionRequestPassword success: %s" % connection_request_password) log.app_info( "update InternetGatewayDevice.X_CU_Function.Web.AdminPassword success: %s" % tele_com_account_password) else: log.app_err(err_message) break else: desc = "worklist(Auto_SetParameterValue) execute fail." log.app_err(desc) break except Exception, e: print_trace(e) break ret = ERR_SUCCESS
def QoS(obj, sn, DeviceType, dict_root, dict_app, list_value_type, dict_classification, dict_priorityQueue, change_account=1, rollbacklist=[]): """ """ ret_res = ERR_FAIL # 返回成功或失败 ret_data_scr = "" # 返回结果日志 #QoS的根节点 QoS_ROOT_PATH = "InternetGatewayDevice.X_CT-COM_UplinkQoS." 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 #第一步:启用QoS和设置调度策略、DSCP及其他标志 info = u"开始启用QoS和设置调度策略、DSCP及其它标志\n" log.app_info(info) ret_data_scr += info para_list1 = [] for i in dict_root: if dict_root[i][0] == 1: tmp_path = QoS_ROOT_PATH + i para_list1.append( dict(Name=tmp_path, Value=dict_root[i][1])) if para_list1 == []: info = u"参数为空,请检查" log.app_info(info) ret_data_scr += info return ret_res, ret_data_scr #sleep(3) # must be ;otherwise exception ret_root, ret_data_root = u1.set_parameter_values( ParameterList=para_list1) if (ret_root == ERR_SUCCESS): info = u"启用QoS和设置调度策略、DSCP及其它标志成功\n" log.app_info(info) ret_data_scr += info rebootFlag = int(ret_data_root["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,直接返回错误 info = u"启用QoS和设置调度策略、DSCP及其它标志失败,错误原因:%s\n" % ret_data_root log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr #第二步:增加队列实例 #针对基于业务的QoS保障测试-UDP工单,需要多个TYPE实例 tmp_Classification_path = [ ] # GCW 20130418 增加一步新建Classification实例的动作 list_path3 = [] # Classification.{i}.type.路径下需下发的参数列表 # 取队列号 class_num = dict_classification['ClassQueue'][1] for i in xrange(len(list_value_type)): # GCW 20130418比贝曼增加一步,新增加以下实例 # InternetGatewayDevice.X_CT-COM_UplinkQoS.Classification. info = u"开始调用AddObject新建Classification实例\n" log.app_info(info) ret_data_scr += info Classification_path = "InternetGatewayDevice.X_CT-COM_UplinkQoS.Classification." #sleep(3) # must be ;otherwise exception ret_add, ret_data_add = u1.add_object( ObjectName=Classification_path) if (ret_add == ERR_SUCCESS): instanceNum1 = ret_data_add["InstanceNumber"] info = u"新建Classification实例成功,返回实例号:%s\n" % instanceNum1 log.app_info(info) ret_data_scr += info tmp_Classification_path.append(Classification_path + instanceNum1 + ".") # GCW 20130327 增加回退机制 rollbacklist.append(Classification_path + instanceNum1 + ".") rebootFlag = int(ret_data_add["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,返回失败 info = u"新建Classification实例失败,退出执行,错误原因:%s\n" % ret_data_add log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr info = u"开始调用AddObject新建type实例\n" log.app_info(info) ret_data_scr += info type_path = Classification_path + instanceNum1 + ".type." #sleep(3) # must be ;otherwise exception ret_add, ret_data_add = u1.add_object(ObjectName=type_path) if (ret_add == ERR_SUCCESS): instanceNum1 = ret_data_add["InstanceNumber"] info = u"新建type实例成功,返回实例号:%s\n" % instanceNum1 log.app_info(info) ret_data_scr += info # GCW 20130327 增加回退机制 # GCW 20130419 由于增加了步骤新建Classification实例,所以回滚直接删除Classification实例 # rollbacklist.append(type_path + instanceNum1 + ".") rebootFlag = int(ret_data_add["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,返回失败 info = u"新建type实例失败,退出执行,错误原因:%s\n" % ret_data_add log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr list_path3.append(type_path + instanceNum1 + ".") #第三步:对队列各个参数进行配置 #注意,电信规范上没有分开写,即可以解读为是在一个RPC中下发后面第三四五步的所有参数, #而且对A上行,还有要求VLAN,但贝曼工单抓包看这两点均没有.目前按贝曼实现,待完善! for i in xrange(len(list_path3)): info = u"开始调用SetParameterValues,对队列各个参数进行配置\n" log.app_info(info) ret_data_scr += info para_list3 = [] dict_type = list_value_type[i] for j in dict_type: if dict_type[j][0] == 1: tmp_path = list_path3[i] + j para_list3.append( dict(Name=tmp_path, Value=dict_type[j][1])) if para_list3 == []: info = u"参数为空,请检查\n" log.app_info(info) ret_data_scr += info return ret_res, ret_data_scr #sleep(3) # must be ;otherwise exception ret_type, ret_data_type = u1.set_parameter_values( ParameterList=para_list3) if (ret_type == ERR_SUCCESS): info = u"对队列各个参数进行配置成功\n" log.app_info(info) ret_data_scr += info rebootFlag = int(ret_data_type["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,返回失败 info = u"对队列各个参数进行配置失败,错误原因:%s\n" % ret_data_type log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr #可以有个开关控制是否将以下参数与上面的参数一起下发。电信规范上是一起 #第四步:对流分类进行配置 # GCW 20130418增加了对Classification的设置. info = u"开始调用SetParameterValues,对Classification参数进行配置\n" log.app_info(info) ret_data_scr += info #path4 = QoS_ROOT_PATH + "Classification." + class_num + "." para_list4 = [] for i in xrange(len(tmp_Classification_path)): for j in dict_classification: if dict_classification[j][0] == 1: tmp_path = tmp_Classification_path[i] + j para_list4.append( dict(Name=tmp_path, Value=dict_classification[j][1])) if para_list4 == []: info = u"参数为空,请检查\n" log.app_info(info) ret_data_scr += info return ret_res, ret_data_scr #sleep(3) # must be ;otherwise exception ret_class, ret_data_class = u1.set_parameter_values( ParameterList=para_list4) if (ret_class == ERR_SUCCESS): info = u"对Classification进行配置成功\n" log.app_info(info) ret_data_scr += info rebootFlag = int(ret_data_class["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,返回失败 info = u"对Classification进行配置失败,错误原因:%s\n" % ret_data_class log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr #第五步:对优先级队列进行配置 info = u"开始调用SetParameterValues,对优先级队列进行配置\n" log.app_info(info) ret_data_scr += info path5 = QoS_ROOT_PATH + "PriorityQueue." + class_num + "." para_list5 = [] for i in dict_priorityQueue: if dict_priorityQueue[i][0] == 1: tmp_path = path5 + i para_list5.append( dict(Name=tmp_path, Value=dict_priorityQueue[i][1])) if para_list5 == []: return ret_res, ret_data_scr #sleep(3) # must be ;otherwise exception ret_prio, ret_data_prio = u1.set_parameter_values( ParameterList=para_list5) if (ret_prio == ERR_SUCCESS): info = u"对优先级队列进行配置成功\n" log.app_info(info) ret_data_scr += info rebootFlag = int(ret_data_prio["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,返回失败 info = u"对优先级队列进行配置失败,错误原因:%s\n" % ret_data_prio 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
def WLANMulti(obj, sn, Num, dict_root, dict_WEPKey, dict_PreSharedKey, change_account=0, rollbacklist=[]): """ """ ret_res = ERR_FAIL # 脚本返回值,成功或失败.缺省失败 ret_data_scr = "" # 返回结果日志 #绑定tr069模板类型,暂时只定义为上行方式 DeviceType = 'ADSL' ROOT_PATH = "InternetGatewayDevice.LANDevice.1.WLANConfiguration." 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方法,查找当前有几个无线实例 info = u"开始调用GetParameterNames方法,查找当前无线实例\n" log.app_info(info) ret_data_scr += info para_list = [] path = ROOT_PATH ret_root, ret_data1_root = u1.get_parameter_names( ParameterPath=path, NextLevel='1') #sleep(2) # must be ;otherwise exception if (ret_root == ERR_SUCCESS): info = u"查找当前无线实例成功\n" log.app_info(info) ret_data_scr += info # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除 ret_data1_root = DelOwnParameterNames(ret_data1_root, path) else: #对于失败的情况,如何处理? info = u"查找当前无线实例失败,返回错误:%s\n" % ret_data1_root log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr #第二步:直接增加N个实例。如果有个数超出范围的问题,则由CPE处理判断 para_list = [] path = ROOT_PATH path2 = [] #将查到的实例号路径追加到列表中 for i in xrange(len(ret_data1_root['ParameterList'])): path2.append(ret_data1_root['ParameterList'][i]['Name']) # 新建实例个数等于传参进来的个数减去查到已经存在的个数,但如要Num为0或者小于已有实例个数,则不需新建 if (int(Num) > len(ret_data1_root['ParameterList'])): info = u"开始调用AddObject,增加无线实例\n" log.app_info(info) ret_data_scr += info for i in xrange( int(Num) - len(ret_data1_root['ParameterList'])): ret_addobject, ret_data_addobject = u1.add_object( ObjectName=path) #sleep(2) # must be ;otherwise exception if (ret_addobject == ERR_SUCCESS): instanceNum1 = ret_data_addobject["InstanceNumber"] path2.append(path + instanceNum1 + '.') # GCW 20130327 增加回退机制 rollbacklist.append(path + instanceNum1 + '.') info = u"增加无线实例成功,返回实例号:%s\n" % instanceNum1 log.app_info(info) ret_data_scr += info rebootFlag = int(ret_data_addobject["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,直接返回失败 info = u"增加无线实例失败,失败信息:%s\n" % ret_data_addobject log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr else: info = u"已经开通的无线实例个数大于或等于 %s\n" % str(Num) log.app_info(info) ret_data_scr += info # 第三步,使能X_CT-COM_APModuleEnable para_list = [] info = u"开始调用SetParameterValues对各个无线实例的X_CT-COM_APModuleEnable进行使能\n" log.app_info(info) ret_data_scr += info for i in xrange(len(path2)): tmp_path = path2[i] + 'X_CT-COM_APModuleEnable' para_list.append(dict(Name=tmp_path, Value='1')) ret_root, ret_data_root = u1.set_parameter_values( ParameterList=para_list) #sleep(2) # must be ;otherwise exception if (ret_root == ERR_SUCCESS): info = u"对所有无线实例的X_CT-COM_APModuleEnable进行使能成功\n" log.app_info(info) ret_data_scr += info rebootFlag = int(ret_data_root["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,直接返回错误 info = u"对所有无线实例的X_CT-COM_APModuleEnable进行使能失败,返回错误:%s\n" % ret_data_root log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr # 第四步:对队列各个参数进行配置 for i in xrange(len(path2)): info = u"对第%s个无线实例的参数进行配置\n" % str(i + 1) log.app_info(info) ret_data_scr += info # 根据电信的抓包,SSID1不修改,SSID2为WEP,SSID3和SSID4为不加密 if i == 0: # 对WLAN1不做任何修改 info = u"根据业务流程,对第%s个无线实例的参数不做修改\n" % str(i + 1) log.app_info(info) ret_data_scr += info continue elif i == 1: # WEP加密 para_list = [] path = path2[i] for j in dict_root: if dict_root[j][0] == 1: tmp_path = path + j para_list.append( dict(Name=tmp_path, Value=dict_root[j][1])) if para_list == []: info = u"参数为空,请检查\n" log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr elif i == 2: # 不加密码 para_list = [] path = path2[i] tmp_path_1 = path + 'Enable' tmp_path_2 = path + 'BeaconType' para_list.append(dict(Name=tmp_path_1, Value='1')) para_list.append(dict(Name=tmp_path_2, Value='None')) # 继续循环,以便将WLAN4的参数一起追加下发 info = u"根据业务流程,对第%s个无线实例的参数进行保存,与下一个无线实例参数一起下发\n" % str( i + 1) log.app_info(info) ret_data_scr += info continue elif i == 3: # 不加密 path = path2[i] tmp_path_1 = path + 'Enable' tmp_path_2 = path + 'BeaconType' para_list.append(dict(Name=tmp_path_1, Value='1')) para_list.append(dict(Name=tmp_path_2, Value='None')) #设置值 ret_root, ret_data_root = u1.set_parameter_values( ParameterList=para_list) #sleep(2) # must be ;otherwise exception if (ret_root == ERR_SUCCESS): info = u"对第%s个无线实例的参数进行配置成功\n" % str(i + 1) log.app_info(info) ret_data_scr += info rebootFlag = int(ret_data_root["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,直接返回错误 info = u"对第%s个无线实例的参数进行配置失败,返回错误:%s\n" % (str(i + 1), ret_data_root) log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr # 如果是WLAN2,则设置WEP密钥 if i == 1: info = u"对第%s个无线实例的WEP密钥进行配置\n" % str(i + 1) log.app_info(info) ret_data_scr += info if dict_root['WEPKeyIndex'][0] != 1: info = u"传参时,字典中KEY索引没有打开,请检查\n" log.app_err(info) ret_data_scr += info return ret_res, ret_data_scr #KEY索引没有打开,不建议再判断索引值范围。 path_WEPKey = path2[i] + 'WEPKey.' + dict_root[ 'WEPKeyIndex'][1] + '.WEPKey' para_list = [] para_list.append( dict(Name=path_WEPKey, Value=dict_WEPKey['WEPKey'][1])) #设置值 ret_WEPKey, ret_data_WEPKey = u1.set_parameter_values( ParameterList=para_list) #sleep(1) # must be ;otherwise exception if (ret_WEPKey == ERR_SUCCESS): info = u"对第%s个无线实例的WEP密钥进行配置成功\n" % str(i + 1) log.app_info(info) ret_data_scr += info rebootFlag = int(ret_data_WEPKey["Status"]) if (rebootFlag == 1): reboot_Yes = 1 else: #对于失败的情况,直接返回错误 info = u"对第%s个无线实例的WEP密钥进行配置失败,返回错误%s\n" % ( str(i + 1), ret_data_WEPKey) 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
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
def get_url(sn, url, username, password): """ """ from cpe import CPE ret = AUTHENTICATE_FAIL ret_api = None err_messsage = "" soap_id = 0 desc = "begin get url(url=%s, username=%s, password=%s)." % (url, username, password) log.app_info(desc) if (not sn): err_messsage = "The sn is not exist" log.app_info(err_messsage) return AUTHENTICATE_FAIL, err_messsage if (not url): err_messsage = "The url is not exist(need inform?)" log.app_info(err_messsage) return AUTHENTICATE_FAIL, err_messsage # nwf 2013-06-09; retry 3times if error(10060 or 10065) for i in [1, 2]: try: #conn = httplib2.Http(timeout = 60) conn = MyHttp(sn, timeout=60) # Alter by lizn 2014-05-30 conn.add_credentials(username, password) # mysql ; first cpe = CPE.get_cpe(sn) time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') cpe.cpe_soap.time_s1_start = time # Alter by lizn 2014-03-11 # mysql ------------- out content = "username=%s; password=%s; url=%s" % (username, password, url) #insert_acs_soap("connection request", "OUT", sn, content) by lizn 2014-05-30 ret_api, data = conn.request(url) # mysql -------------- in content = str(ret_api) + "\n\n" + data #soap_id = insert_acs_soap("connection request", "IN", sn, content) by lizn 2014-05-30 # mysql ; first end time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') cpe.cpe_soap.time_s1_finish = time # Alter by lizn 2014-03-11 status = ret_api.status conn.close() if status == AUTHENTICTATE_SUCCEED: err_messsage = "Get cpe url(url=%s, username=%s, password=%s) success." % ( url, username, password) log.app_info(err_messsage) ret = AUTHENTICTATE_SUCCEED break else: err_messsage = "Get cpe url(url=%s, username=%s, password=%s) not pass." % ( url, username, password) log.app_info(err_messsage) ret = AUTHENTICATE_FAIL break except Exception, e: err_messsage = "Get cpe url(url=%s, username=%s, password=%s) fail:%s." % ( url, username, password, e) log.app_err(err_messsage) # friendly tip err_messsage = "Get cpe url(url=%s, username=%s, password=%s) fail:connect to cpe fail." % ( url, username, password) try: # retry if ((e.errno == 10060) or (e.errno == 10065)): continue except Exception: pass # other error, fail ret = AUTHENTICATE_FAIL break
def test_script(obj): """ obj = MsgWorklistExecute default function name= test_script """ ret_worklist = ERR_FAIL # default ret_rpc = ERR_FAIL ret_datas = "" bool_reboot = False instance_number = 1 sn = obj.sn 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("first rpc") ret_rpc, ret_data = u1.set_parameter_values(ParameterList=[ dict( Name="InternetGatewayDevice.DeviceInfo.X_CU_Monitor.Enable", Value="1") ]) ret_datas = ret_datas + "\n" + str(ret_data) if ret_rpc == ERR_SUCCESS: log.app_info("success:%s" % ret_data) else: log.app_err("fail:%s" % ret_data) break # ---------------------------------------------------------- log.app_info("second rpc") alarm_root_path = "InternetGatewayDevice.DeviceInfo.X_CU_Monitor.MonitorConfig." ret_rpc, ret_data = u1.add_object(ObjectName=alarm_root_path) ret_datas = ret_datas + "\n" + str(ret_data) if ret_rpc == ERR_SUCCESS: log.app_info("success:%s" % ret_data) status = int(ret_data["Status"]) if status == 1: bool_reboot = True instance_number = int(ret_data["InstanceNumber"]) else: log.app_err("fail:%s" % ret_data) break # ---------------------------------------------------------- log.app_info("third rpc") alarm_node_path = "%s%s." % (alarm_root_path, instance_number) ret_rpc, ret_data = u1.set_parameter_values(ParameterList=[ dict(Name="%sParaList" % alarm_node_path, Value=obj.dict_data["parameterlist"]), dict(Name="%sTimeList" % alarm_node_path, Value=obj.dict_data["timelist"]) ]) ret_datas = ret_datas + "\n" + str(ret_data) if ret_rpc == ERR_SUCCESS: log.app_info("success:%s" % ret_data) status = int(ret_data["Status"]) if status == 1: bool_reboot = True else: log.app_err("fail:%s" % ret_data) break if bool_reboot: # ---------------------------------------------------------- log.app_info("need reboot") ret_rpc, ret_data = u1.reboot() ret_datas = ret_datas + "\n" + str(ret_data) if ret_rpc == ERR_SUCCESS: log.app_info("success:%s" % ret_data) else: log.app_err("fail:%s" % ret_data) break # need del obj.dict_ret["node_add_object"] = alarm_node_path ret_worklist = ERR_SUCCESS except Exception, e: ret_datas = ret_datas + "\n" + str(e) log.app_err(e) break
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 for nwf in [1]: try: # 新的双向的DIGEST认证账号的生成规则为:old+8为随机数 user_name = get_random_8str(_Config.CPE2ACS_LOGIN_NAME) password = get_random_8str(_Config.CPE2ACS_LOGIN_PASSWORD) connection_request_user_name = get_random_8str( _Config.ACS2CPE_LOGIN_NAME) connection_request_password = get_random_8str( _Config.ACS2CPE_LOGIN_PASSWORD) # 新的联通维护账号密码的生成规则为 “cuadmin” + 8位随机数 # cu_account_password = get_random_8str("cuadmin") # 组建所有要设置的节点参数 ParameterList = [ dict(Name="InternetGatewayDevice.ManagementServer.Username", Value=user_name), dict(Name="InternetGatewayDevice.ManagementServer.Password", Value=password), dict( Name= "InternetGatewayDevice.ManagementServer.ConnectionRequestUsername", Value=connection_request_user_name), dict( Name= "InternetGatewayDevice.ManagementServer.ConnectionRequestPassword", Value=connection_request_password) ] # dict(Name="InternetGatewayDevice.X_CU_Function.Web.AdminPassword", # Value=cu_account_password)] 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 set parameter value: %s " % ParameterList) ret_rpc, ret_data = u1.set_parameter_values( ParameterList=ParameterList) ret_datas = ret_datas + "\n" + str(ret_data) if ret_rpc == ERR_SUCCESS: info = "success:%s" % ret_data log.app_info(info) else: info = "fail:%s" % ret_data log.app_err(info) break # update 2 acs(修改密码后需要通知ACS) ret_rpc, ret_data = update_username_password_to_acs( sn, user_name, password, connection_request_user_name, connection_request_password) if ret_rpc != ERR_SUCCESS: info = "fail:%s" % ret_data log.app_err(info) break # ------------------------- log.app_info("Auto process get rpc methods") ret_rpc, ret_data = u1.get_rpc_methods() ret_datas = ret_datas + "\n" + str(ret_data) if ret_rpc == ERR_SUCCESS: info = "success:%s" % ret_data log.app_info(info) else: info = "fail:%s" % ret_data log.app_err(info) break ret_worklist = ERR_SUCCESS except Exception, e: info = str(e) log.app_err(info) ret_datas = ret_datas + "\n" + info break
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
def check_dir_file(self, obj): """ obj(MsgWorklistExecute) is dir[domain] + file[worklist name] exist? """ ret = ERR_FAIL ret_api = None script_root_dir = worklistcfg.SCRIPT_ROOT_DIR desc = "cpe(sn=%s, cpe device type=%s) begin search worklist(name=%s)" %( obj.sn, obj.domain, obj.worklist_name) log.app_info(desc) for nwf in [1]: try: dir_root = script_root_dir # tr069v3\lib\worklist\operator ret_api = os.path.isdir(dir_root) if (ret_api == False): desc = "%s is not dir in worklist server." %(dir_root) obj.dict_ret["str_result"] = desc log.app_err(desc) break operator = obj.operator # tr069v3\lib\worklist\operator\CT dir_operator = os.path.join(dir_root, operator) ret_api = os.path.isdir(dir_operator) if (ret_api == False): desc = "%s is not dir in worklist server." %(dir_operator) log.app_err(desc) desc = u"cpe operator=%s 不支持(支持的有 CT CU)." %operator obj.dict_ret["str_result"] = desc break # V3.0 or V4.0? cpe_interface_version = obj.cpe_interface_version dir_interface_version = os.path.join(dir_operator, cpe_interface_version) ret_api = os.path.isdir(dir_interface_version) if (ret_api == False): desc = "%s is not dir in worklist server." %(dir_interface_version) log.app_err(desc) desc = u"CPE operator=%s, interface version=%s 不支持." %( operator, cpe_interface_version) obj.dict_ret["str_result"] = desc break # tr069v3\lib\worklist\operator\CT\V3.0\business dir_business = os.path.join(dir_interface_version, worklistcfg.BUSINESS_DOMAINS) ret_api = os.path.isdir(dir_business) if (ret_api == False): desc = "%s is not dir in worklist server." %(dir_business) obj.dict_ret["str_result"] = desc log.app_err(desc) break domain = obj.domain # tr069v3\lib\worklist\operator\CT\V3.0\business\ADSL dir_domain = os.path.join(dir_business, domain) ret_api = os.path.isdir(dir_domain) if (ret_api == False): desc = "%s is not dir in worklist server." %(dir_domain) log.app_err(desc) desc = u"CPE device type=%s 不支持." %domain obj.dict_ret["str_result"] = desc break # nwf 2013-07-02; support _COMMON(Auto) desc = "" dir_system = os.path.join(dir_interface_version, worklistcfg.SYSTEM_DOMAINS) for dir_domain in [dir_domain, dir_system]: # nwf 2013-04-10 ; support to pyc(publish) worklist_name= obj.worklist_name # tr069v3\lib\worklist\operator\CT\V3.0\business\ADSL exec_script_dir = os.path.join(dir_domain, worklist_name) file1 = os.path.join(exec_script_dir, worklistcfg.SCRIPT_FILE_NAME+".py") ret_api = os.path.isfile(file1) if (ret_api == False): # retry file2 = os.path.join(exec_script_dir, worklistcfg.SCRIPT_FILE_NAME + ".pyc") ret_api = os.path.isfile(file2) if (ret_api == False): desc += "warning:(%s) or (%s) is not file in worklist server.\n" %(file1, file2) log.app_err(desc) desc = u"CPE worklist name=%s 不支持." %worklist_name obj.dict_ret["str_result"] = desc else: # success break else: # success break if (ret_api == False): break # save E:\____python\tr069\TR069_BS2_nwf\TR069\lib\worklists\operator\CT\v3.0\business\ADSL_2LAN\QoS_DSCP self.exec_script_dir =exec_script_dir # script.py exec_script_modulename = worklistcfg.SCRIPT_FILE_NAME # no .py self.exec_script_modulename = exec_script_modulename except Exception,e: print_trace(e) obj.dict_ret["str_result"] = str(e) break desc = "cpe(sn=%s, cpe device type=%s) search worklist(name=%s) success." %(obj.sn, obj.domain, obj.worklist_name) log.app_info(desc) ret = ERR_SUCCESS