def get_mlag_error_down_info(self): """ get error down info.""" mlag_error_down_info = dict() conf_str = CE_NC_GET_MLAG_ERROR_DOWN_INFO xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return mlag_error_down_info else: xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") mlag_error_down_info["mlagErrorDownInfos"] = list() root = ElementTree.fromstring(xml_str) mlag_error_infos = root.findall( "data/mlag/errordowns/errordown") if mlag_error_infos: for mlag_error_info in mlag_error_infos: mlag_error_dict = dict() for ele in mlag_error_info: if ele.tag in ["dfsgroupId", "portName"]: mlag_error_dict[ele.tag] = ele.text mlag_error_down_info[ "mlagErrorDownInfos"].append(mlag_error_dict) return mlag_error_down_info
def get_mlag_info(self): """ get mlag info.""" mlag_info = dict() conf_str = CE_NC_GET_MLAG_INFO xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return mlag_info else: xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") mlag_info["mlagInfos"] = list() root = ElementTree.fromstring(xml_str) dfs_mlag_infos = root.findall( "data/mlag/mlagInstances/mlagInstance") if dfs_mlag_infos: for dfs_mlag_info in dfs_mlag_infos: mlag_dict = dict() for ele in dfs_mlag_info: if ele.tag in [ "dfsgroupId", "mlagId", "localMlagPort" ]: mlag_dict[ele.tag] = ele.text mlag_info["mlagInfos"].append(mlag_dict) return mlag_info
def get_mlag_info(self): """ get mlag info.""" mlag_info = dict() conf_str = CE_NC_GET_MLAG_INFO xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return mlag_info else: xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") mlag_info["mlagInfos"] = list() root = ElementTree.fromstring(xml_str) dfs_mlag_infos = root.findall( "data/mlag/mlagInstances/mlagInstance") if dfs_mlag_infos: for dfs_mlag_info in dfs_mlag_infos: mlag_dict = dict() for ele in dfs_mlag_info: if ele.tag in ["dfsgroupId", "mlagId", "localMlagPort"]: mlag_dict[ele.tag] = ele.text mlag_info["mlagInfos"].append(mlag_dict) return mlag_info
def remote_file_exists(self, dst, file_system='flash:'): """Remote file whether exists""" full_path = file_system + dst file_name = os.path.basename(full_path) file_path = os.path.dirname(full_path) file_path = file_path + '/' xml_str = CE_NC_GET_FILE_INFO % (file_name, file_path) ret_xml = get_nc_config(self.module, xml_str) if "<data/>" in ret_xml: return False, 0 xml_str = ret_xml.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get file info root = ElementTree.fromstring(xml_str) topo = root.find("data/vfm/dirs/dir") if topo is None: return False, 0 for eles in topo: if eles.tag in ["DirSize"]: return True, int(eles.text.replace(',', '')) return False, 0
def get_vrf(self): """ check if vrf is need to change""" getxmlstr = CE_NC_GET_VRF xml_str = get_nc_config(self.module, getxmlstr) xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) vpn_instances = root.findall( "data/l3vpn/l3vpncomm/l3vpnInstances/l3vpnInstance") if vpn_instances: for vpn_instance in vpn_instances: if vpn_instance.find('vrfName').text == self.vrf: if vpn_instance.find('vrfDescription').text == self.description: if self.state == "present": return False else: return True else: return True return self.state == "present" else: return self.state == "present"
def get_dfs_group_info(self): """ get dfs group attributes info.""" dfs_group_info = dict() conf_str = CE_NC_GET_DFS_GROUP_INFO xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return dfs_group_info else: xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) dfs_info = root.findall("data/dfs/groupInstances/groupInstance") if dfs_info: for tmp in dfs_info: for site in tmp: if site.tag in [ "groupId", "priority", "ipAddress", "srcVpnName" ]: dfs_group_info[site.tag] = site.text dfs_nick_info = root.findall( "data/dfs/groupInstances/groupInstance/trillType") if dfs_nick_info: for tmp in dfs_nick_info: for site in tmp: if site.tag in [ "localNickname", "pseudoNickname", "pseudoPriority" ]: dfs_group_info[site.tag] = site.text return dfs_group_info
def get_bfd_dict(self): """bfd config dict""" bfd_dict = dict() bfd_dict["global"] = dict() bfd_dict["session"] = dict() conf_str = CE_NC_GET_BFD % (CE_NC_GET_BFD_GLB + (CE_NC_GET_BFD_SESSION % self.session_name)) xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return bfd_dict xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) # get bfd global info glb = root.find("data/bfd/bfdSchGlobal") if glb: for attr in glb: bfd_dict["global"][attr.tag] = attr.text # get bfd session info sess = root.find("data/bfd/bfdCfgSessions/bfdCfgSession") if sess: for attr in sess: bfd_dict["session"][attr.tag] = attr.text return bfd_dict
def get_bfd_dict(self): """bfd config dict""" bfd_dict = dict() bfd_dict["global"] = dict() bfd_dict["session"] = dict() conf_str = CE_NC_GET_BFD % ( CE_NC_GET_BFD_GLB + (CE_NC_GET_BFD_SESSION % self.session_name)) xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return bfd_dict xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) # get bfd global info glb = root.find("data/bfd/bfdSchGlobal") if glb: for attr in glb: bfd_dict["global"][attr.tag] = attr.text # get bfd session info sess = root.find("data/bfd/bfdCfgSessions/bfdCfgSession") if sess: for attr in sess: bfd_dict["session"][attr.tag] = attr.text return bfd_dict
def get_interface_dict(self, ifname): """ get one interface attributes dict.""" intf_info = dict() conf_str = CE_NC_GET_INTF % ifname recv_xml = get_nc_config(self.module, conf_str) if "<data/>" in recv_xml: return intf_info intf = re.findall( r'.*<ifName>(.*)</ifName>.*\s*' r'<ifPhyType>(.*)</ifPhyType>.*\s*' r'<ifNumber>(.*)</ifNumber>.*\s*' r'<ifDescr>(.*)</ifDescr>.*\s*' r'<isL2SwitchPort>(.*)</isL2SwitchPort>.*\s*' r'<ifAdminStatus>(.*)</ifAdminStatus>.*\s*' r'<ifMtu>(.*)</ifMtu>.*', recv_xml) if intf: intf_info = dict(ifName=intf[0][0], ifPhyType=intf[0][1], ifNumber=intf[0][2], ifDescr=intf[0][3], isL2SwitchPort=intf[0][4], ifAdminStatus=intf[0][5], ifMtu=intf[0][6]) return intf_info
def get_vrf(self): """ check if vrf is need to change""" getxmlstr = CE_NC_GET_VRF xml_str = get_nc_config(self.module, getxmlstr) xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) vpn_instances = root.findall( "data/l3vpn/l3vpncomm/l3vpnInstances/l3vpnInstance") if vpn_instances: for vpn_instance in vpn_instances: if vpn_instance.find('vrfName').text == self.vrf: if vpn_instance.find( 'vrfDescription').text == self.description: if self.state == "present": return False else: return True else: return True return self.state == "present" else: return self.state == "present"
def get_port_info(self, interface): """Get port information""" if_type = get_interface_type(interface) if if_type == 'meth': xml_str = CE_NC_GET_PORT_SPEED % interface.lower().replace('meth', 'MEth') else: xml_str = CE_NC_GET_PORT_SPEED % interface.upper() con_obj = get_nc_config(self.module, xml_str) if "<data/>" in con_obj: return xml_str = con_obj.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get link status information root = ElementTree.fromstring(xml_str) port_info = root.find("data/devm/ports/port") if port_info: for eles in port_info: if eles.tag == "ethernetPort": for ele in eles: if ele.tag == 'speed': self.result[interface]['Speed'] = ele.text
def get_vni2bd_dict(self): """ get vni2bd attributes dict.""" vni2bd_info = dict() # get vni bd info conf_str = CE_NC_GET_VNI_BD_INFO xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return vni2bd_info xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get vni to bridge domain id info root = ElementTree.fromstring(xml_str) vni2bd_info["vni2BdInfos"] = list() vni2bds = root.findall("data/nvo3/nvo3Vni2Bds/nvo3Vni2Bd") if vni2bds: for vni2bd in vni2bds: vni_dict = dict() for ele in vni2bd: if ele.tag in ["vniId", "bdId"]: vni_dict[ele.tag] = ele.text vni2bd_info["vni2BdInfos"].append(vni_dict) return vni2bd_info
def get_mlag_trunk_attribute_info(self): """ get mlag global info.""" mlag_trunk_attribute_info = dict() eth_trunk = "Eth-Trunk" eth_trunk += self.eth_trunk_id conf_str = CE_NC_GET_LACP_MLAG_INFO % eth_trunk xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return mlag_trunk_attribute_info else: xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) global_info = root.findall( "data/ifmtrunk/TrunkIfs/TrunkIf/lacpMlagIf") if global_info: for tmp in global_info: for site in tmp: if site.tag in ["lacpMlagSysId", "lacpMlagPriority"]: mlag_trunk_attribute_info[site.tag] = site.text return mlag_trunk_attribute_info
def get_ntp_all_auth_keyid(self): """Get all authentication keyid info""" ntp_auth_conf = list() xml_str = CE_NC_GET_ALL_NTP_AUTH_CONFIG con_obj = get_nc_config(self.module, xml_str) if "<data/>" in con_obj: self.ntp_auth_conf["authentication-keyid"] = "None" return ntp_auth_conf # get ntp authentication config ntp_auth = re.findall( r'.*<keyId>(.*)</keyId>.*\s*<mode>(.*)</mode>.*\s*' r'<keyVal>(.*)</keyVal>.*\s*<isReliable>(.*)</isReliable>.*', con_obj) for ntp_auth_num in ntp_auth: if ntp_auth_num[0] == self.key_id: self.key_id_exist = True if ntp_auth_num[3] == 'true': self.cur_trusted_key = 'enable' else: self.cur_trusted_key = 'disable' if ntp_auth_num[3] == 'true': trusted_key = 'enable' else: trusted_key = 'disable' ntp_auth_conf.append(dict(key_id=ntp_auth_num[0], auth_mode=ntp_auth_num[1].lower(), trusted_key=trusted_key)) self.ntp_auth_conf["authentication-keyid"] = ntp_auth_conf return ntp_auth_conf
def get_interface_dict(self, ifname): """ get one interface attributes dict.""" intf_info = dict() conf_str = CE_NC_GET_PORT_ATTR % ifname rcv_xml = get_nc_config(self.module, conf_str) if "<data/>" in rcv_xml: return intf_info intf = re.findall( r'.*<ifName>(.*)</ifName>.*\s*<l2Enable>(.*)</l2Enable>.*', rcv_xml) if intf: intf_info = dict(ifName=intf[0][0], l2Enable=intf[0][1], linkType="", pvid="", trunkVlans="") if intf_info["l2Enable"] == "enable": attr = re.findall( r'.*<linkType>(.*)</linkType>.*.*\s*<pvid>(.*)' r'</pvid>.*\s*<trunkVlans>(.*)</trunkVlans>.*', rcv_xml) if attr: intf_info["linkType"] = attr[0][0] intf_info["pvid"] = attr[0][1] intf_info["trunkVlans"] = attr[0][2] return intf_info
def get_interface_vpn(self): """ get the VPN instance associated with the interface""" xml_str = CE_NC_GET_VRF_INTERFACE con_obj = get_nc_config(self.module, xml_str) if "<data/>" in con_obj: return xml_str = con_obj.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get global vrf interface info root = ElementTree.fromstring(xml_str) vpns = root.findall( "data/l3vpn/l3vpncomm/l3vpnInstances/l3vpnInstance") if vpns: for vpnele in vpns: vpn_name = None for vpninfo in vpnele: if vpninfo.tag == 'vrfName': vpn_name = vpninfo.text if vpninfo.tag == 'l3vpnIfs': self.get_interface_vpn_name(vpninfo, vpn_name) return
def get_interfaces_dict(self): """ get interfaces attributes dict.""" intfs_info = dict() conf_str = CE_NC_GET_INTFS recv_xml = get_nc_config(self.module, conf_str) if "<data/>" in recv_xml: return intfs_info intf = re.findall( r'.*<ifName>(.*)</ifName>.*\s*<ifPhyType>(.*)</ifPhyType>.*\s*' r'<ifNumber>(.*)</ifNumber>.*\s*<ifDescr>(.*)</ifDescr>.*\s*' r'<isL2SwitchPort>(.*)</isL2SwitchPort>.*\s*<ifAdminStatus>' r'(.*)</ifAdminStatus>.*\s*<ifMtu>(.*)</ifMtu>.*', recv_xml) for tmp in intf: if tmp[1]: if not intfs_info.get(tmp[1].lower()): # new interface type list intfs_info[tmp[1].lower()] = list() intfs_info[tmp[1].lower()].append( dict(ifName=tmp[0], ifPhyType=tmp[1], ifNumber=tmp[2], ifDescr=tmp[3], isL2SwitchPort=tmp[4], ifAdminStatus=tmp[5], ifMtu=tmp[6])) return intfs_info
def get_dfs_group_info(self): """ get dfs group attributes info.""" dfs_group_info = dict() conf_str = CE_NC_GET_DFS_GROUP_INFO xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return dfs_group_info else: xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) dfs_info = root.findall( "data/dfs/groupInstances/groupInstance") if dfs_info: for tmp in dfs_info: for site in tmp: if site.tag in ["groupId", "priority", "ipAddress", "srcVpnName"]: dfs_group_info[site.tag] = site.text dfs_nick_info = root.findall( "data/dfs/groupInstances/groupInstance/trillType") if dfs_nick_info: for tmp in dfs_nick_info: for site in tmp: if site.tag in ["localNickname", "pseudoNickname", "pseudoPriority"]: dfs_group_info[site.tag] = site.text return dfs_group_info
def get_interfaces_dict(self): """ get interfaces attributes dict.""" intfs_info = dict() conf_str = CE_NC_GET_INTFS recv_xml = get_nc_config(self.module, conf_str) if "<data/>" in recv_xml: return intfs_info intf = re.findall( r'.*<ifName>(.*)</ifName>.*\s*<ifPhyType>(.*)</ifPhyType>.*\s*' r'<ifNumber>(.*)</ifNumber>.*\s*<ifDescr>(.*)</ifDescr>.*\s*' r'<isL2SwitchPort>(.*)</isL2SwitchPort>.*\s*<ifAdminStatus>' r'(.*)</ifAdminStatus>.*\s*<ifMtu>(.*)</ifMtu>.*', recv_xml) for tmp in intf: if tmp[1]: if not intfs_info.get(tmp[1].lower()): # new interface type list intfs_info[tmp[1].lower()] = list() intfs_info[tmp[1].lower()].append(dict(ifName=tmp[0], ifPhyType=tmp[1], ifNumber=tmp[2], ifDescr=tmp[3], isL2SwitchPort=tmp[4], ifAdminStatus=tmp[5], ifMtu=tmp[6])) return intfs_info
def get_mlag_error_down_info(self): """ get error down info.""" mlag_error_down_info = dict() conf_str = CE_NC_GET_MLAG_ERROR_DOWN_INFO xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return mlag_error_down_info else: xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") mlag_error_down_info["mlagErrorDownInfos"] = list() root = ElementTree.fromstring(xml_str) mlag_error_infos = root.findall("data/mlag/errordowns/errordown") if mlag_error_infos: for mlag_error_info in mlag_error_infos: mlag_error_dict = dict() for ele in mlag_error_info: if ele.tag in ["dfsgroupId", "portName"]: mlag_error_dict[ele.tag] = ele.text mlag_error_down_info["mlagErrorDownInfos"].append( mlag_error_dict) return mlag_error_down_info
def get_interface_info(self): """Get interface information""" xml_str = CE_NC_GET_INT_STATISTICS % self.interface.upper() con_obj = get_nc_config(self.module, xml_str) if "<data/>" in con_obj: self.module.fail_json( msg='Error: %s interface does not exist.' % self.interface.upper()) return xml_str = con_obj.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get link status information root = ElementTree.fromstring(xml_str) intf_info = root.find("data/ifm/interfaces/interface") if intf_info: for eles in intf_info: if eles.tag in ["ifDynamicInfo", "ifStatistics", "ifClearedStat"]: if eles.tag == "ifDynamicInfo": self.get_intf_dynamic_info(eles, self.interface) elif eles.tag == "ifStatistics": self.get_intf_statistics_info(eles, self.interface) elif eles.tag == "ifClearedStat": self.get_intf_cleared_stat(eles, self.interface)
def get_dldp_exist_config(self): """Get current dldp existed configuration""" dldp_conf = dict() xml_str = CE_NC_GET_GLOBAL_DLDP_CONFIG con_obj = get_nc_config(self.module, xml_str) if "<data/>" in con_obj: return dldp_conf xml_str = con_obj.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get global DLDP info root = ElementTree.fromstring(xml_str) topo = root.find("data/dldp/dldpSys") if not topo: self.module.fail_json( msg="Error: Get current DLDP configration failed.") for eles in topo: if eles.tag in ["dldpEnable", "dldpInterval", "dldpWorkMode", "dldpAuthMode"]: if eles.tag == 'dldpEnable': if eles.text == 'true': value = 'enable' else: value = 'disable' else: value = eles.text dldp_conf[eles.tag] = value return dldp_conf
def get_dldp_exist_config(self): """Get current dldp existed configuration""" dldp_conf = dict() xml_str = CE_NC_GET_GLOBAL_DLDP_CONFIG con_obj = get_nc_config(self.module, xml_str) if "<data/>" in con_obj: return dldp_conf xml_str = con_obj.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get global DLDP info root = ElementTree.fromstring(xml_str) topo = root.find("data/dldp/dldpSys") if not topo: self.module.fail_json( msg="Error: Get current DLDP configration failed.") for eles in topo: if eles.tag in [ "dldpEnable", "dldpInterval", "dldpWorkMode", "dldpAuthMode" ]: if eles.tag == 'dldpEnable': if eles.text == 'true': value = 'enable' else: value = 'disable' else: value = eles.text dldp_conf[eles.tag] = value return dldp_conf
def get_ntp_exist_config(self): """Get ntp existed configure""" ntp_config = list() conf_str = CE_NC_GET_NTP_CONFIG con_obj = get_nc_config(self.module, conf_str) if "<data/>" in con_obj: return ntp_config xml_str = con_obj.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get all ntp config info root = ElementTree.fromstring(xml_str) ntpsite = root.findall("data/ntp/ntpUCastCfgs/ntpUCastCfg") for nexthop in ntpsite: ntp_dict = dict() for ele in nexthop: if ele.tag in ["addrFamily", "vpnName", "ifName", "ipv4Addr", "ipv6Addr", "type", "isPreferred", "keyId"]: ntp_dict[ele.tag] = ele.text ip_addr = ntp_dict['ipv6Addr'] if ntp_dict['addrFamily'] == "IPv4": ip_addr = ntp_dict['ipv4Addr'] if ntp_dict['ifName'] is None: ntp_dict['ifName'] = "" if ntp_dict['isPreferred'] == 'true': is_preferred = 'enable' else: is_preferred = 'disable' if self.state == "present": key_id = ntp_dict['keyId'] or "" cur_ntp_cfg = dict(vpn_name=ntp_dict['vpnName'], source_int=ntp_dict['ifName'].lower(), address=ip_addr, peer_type=ntp_dict['type'], prefer=is_preferred, key_id=key_id) exp_ntp_cfg = dict(vpn_name=self.vpn_name, source_int=self.interface.lower(), address=self.address, peer_type=self.peer_type, prefer=self.is_preferred, key_id=self.key_id) if cur_ntp_cfg == exp_ntp_cfg: self.conf_exsit = True vpn_name = ntp_dict['vpnName'] if ntp_dict['vpnName'] == "_public_": vpn_name = None if_name = ntp_dict['ifName'] if if_name == "": if_name = None if self.peer_type == 'Server': ntp_config.append(dict(vpn_name=vpn_name, source_int=if_name, server=ip_addr, is_preferred=is_preferred, key_id=ntp_dict['keyId'])) else: ntp_config.append(dict(vpn_name=vpn_name, source_int=if_name, peer=ip_addr, is_preferred=is_preferred, key_id=ntp_dict['keyId'])) return ntp_config
def is_vrf_exist(self): """ judge whether the VPN instance is existed""" conf_str = CE_NC_GET_VRF % self.vrf con_obj = get_nc_config(self.module, conf_str) if "<data/>" in con_obj: return False return True
def netconf_get_config(self, **kwargs): """ Get configure through netconf """ module = kwargs["module"] conf_str = kwargs["conf_str"] xml_str = get_nc_config(module, conf_str) return xml_str
def check_vni_bd(self): """Check whether vxlan vni is configured in BD view""" xml_str = CE_NC_GET_VNI_BD % self.bridge_domain_id xml_str = get_nc_config(self.module, xml_str) if "<data/>" in xml_str: self.module.fail_json( msg= 'Error: The vxlan vni is not configured or the bridge domain id is invalid.' )
def get_vlans_list(self): """ get all vlan vid list, sample: [ "20", "30", "31" ]""" conf_str = CE_NC_GET_VLANS xml_str = get_nc_config(self.module, conf_str) vlan_list = list() if "<data/>" in xml_str: return vlan_list else: vlan_list = re.findall(r'.*<vlanId>(.*)</vlanId>.*', xml_str) return vlan_list
def get_vlans_list(self): """ get all vlan vid list, sample: [ "20", "30", "31" ]""" conf_str = CE_NC_GET_VLANS xml_str = get_nc_config(self.module, conf_str) vlan_list = list() if "<data/>" in xml_str: return vlan_list else: vlan_list = re.findall( r'.*<vlanId>(.*)</vlanId>.*', xml_str) return vlan_list
def get_vrf(self): """ check if vrf is need to change""" getxmlstr = CE_NC_GET_VRF xmlstr_new_1 = (self.vrf.lower()) xml_str = get_nc_config(self.module, getxmlstr) re_find_1 = re.findall(r'.*<vrfname>(.*)</vrfname>.*', xml_str.lower()) if re_find_1 is None: return False return xmlstr_new_1 in re_find_1
def get_ospf_dict(self): """ get one ospf attributes dict.""" ospf_info = dict() conf_str = CE_NC_GET_OSPF % (self.process_id, self.get_area_ip(), self.interface) rcv_xml = get_nc_config(self.module, conf_str) if "<data/>" in rcv_xml: return ospf_info xml_str = rcv_xml.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get process base info root = ElementTree.fromstring(xml_str) ospfsite = root.find("data/ospfv2/ospfv2comm/ospfSites/ospfSite") if not ospfsite: self.module.fail_json(msg="Error: ospf process does not exist.") for site in ospfsite: if site.tag in ["processId", "routerId", "vrfName"]: ospf_info[site.tag] = site.text # get areas info ospf_info["areaId"] = "" areas = root.find( "data/ospfv2/ospfv2comm/ospfSites/ospfSite/areas/area") if areas: for area in areas: if area.tag == "areaId": ospf_info["areaId"] = area.text break # get interface info ospf_info["interface"] = dict() intf = root.find( "data/ospfv2/ospfv2comm/ospfSites/ospfSite/areas/area/interfaces/interface" ) if intf: for attr in intf: if attr.tag in [ "ifName", "networkType", "helloInterval", "deadInterval", "silentEnable", "configCost", "authenticationMode", "authTextSimple", "keyId", "authTextMd5" ]: ospf_info["interface"][attr.tag] = attr.text return ospf_info
def check_global_args(self): """ Check global args """ need_cfg = False find_flag = False self.cur_global_cfg["global_cfg"] = [] if self.debug_time_stamp: conf_str = CE_GET_DEBUG_GLOBAL_HEADER conf_str += "<debugTimeStamp></debugTimeStamp>" conf_str += CE_GET_DEBUG_GLOBAL_TAIL xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: find_flag = False else: xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) global_cfg = root.findall("data/syslog/globalParam") if global_cfg: for tmp in global_cfg: tmp_dict = dict() for site in tmp: if site.tag in ["debugTimeStamp"]: tmp_dict[site.tag] = site.text self.cur_global_cfg["global_cfg"].append(tmp_dict) if self.cur_global_cfg["global_cfg"]: for tmp in self.cur_global_cfg["global_cfg"]: find_flag = True if tmp.get("debugTimeStamp").lower( ) != self.debug_time_stamp: find_flag = False if find_flag: break else: find_flag = False if self.state == "present": need_cfg = bool(not find_flag) else: need_cfg = bool(find_flag) self.cur_global_cfg["need_cfg"] = need_cfg
def get_vlans_name(self): """ get all vlan vid and its name list, sample: [ ("20", "VLAN_NAME_20"), ("30", "VLAN_NAME_30") ]""" conf_str = CE_NC_GET_VLANS xml_str = get_nc_config(self.module, conf_str) vlan_list = list() if "<data/>" in xml_str: return vlan_list else: vlan_list = re.findall( r'.*<vlanId>(.*)</vlanId>.*\s*<vlanName>(.*)</vlanName>.*', xml_str) return vlan_list
def check_global_args(self): """ Check global args """ need_cfg = False find_flag = False self.cur_global_cfg["global_cfg"] = [] if self.debug_time_stamp: conf_str = CE_GET_DEBUG_GLOBAL_HEADER conf_str += "<debugTimeStamp></debugTimeStamp>" conf_str += CE_GET_DEBUG_GLOBAL_TAIL xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: find_flag = False else: xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) global_cfg = root.findall("data/syslog/globalParam") if global_cfg: for tmp in global_cfg: tmp_dict = dict() for site in tmp: if site.tag in ["debugTimeStamp"]: tmp_dict[site.tag] = site.text self.cur_global_cfg["global_cfg"].append(tmp_dict) if self.cur_global_cfg["global_cfg"]: for tmp in self.cur_global_cfg["global_cfg"]: find_flag = True if tmp.get("debugTimeStamp").lower() != self.debug_time_stamp: find_flag = False if find_flag: break else: find_flag = False if self.state == "present": need_cfg = bool(not find_flag) else: need_cfg = bool(find_flag) self.cur_global_cfg["need_cfg"] = need_cfg
def get_vrf(self): """ check if vrf is need to change""" getxmlstr = CE_NC_GET_VRF xmlstr_new_1 = (self.vrf.lower()) xml_str = get_nc_config(self.module, getxmlstr) re_find_1 = re.findall( r'.*<vrfname>(.*)</vrfname>.*', xml_str.lower()) if re_find_1 is None: return False return xmlstr_new_1 in re_find_1
def get_interface_dict(self, ifname): """ get one interface attributes dict.""" intf_info = dict() conf_str = CE_NC_GET_INTF % ifname rcv_xml = get_nc_config(self.module, conf_str) if "<data/>" in rcv_xml: return intf_info # get interface base info intf = re.findall( r'.*<ifName>(.*)</ifName>.*\s*' r'<isL2SwitchPort>(.*)</isL2SwitchPort>.*', rcv_xml) if intf: intf_info = dict(ifName=intf[0][0], isL2SwitchPort=intf[0][1]) # get interface ipv4 address info ipv4_info = re.findall( r'.*<ifIpAddr>(.*)</ifIpAddr>.*\s*<subnetMask>(.*)' r'</subnetMask>.*\s*<addrType>(.*)</addrType>.*', rcv_xml) intf_info["am4CfgAddr"] = list() for info in ipv4_info: intf_info["am4CfgAddr"].append( dict(ifIpAddr=info[0], subnetMask=info[1], addrType=info[2])) # get interface ipv6 address info ipv6_info = re.findall( r'.*<ifmAm6>.*\s*<enableFlag>(.*)</enableFlag>.*', rcv_xml) if not ipv6_info: self.module.fail_json( msg='Error: Fail to get interface %s IPv6 state.' % self.interface) else: intf_info["enableFlag"] = ipv6_info[0] # get interface ipv6 enable info ipv6_info = re.findall( r'.*<ifIp6Addr>(.*)</ifIp6Addr>.*\s*<addrPrefixLen>(.*)' r'</addrPrefixLen>.*\s*<addrType6>(.*)</addrType6>.*', rcv_xml) intf_info["am6CfgAddr"] = list() for info in ipv6_info: intf_info["am6CfgAddr"].append( dict(ifIp6Addr=info[0], addrPrefixLen=info[1], addrType6=info[2])) return intf_info
def get_ospf_dict(self): """ get one ospf attributes dict.""" ospf_info = dict() conf_str = CE_NC_GET_OSPF % ( self.process_id, self.get_area_ip(), self.interface) rcv_xml = get_nc_config(self.module, conf_str) if "<data/>" in rcv_xml: return ospf_info xml_str = rcv_xml.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get process base info root = ElementTree.fromstring(xml_str) ospfsite = root.find("data/ospfv2/ospfv2comm/ospfSites/ospfSite") if not ospfsite: self.module.fail_json(msg="Error: ospf process does not exist.") for site in ospfsite: if site.tag in ["processId", "routerId", "vrfName"]: ospf_info[site.tag] = site.text # get areas info ospf_info["areaId"] = "" areas = root.find( "data/ospfv2/ospfv2comm/ospfSites/ospfSite/areas/area") if areas: for area in areas: if area.tag == "areaId": ospf_info["areaId"] = area.text break # get interface info ospf_info["interface"] = dict() intf = root.find( "data/ospfv2/ospfv2comm/ospfSites/ospfSite/areas/area/interfaces/interface") if intf: for attr in intf: if attr.tag in ["ifName", "networkType", "helloInterval", "deadInterval", "silentEnable", "configCost", "authenticationMode", "authTextSimple", "keyId", "authTextMd5"]: ospf_info["interface"][attr.tag] = attr.text return ospf_info
def get_ntp_auth_enable(self): """Get ntp authentication enable state""" xml_str = CE_NC_GET_NTP_AUTH_ENABLE con_obj = get_nc_config(self.module, xml_str) if "<data/>" in con_obj: return # get ntp authentication enable auth_en = re.findall(r'.*<isAuthEnable>(.*)</isAuthEnable>.*', con_obj) if auth_en: if auth_en[0] == 'true': self.ntp_auth_conf['authentication'] = 'enable' else: self.ntp_auth_conf['authentication'] = 'disable'
def get_all_interface_info(self, intf_type=None): """Get interface information all or by interface type""" xml_str = CE_NC_GET_INT_STATISTICS % '' con_obj = get_nc_config(self.module, xml_str) if "<data/>" in con_obj: return xml_str = con_obj.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get link status information root = ElementTree.fromstring(xml_str) intfs_info = root.find("data/ifm/interfaces") if not intfs_info: return intf_name = '' flag = False for eles in intfs_info: if eles.tag == "interface": for ele in eles: if ele.tag in [ "ifName", "ifDynamicInfo", "ifStatistics", "ifClearedStat" ]: if ele.tag == "ifName": intf_name = ele.text.lower() if intf_type: if get_interface_type( intf_name) != intf_type.lower(): break else: flag = True self.init_interface_data(intf_name) if is_ethernet_port(intf_name): self.get_port_info(intf_name) if ele.tag == "ifDynamicInfo": self.get_intf_dynamic_info(ele, intf_name) elif ele.tag == "ifStatistics": self.get_intf_statistics_info(ele, intf_name) elif ele.tag == "ifClearedStat": self.get_intf_cleared_stat(ele, intf_name) if intf_type and not flag: self.module.fail_json( msg='Error: %s interface type does not exist.' % intf_type.upper())
def get_vrf_af(self): """ check if vrf is need to change""" self.vrf_af_info["vpnInstAF"] = list() if self.evpn is True: getxmlstr = CE_NC_GET_VRF_AF % (self.vrf, CE_NC_GET_EXTEND_VRF_TARGET) else: getxmlstr = CE_NC_GET_VRF_AF % (self.vrf, CE_NC_GET_VRF_TARGET) xml_str = get_nc_config(self.module, getxmlstr) if 'data/' in xml_str: return self.state == 'present' xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) # get the vpn address family and RD text vrf_addr_types = root.findall( "data/l3vpn/l3vpncomm/l3vpnInstances/l3vpnInstance/vpnInstAFs/vpnInstAF" ) if vrf_addr_types: for vrf_addr_type in vrf_addr_types: vrf_af_info = dict() for vrf_addr_type_ele in vrf_addr_type: if vrf_addr_type_ele.tag in ["vrfName", "afType", "vrfRD"]: vrf_af_info[ vrf_addr_type_ele.tag] = vrf_addr_type_ele.text if vrf_addr_type_ele.tag == 'vpnTargets': vrf_af_info["vpnTargets"] = list() for rtargets in vrf_addr_type_ele: rt_dict = dict() for rtarget in rtargets: if rtarget.tag in ["vrfRTValue", "vrfRTType"]: rt_dict[rtarget.tag] = rtarget.text vrf_af_info["vpnTargets"].append(rt_dict) if vrf_addr_type_ele.tag == 'exVpnTargets': vrf_af_info["evpnTargets"] = list() for rtargets in vrf_addr_type_ele: rt_dict = dict() for rtarget in rtargets: if rtarget.tag in ["vrfRTValue", "vrfRTType"]: rt_dict[rtarget.tag] = rtarget.text vrf_af_info["evpnTargets"].append(rt_dict) self.vrf_af_info["vpnInstAF"].append(vrf_af_info)
def get_ntp_auth_enable(self): """Get ntp authentication enable state""" xml_str = CE_NC_GET_NTP_AUTH_ENABLE con_obj = get_nc_config(self.module, xml_str) if "<data/>" in con_obj: return # get ntp authentication enable auth_en = re.findall( r'.*<isAuthEnable>(.*)</isAuthEnable>.*', con_obj) if auth_en: if auth_en[0] == 'true': self.ntp_auth_conf['authentication'] = 'enable' else: self.ntp_auth_conf['authentication'] = 'disable'
def get_nve_dict(self, nve_name): """ get nve interface attributes dict.""" nve_info = dict() # get nve info conf_str = CE_NC_GET_NVE_INFO % nve_name xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return nve_info xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get nve info root = ElementTree.fromstring(xml_str) nvo3 = root.find("data/nvo3/nvo3Nves/nvo3Nve") if nvo3: for nve in nvo3: if nve.tag in ["srcAddr", "ifName", "nveType"]: nve_info[nve.tag] = nve.text # get nve vni info nve_info["vni_peer_protocols"] = list() vni_members = root.findall( "data/nvo3/nvo3Nves/nvo3Nve/vniMembers/vniMember") if vni_members: for member in vni_members: vni_dict = dict() for ele in member: if ele.tag in ["vniId", "protocol"]: vni_dict[ele.tag] = ele.text nve_info["vni_peer_protocols"].append(vni_dict) # get vni peer address ip info nve_info["vni_peer_ips"] = list() vni_peers = root.findall( "data/nvo3/nvo3Nves/nvo3Nve/vniMembers/vniMember/nvo3VniPeers/nvo3VniPeer") if vni_peers: for peer_address in vni_peers: vni_peer_dict = dict() for ele in peer_address: if ele.tag in ["vniId", "peerAddr"]: vni_peer_dict[ele.tag] = ele.text nve_info["vni_peer_ips"].append(vni_peer_dict) return nve_info
def get_interface_dict(self, ifname): """ get one interface attributes dict.""" intf_info = dict() conf_str = CE_NC_GET_INTF % ifname rcv_xml = get_nc_config(self.module, conf_str) if "<data/>" in rcv_xml: return intf_info # get interface base info intf = re.findall( r'.*<ifName>(.*)</ifName>.*\s*' r'<isL2SwitchPort>(.*)</isL2SwitchPort>.*', rcv_xml) if intf: intf_info = dict(ifName=intf[0][0], isL2SwitchPort=intf[0][1]) # get interface ipv4 address info ipv4_info = re.findall( r'.*<ifIpAddr>(.*)</ifIpAddr>.*\s*<subnetMask>(.*)' r'</subnetMask>.*\s*<addrType>(.*)</addrType>.*', rcv_xml) intf_info["am4CfgAddr"] = list() for info in ipv4_info: intf_info["am4CfgAddr"].append( dict(ifIpAddr=info[0], subnetMask=info[1], addrType=info[2])) # get interface ipv6 address info ipv6_info = re.findall( r'.*<ifmAm6>.*\s*<enableFlag>(.*)</enableFlag>.*', rcv_xml) if not ipv6_info: self.module.fail_json(msg='Error: Fail to get interface %s IPv6 state.' % self.interface) else: intf_info["enableFlag"] = ipv6_info[0] # get interface ipv6 enable info ipv6_info = re.findall( r'.*<ifIp6Addr>(.*)</ifIp6Addr>.*\s*<addrPrefixLen>(.*)' r'</addrPrefixLen>.*\s*<addrType6>(.*)</addrType6>.*', rcv_xml) intf_info["am6CfgAddr"] = list() for info in ipv6_info: intf_info["am6CfgAddr"].append( dict(ifIp6Addr=info[0], addrPrefixLen=info[1], addrType6=info[2])) return intf_info
def get_vrf_af(self): """ check if vrf is need to change""" self.vrf_af_info["vpnInstAF"] = list() if self.evpn is True: getxmlstr = CE_NC_GET_VRF_AF % ( self.vrf, CE_NC_GET_EXTEND_VRF_TARGET) else: getxmlstr = CE_NC_GET_VRF_AF % (self.vrf, CE_NC_GET_VRF_TARGET) xml_str = get_nc_config(self.module, getxmlstr) if 'data/' in xml_str: return self.state == 'present' xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") root = ElementTree.fromstring(xml_str) # get the vpn address family and RD text vrf_addr_types = root.findall( "data/l3vpn/l3vpncomm/l3vpnInstances/l3vpnInstance/vpnInstAFs/vpnInstAF") if vrf_addr_types: for vrf_addr_type in vrf_addr_types: vrf_af_info = dict() for vrf_addr_type_ele in vrf_addr_type: if vrf_addr_type_ele.tag in ["vrfName", "afType", "vrfRD"]: vrf_af_info[vrf_addr_type_ele.tag] = vrf_addr_type_ele.text if vrf_addr_type_ele.tag == 'vpnTargets': vrf_af_info["vpnTargets"] = list() for rtargets in vrf_addr_type_ele: rt_dict = dict() for rtarget in rtargets: if rtarget.tag in ["vrfRTValue", "vrfRTType"]: rt_dict[rtarget.tag] = rtarget.text vrf_af_info["vpnTargets"].append(rt_dict) if vrf_addr_type_ele.tag == 'exVpnTargets': vrf_af_info["evpnTargets"] = list() for rtargets in vrf_addr_type_ele: rt_dict = dict() for rtarget in rtargets: if rtarget.tag in ["vrfRTValue", "vrfRTType"]: rt_dict[rtarget.tag] = rtarget.text vrf_af_info["evpnTargets"].append(rt_dict) self.vrf_af_info["vpnInstAF"].append(vrf_af_info)
def get_rollback_dict(self): """ get rollback attributes dict.""" rollback_info = dict() conf_str = CE_NC_GET_CHECKPOINT xml_str = get_nc_config(self.module, conf_str) rollback_info["RollBackInfos"] = list() if "<data/>" in xml_str: return rollback_info else: re_find = re.findall(r'.*<commitId>(.*)</commitId>.*\s*' r'<userName>(.*)</userName>.*\s*' r'<userLabel>(.*)</userLabel>.*', xml_str) for mem in re_find: rollback_info["RollBackInfos"].append( dict(commitId=mem[0], userLabel=mem[2])) return rollback_info
def get_vlan_attr(self, vlan_id): """ get vlan attributes.""" conf_str = CE_NC_GET_VLAN % vlan_id xml_str = get_nc_config(self.module, conf_str) attr = dict() if "<data/>" in xml_str: return attr else: re_find = re.findall(r'.*<vlanId>(.*)</vlanId>.*\s*' r'<vlanName>(.*)</vlanName>.*\s*' r'<vlanDesc>(.*)</vlanDesc>.*', xml_str) if re_find: attr = dict(vlan_id=re_find[0][0], name=re_find[0][1], description=re_find[0][2]) return attr
def get_l2_sub_intf_dict(self, ifname): """get l2 sub-interface info""" intf_info = dict() if not ifname: return intf_info conf_str = CE_NC_GET_ENCAP % ifname xml_str = get_nc_config(self.module, conf_str) if "<data/>" in xml_str: return intf_info xml_str = xml_str.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get l2 sub interface encapsulation info root = ElementTree.fromstring(xml_str) bds = root.find("data/ethernet/servicePoints/servicePoint") if not bds: return intf_info for ele in bds: if ele.tag in ["ifName", "flowType"]: intf_info[ele.tag] = ele.text.lower() if intf_info.get("flowType") == "dot1q": ce_vid = root.find( "data/ethernet/servicePoints/servicePoint/flowDot1qs") intf_info["dot1qVids"] = "" if ce_vid: for ele in ce_vid: if ele.tag == "dot1qVids": intf_info["dot1qVids"] = ele.text elif intf_info.get("flowType") == "qinq": vids = root.find( "data/ethernet/servicePoints/servicePoint/flowQinqs/flowQinq") if vids: for ele in vids: if ele.tag in ["peVlanId", "ceVids"]: intf_info[ele.tag] = ele.text return intf_info
def get_all_interface_info(self, intf_type=None): """Get interface information all or by interface type""" xml_str = CE_NC_GET_INT_STATISTICS % '' con_obj = get_nc_config(self.module, xml_str) if "<data/>" in con_obj: return xml_str = con_obj.replace('\r', '').replace('\n', '').\ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\ replace('xmlns="http://www.huawei.com/netconf/vrp"', "") # get link status information root = ElementTree.fromstring(xml_str) intfs_info = root.find("data/ifm/interfaces") if not intfs_info: return intf_name = '' flag = False for eles in intfs_info: if eles.tag == "interface": for ele in eles: if ele.tag in ["ifName", "ifDynamicInfo", "ifStatistics", "ifClearedStat"]: if ele.tag == "ifName": intf_name = ele.text.lower() if intf_type: if get_interface_type(intf_name) != intf_type.lower(): break else: flag = True self.init_interface_data(intf_name) if is_ethernet_port(intf_name): self.get_port_info(intf_name) if ele.tag == "ifDynamicInfo": self.get_intf_dynamic_info(ele, intf_name) elif ele.tag == "ifStatistics": self.get_intf_statistics_info(ele, intf_name) elif ele.tag == "ifClearedStat": self.get_intf_cleared_stat(ele, intf_name) if intf_type and not flag: self.module.fail_json( msg='Error: %s interface type does not exist.' % intf_type.upper())
def get_trunk_dict(self, trunk_id): """ get one interface attributes dict.""" trunk_info = dict() conf_str = CE_NC_GET_TRUNK % trunk_id recv_xml = get_nc_config(self.module, conf_str) if "<data/>" in recv_xml: return trunk_info # get trunk base info base = re.findall( r'.*<ifName>(.*)</ifName>.*\s*' r'<minUpNum>(.*)</minUpNum>.*\s*' r'<maxUpNum>(.*)</maxUpNum>.*\s*' r'<trunkType>(.*)</trunkType>.*\s*' r'<hashType>(.*)</hashType>.*\s*' r'<workMode>(.*)</workMode>.*\s*' r'<upMemberIfNum>(.*)</upMemberIfNum>.*\s*' r'<memberIfNum>(.*)</memberIfNum>.*', recv_xml) if base: trunk_info = dict(ifName=base[0][0], trunkId=base[0][0].lower().replace("eth-trunk", "").replace(" ", ""), minUpNum=base[0][1], maxUpNum=base[0][2], trunkType=base[0][3], hashType=base[0][4], workMode=base[0][5], upMemberIfNum=base[0][6], memberIfNum=base[0][7]) # get trunk member interface info member = re.findall( r'.*<memberIfName>(.*)</memberIfName>.*\s*' r'<memberIfState>(.*)</memberIfState>.*', recv_xml) trunk_info["TrunkMemberIfs"] = list() for mem in member: trunk_info["TrunkMemberIfs"].append( dict(memberIfName=mem[0], memberIfState=mem[1])) return trunk_info