def _cumulus_vrf_api_converter(hostname: str(), cmd_output, options={}) -> ListVRF: template = open(f"{TEXTFSM_PATH}cumulus_net_show_vrf.textfsm") results_template = textfsm.TextFSM(template) parsed_results = results_template.ParseText(cmd_output.decode()) list_vrf = ListVRF(list()) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL3): printline() print(parsed_results) for line in parsed_results: vrf = VRF(vrf_name=line[0], vrf_id=line[1], vrf_type=NOT_SET, l3_vni=NOT_SET, rd=NOT_SET, rt_imp=NOT_SET, rt_exp=NOT_SET, imp_targ=NOT_SET, exp_targ=NOT_SET, options=options) list_vrf.vrf_lst.append(vrf) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(list_vrf.to_json()) return list_vrf
def _nxos_vrf_ssh_converter( hostname: str(), cmd_output, options={} ) -> ListVRF: vrf_list = ListVRF(list()) for vrf in cmd_output.get('TABLE_vrf', NOT_SET).get('ROW_vrf'): vrf_list.vrf_lst.append( VRF( vrf_name=vrf.get('vrf_name', NOT_SET), vrf_id=vrf.get('vrf_id', NOT_SET), vrf_type=NOT_SET, l3_vni=NOT_SET, rd=vrf.get('rd') if vrf.get('rd') != '0:0' else NOT_SET, rt_imp=NOT_SET, rt_exp=NOT_SET, imp_targ=NOT_SET, exp_targ=NOT_SET, options=options ) ) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1 ): printline() print(f">>>>> {hostname}") PP.pprint(vrf_list.to_json()) return vrf_list
def _juniper_vrf_api_converter(hostname: str, cmd_output: list, options={}) -> ListVRF: if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL5): printline() print(type(cmd_output)) print(cmd_output) cmd_output = format_xml_output(cmd_output) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL4): printline() print(type(cmd_output)) PP.pprint(cmd_output) vrf_list = ListVRF(vrf_lst=list()) for vrf in cmd_output.get('instance-information') \ .get('instance-core'): if _juniper_vrf_filter(vrf.get('instance-name')): rd = NOT_SET, rt_imp = NOT_SET rt_exp = NOT_SET imp_targ = NOT_SET exp_targ = NOT_SET if "instance-vrf" in vrf.keys(): rd = vrf.get('instance-vrf') \ .get('route-distinguisher', NOT_SET) rt_imp = vrf.get('instance-vrf') \ .get('vrf-import', NOT_SET) rt_exp = vrf.get('instance-vrf') \ .get('vrf-export', NOT_SET) imp_targ = vrf.get('instance-vrf') \ .get('vrf-import-target', NOT_SET) exp_targ = vrf.get('instance-vrf') \ .get('vrf-export-target', NOT_SET) vrf_list.vrf_lst.append( VRF(vrf_name=_juniper_vrf_default_mapping( vrf.get('instance-name')), vrf_id=vrf.get('router-id', NOT_SET), vrf_type=vrf.get('instance-type', NOT_SET), l3_vni=NOT_SET, rd=rd, rt_imp=rt_imp, rt_exp=rt_exp, imp_targ=imp_targ, exp_targ=exp_targ, options=options)) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() print(f">>>>> {hostname}") PP.pprint(vrf_list.to_json()) return vrf_list
def _juniper_vrf_netconf_converter(hostname: str(), cmd_output, options={}) -> ListVRF: if isinstance(cmd_output, lxml.etree._Element): cmd_output = json.dumps( xmltodict.parse(ElementTree.tostring(cmd_output))) elif isinstance(cmd_output, str): cmd_output = json.dumps(xmltodict.parse(cmd_output)) cmd_output = json.loads(cmd_output) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL4): printline() PP.pprint(cmd_output) vrf_list = ListVRF(list()) for vrf in cmd_output.get('instance-information') \ .get('instance-core'): if _juniper_vrf_filter(vrf.get('instance-name')): rd = NOT_SET, rt_imp = NOT_SET rt_exp = NOT_SET imp_targ = NOT_SET exp_targ = NOT_SET if "instance-vrf" in vrf.keys(): rd = vrf.get('instance-vrf') \ .get('route-distinguisher', NOT_SET) rt_imp = vrf.get('instance-vrf') \ .get('vrf-import', NOT_SET) rt_exp = vrf.get('instance-vrf') \ .get('vrf-export', NOT_SET) imp_targ = vrf.get('instance-vrf') \ .get('vrf-import-target', NOT_SET) exp_targ = vrf.get('instance-vrf') \ .get('vrf-export-target', NOT_SET) vrf_list.vrf_lst.append( VRF(vrf_name=_juniper_vrf_default_mapping( vrf.get('instance-name')), vrf_id=vrf.get('router-id', NOT_SET), vrf_type=vrf.get('instance-type', NOT_SET), l3_vni=NOT_SET, rd=rd, rt_imp=rt_imp, rt_exp=rt_exp, imp_targ=imp_targ, exp_targ=exp_targ, options=options)) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(vrf_list.to_json()) return vrf_list
def _arista_vrf_ssh_converter( hostname: str(), cmd_output, options={} ) -> ListVRF: if not isinstance(cmd_output, dict): cmd_output = json.loads(cmd_output) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL3 ): printline() print(cmd_output) vrf_list = ListVRF(list()) for vrf_name, facts in cmd_output.get('vrfs').items(): if ( facts.get('routeDistinguisher', NOT_SET) == NOT_SET or facts.get('routeDistinguisher', NOT_SET) == '' ): rd = NOT_SET else: rd = facts.get('routeDistinguisher', NOT_SET) vrf_obj = VRF( vrf_name=vrf_name, vrf_id=NOT_SET, vrf_type=NOT_SET, l3_vni=NOT_SET, rd=rd, rt_imp=NOT_SET, rt_exp=NOT_SET, imp_targ=NOT_SET, exp_targ=NOT_SET, options=options ) vrf_list.vrf_lst.append( vrf_obj ) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1 ): printline() print(f">>>>> {hostname}") PP.pprint(vrf_list.to_json()) return vrf_list
def _ios_vrf_ssh_converter(hostname: str(), cmd_output, options={}) -> ListVRF: cmd_output = re.sub(pattern=r"communities[\n\r]\s+RT", repl="communities:RT", string=cmd_output) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NSET), needed_value=LEVEL4): printline() print(cmd_output) template = open(f"{TEXTFSM_PATH}cisco_ios_show_ip_vrf_detail.textfsm") results_template = textfsm.TextFSM(template) # Example : [ # ['mgmt', '1', '<not set>'], # ['tenant-1', '2', '10.255.255.103:103'] # ] parsed_results = results_template.ParseText(cmd_output) vrf_list = ListVRF(list()) # Add the default VRF maually vrf_list.vrf_lst.append( VRF(vrf_name="default", vrf_id="0", vrf_type=NSET, l3_vni=NSET, rd=NSET, rt_imp=NSET, rt_exp=NSET, exp_targ=NSET, imp_targ=NSET, options=options)) for l in parsed_results: vrf_list.vrf_lst.append( VRF(vrf_name=l[0] if l[0] != "<not set>" and l[0] != '' else NSET, vrf_id=l[1] if l[1] != "<not set>" and l[1] != '' else NSET, vrf_type=NSET, l3_vni=NSET, rd=l[2] if l[2] != "<not set>" and l[2] != '' else NSET, rt_imp=l[5] if l[5] != "<not set>" and l[5] != '' else NSET, rt_exp=l[6] if l[6] != "<not set>" and l[6] != '' else NSET, exp_targ=NSET, imp_targ=NSET, options=options)) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NSET), needed_value=LEVEL1): printline() print(f">>>>> {hostname}") PP.pprint(vrf_list.to_json()) return vrf_list
def _iosxr_vrf_ssh_converter(hostname: str(), cmd_output, options={}) -> ListVRF: cmd_output = re.sub(pattern=r"communities:[\n\r]\s+RT", repl="communities:RT", string=cmd_output) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL4): printline() print(cmd_output) template = open(f"{TEXTFSM_PATH}cisco_xr_show_vrf_all_detail.textfsm") results_template = textfsm.TextFSM(template) parsed_results = results_template.ParseText(cmd_output) list_vrf = ListVRF(list()) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL3): printline() print(parsed_results) for l in parsed_results: vrf = VRF( vrf_name=l[0] if l[0] != "not set" and l[0] != '' else NOT_SET, vrf_id=NOT_SET, vrf_type=l[3] if l[3] != "not set" and l[3] != '' else NOT_SET, l3_vni=NOT_SET, rd=l[1] if l[1] != "not set" and l[1] != '' else NOT_SET, rt_imp=l[5] if l[5] != "not set" and l[5] != '' else NOT_SET, rt_exp=l[6] if l[6] != "not set" and l[6] != '' else NOT_SET, imp_targ=NOT_SET, exp_targ=NOT_SET, options=options) list_vrf.vrf_lst.append(vrf) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(list_vrf.to_json()) return list_vrf
def _juniper_vrf_ssh_converter(hostname: str(), cmd_output, options={}) -> ListVRF: vrf_list = ListVRF(list()) for vrf in cmd_output.get('instance-information')[0].get('instance-core'): if _juniper_vrf_filter( vrf.get('instance-name')[0].get('data', NOT_SET)): vrf_obj = VRF() vrf_obj.vrf_name = _juniper_vrf_default_mapping( vrf.get('instance-name')[0].get('data', NOT_SET)) vrf_obj.vrf_id = vrf.get('router-id')[0].get('data', NOT_SET) vrf_obj.vrf_type = vrf.get('instance-type')[0].get('data', NOT_SET) vrf_obj.l3_vni = NOT_SET if "instance-vrf" in vrf.keys(): vrf_obj.rd = vrf.get('instance-vrf')[0] \ .get('route-distinguisher')[0] \ .get('data', NOT_SET) vrf_obj.rt_imp = vrf.get('instance-vrf')[0] \ .get('vrf-import')[0] \ .get('data', NOT_SET) vrf_obj.rt_exp = vrf.get('instance-vrf')[0]\ .get('vrf-export')[0] \ .get('data', NOT_SET) vrf_obj.imp_targ = vrf.get('instance-vrf')[0] \ .get('vrf-import-target')[0] \ .get('data', NOT_SET) vrf_obj.exp_targ = vrf.get('instance-vrf')[0] \ .get('vrf-export-target')[0] \ .get('data', NOT_SET) vrf_obj.options = options vrf_list.vrf_lst.append(vrf_obj) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(vrf_list.to_json()) return vrf_list
def _napalm_vrf_converter( hostname: str(), cmd_output: json, options={} ) -> ListVRF: vrf_list = ListVRF(list()) for vrf in cmd_output.get('get_network_instances'): vrf_list.vrf_lst.append( VRF( vrf_name=vrf, vrf_type=cmd_output.get('get_network_instances') .get(vrf) .get('type', NOT_SET), rd=cmd_output.get('get_network_instances') .get(vrf) .get('state') .get('route_distinguisher') if cmd_output.get('get_network_instances') .get(vrf) .get('state') .get('route_distinguisher', NOT_SET) != "" else NOT_SET ) ) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1 ): printline() PP.pprint(vrf_list.to_json()) return vrf_list
def _extreme_vsp_vrf_ssh_converter( hostname: str(), cmd_output, options={} ) -> ListVRF: template = open( f"{TEXTFSM_PATH}extreme_vsp_show_ip_vrf.textfsm") results_template = textfsm.TextFSM(template) parsed_results = results_template.ParseText(cmd_output) vrf_list = ListVRF(list()) for vrf in parsed_results: vrf_list.vrf_lst.append( VRF( vrf_name=vrf[0], vrf_id=vrf[1], vrf_type=NOT_SET, l3_vni=NOT_SET, rd=NOT_SET, rt_imp=NOT_SET, rt_exp=NOT_SET, exp_targ=NOT_SET, imp_targ=NOT_SET, options=options ) ) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1 ): printline() print(f">>>>> {hostname}") PP.pprint(vrf_list.to_json()) return vrf_list
def _ios_vrf_api_converter( hostname: str(), cmd_output, options={} ) -> ListVRF: if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL5 ): printline() print(type(cmd_output)) print(cmd_output) cmd_output = format_xml_output(cmd_output) vrf_list = ListVRF(vrf_lst=list()) vrf_list.vrf_lst.append( VRF( vrf_name='default', vrf_id=NOT_SET, vrf_type=NOT_SET, l3_vni=NOT_SET, rd=NOT_SET, rt_imp=NOT_SET, rt_exp=NOT_SET, imp_targ=NOT_SET, exp_targ=NOT_SET, options=options ) ) if ( 'native' in cmd_output.keys() and 'vrf' in cmd_output.get('native').keys() and 'definition' in cmd_output.get('native').get('vrf').keys() ): if isinstance(cmd_output.get('native') .get('vrf') .get('definition'), dict): rt_imp = NOT_SET rt_exp = NOT_SET if 'route-target' in cmd_output.get('native') \ .get('vrf') \ .get('definition').keys(): if ( 'export' in cmd_output.get('native') .get('vrf') .get('definition') .get('route-target').keys() and 'asn-ip' in cmd_output.get('native') .get('vrf') .get('definition') .get('route-target') .get('export').keys() ): rt_exp = cmd_output.get('native') \ .get('vrf') \ .get('definition') \ .get('route-target') \ .get('export') \ .get('asn-ip') if ( 'import' in cmd_output.get('native') .get('vrf') .get('definition') .get('route-target').keys() and 'asn-ip' in cmd_output.get('native') .get('vrf') .get('definition') .get('route-target') .get('import').keys() ): rt_exp = cmd_output.get('native') \ .get('vrf') \ .get('definition') \ .get('route-target') \ .get('import') \ .get('asn-ip') vrf_list.vrf_lst.append( VRF( vrf_name=cmd_output.get('native') .get('vrf') .get('definition') .get('name'), vrf_id=NOT_SET, vrf_type=NOT_SET, l3_vni=NOT_SET, rd=cmd_output.get('native') .get('vrf') .get('definition') .get('rd', NOT_SET), rt_imp=rt_imp, rt_exp=rt_exp, imp_targ=NOT_SET, exp_targ=NOT_SET ) ) elif isinstance(cmd_output.get('native') .get('vrf') .get('definition'), list): for v in cmd_output.get('native') \ .get('vrf') \ .get('definition'): rt_imp = NOT_SET rt_exp = NOT_SET if 'route-target' in v.keys(): if ( 'export' in v.get('route-target').keys() and 'asn-ip' in v.get('route-target').get('export').keys() ): rt_exp = v.get( 'route-target').get('export').get('asn-ip') if ( 'import' in v.get('route-target').keys() and 'asn-ip' in v.get('route-target').get('export').keys() ): rt_imp = v.get( 'route-target').get('import').get('asn-ip') vrf_list.vrf_lst.append( VRF( vrf_name=v.get('name', NOT_SET), vrf_id=NOT_SET, vrf_type=NOT_SET, l3_vni=NOT_SET, rd=v.get('rd', NOT_SET), rt_imp=rt_imp, rt_exp=rt_exp, imp_targ=NOT_SET, exp_targ=NOT_SET ) ) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1 ): printline() print(f">>>>> {hostname}") PP.pprint(vrf_list.to_json()) return vrf_list
def _nxos_vrf_api_converter(hostname: str(), cmd_output, options={}) -> ListVRF: if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL5): printline() print(type(cmd_output)) print(cmd_output) cmd_output = format_xml_output(cmd_output) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL4): printline() print(type(cmd_output)) PP.pprint(cmd_output) vrf_list = ListVRF(vrf_lst=list()) for v in cmd_output.get('inst-items').get('Inst-list'): rd = NOT_SET rt_exp = NOT_SET rt_imp = NOT_SET if ('dom-items' in v.keys() and 'Dom-list' in v.get('dom-items') and 'af-items' in v.get('dom-items').get('Dom-list').keys() and 'DomAf-list' in v.get('dom-items').get('Dom-list').get('af-items').keys() and 'ctrl-items' in v.get('dom-items').get('Dom-list').get( 'af-items').get('DomAf-list').keys() and 'AfCtrl-list' in v.get('dom-items').get('Dom-list').get( 'af-items').get('DomAf-list').get('ctrl-items').keys() and 'rttp-items' in v.get('dom-items').get('Dom-list').get('af-items').get( 'DomAf-list').get('ctrl-items').get('AfCtrl-list').keys() and 'RttP-list' in v.get('dom-items').get('Dom-list').get( 'af-items').get('DomAf-list').get('ctrl-items').get( 'AfCtrl-list').get('rttp-items').keys()): for i in v.get('dom-items') \ .get('Dom-list') \ .get('af-items') \ .get('DomAf-list') \ .get('ctrl-items') \ .get('AfCtrl-list') \ .get('rttp-items') \ .get('RttP-list'): if i.get('type', NOT_SET) == 'export': if ('ent-items' in i.keys() and 'RttEntry-list' in i.get('ent-items').keys() and 'rtt' in i.get('ent-items').get('RttEntry-list').keys()): y = i.get('ent-items') \ .get('RttEntry-list') \ .get('rtt').split(':') rt_exp = f"{y[-2]}:{y[-1]}" if i.get('type', NOT_SET) == 'import': if ('ent-items' in i.keys() and 'RttEntry-list' in i.get('ent-items').keys() and 'rtt' in i.get('ent-items').get('RttEntry-list').keys()): z = i.get('ent-items') \ .get('RttEntry-list') \ .get('rtt').split(':') rt_imp = f"{z[-2]}:{z[-1]}" if ('dom-items' in v.keys() and 'Dom-list' in v.get('dom-items') and 'rd' in v.get('dom-items').get('Dom-list').keys()): t = v.get('dom-items') \ .get('Dom-list') \ .get('rd').split(':') rd = f"{t[-2]}:{t[-1]}" vrf_list.vrf_lst.append( VRF(vrf_name=v.get('name', NOT_SET), vrf_id=v.get('id', NOT_SET), vrf_type=NOT_SET, l3_vni=v.get('encap', NOT_SET), rd=rd, rt_imp=rt_imp, rt_exp=rt_exp, imp_targ=NOT_SET, exp_targ=NOT_SET, options=options)) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() print(f">>>>> {hostname}") PP.pprint(vrf_list.to_json()) return vrf_list
def _arista_vrf_netconf_converter( hostname: str(), cmd_output, options={} ) -> ListVRF: cmd_output = format_xml_output(cmd_output) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL3 ): printline() PP.pprint(cmd_output) if ( 'data' in cmd_output.keys() and 'network-instances' in cmd_output.get('data').keys() and 'network-instance' in cmd_output.get('data') .get('network-instances') .keys() ): vrf_list = ListVRF(list()) if isinstance( cmd_output.get('data') .get('network-instances') .get('network-instance'), dict ): vrf_list.vrf_lst.append( VRF( vrf_name=cmd_output.get('data') .get('network-instances') .get('network-instance') .get('name', NOT_SET), vrf_id=NOT_SET, vrf_type=NOT_SET, l3_vni=NOT_SET, rd=NOT_SET, rt_imp=NOT_SET, rt_exp=NOT_SET, imp_targ=NOT_SET, exp_targ=NOT_SET, options=options ) ) elif isinstance( cmd_output.get('data') .get('network-instances') .get('network-instance'), list ): for v in cmd_output.get('data') \ .get('network-instances') \ .get('network-instance'): vrf_list.vrf_lst.append( VRF( vrf_name=v.get('name', NOT_SET), vrf_id=NOT_SET, vrf_type=NOT_SET, l3_vni=NOT_SET, rd=NOT_SET, rt_imp=NOT_SET, rt_exp=NOT_SET, imp_targ=NOT_SET, exp_targ=NOT_SET, options=options ) ) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1 ): printline() print(f">>>>> {hostname}") PP.pprint(vrf_list.to_json()) return vrf_list
def _iosxr_vrf_netconf_converter( hostname: str(), cmd_output, options={} ) -> ListVRF: if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL5 ): printline() print(type(cmd_output)) PP.pprint(cmd_output) if cmd_output.get('VRF') is not None: cmd_output['VRF'] = format_xml_output(cmd_output.get('VRF')) if cmd_output.get('BGP') is not None: cmd_output['BGP'] = format_xml_output(cmd_output.get('BGP')) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL4 ): printline() print(type(cmd_output)) PP.pprint(cmd_output) vrf_list = ListVRF(vrf_lst=list()) if ( 'VRF' in cmd_output.keys() and 'data' in cmd_output.get('VRF').keys() and 'vrfs' in cmd_output.get('VRF').get('data').keys() and 'vrf' in cmd_output.get('VRF').get('data').get('vrfs').keys() ): if isinstance( cmd_output.get('VRF').get('data').get('vrfs').get('vrf'), dict ): rias = None riin = None reas = None rein = None v = cmd_output.get('VRF').get('data').get('vrfs').get('vrf') if ( 'afs' in v.keys() and 'af' in v.get('afs').keys() and 'bgp' in v.get('afs').get('af').keys() ): rias = v.get('afs').get('af').get('bgp') \ .get('import-route-targets') \ .get('route-targets') \ .get('route-target') \ .get('as-or-four-byte-as') \ .get('as') riin = v.get('afs').get('af').get('bgp') \ .get('import-route-targets') \ .get('route-targets') \ .get('route-target') \ .get('as-or-four-byte-as') \ .get('as-index') reas = v.get('afs').get('af').get('bgp') \ .get('export-route-targets') \ .get('route-targets') \ .get('route-target') \ .get('as-or-four-byte-as') \ .get('as') rein = v.get('afs').get('af').get('bgp') \ .get('export-route-targets') \ .get('route-targets') \ .get('route-target') \ .get('as-or-four-byte-as') \ .get('as-index') rd = NOT_SET if ( cmd_output.get('BGP') is not None and 'data' in cmd_output.get('BGP').keys() and 'bgp' in cmd_output.get('BGP') .get('data').keys() and 'instance' in cmd_output.get('BGP') .get('data') .get('bgp').keys() and 'instance-as' in cmd_output.get('BGP') .get('data') .get('bgp') .get('instance').keys() and 'four-byte-as' in cmd_output.get('BGP') .get('data') .get('bgp') .get('instance') .get('instance-as').keys() and 'vrfs' in cmd_output.get('BGP') .get('data') .get('bgp') .get('instance') .get('instance-as') .get('four-byte-as').keys() and 'vrf' in cmd_output.get('BGP') .get('data') .get('bgp') .get('instance') .get('instance-as') .get('four-byte-as') .get('vrfs').keys() ): if isinstance(cmd_output.get('BGP') .get('data') .get('bgp') .get('instance') .get('instance-as') .get('four-byte-as') .get('vrfs') .get('vrf'), dict): vrf = cmd_output.get('BGP') \ .get('data') \ .get('bgp') \ .get('instance') \ .get('instance-as') \ .get('four-byte-as') \ .get('vrfs') \ .get('vrf') if vrf.get('vrf-name') == v.get('vrf-name'): if ( 'vrf-global' in vrf.keys() and 'route-distinguisher' in vrf.get('vrf-global') .keys() ): rd = vrf.get('vrf-global') \ .get('route-distinguisher') \ .get('as') + ":" + \ vrf.get('vrf-global') \ .get('route-distinguisher') \ .get('as-index') elif isinstance(cmd_output.get('BGP') .get('data') .get('bgp') .get('instance') .get('instance-as') .get('four-byte-as') .get('vrfs') .get('vrf'), list): for vrf in cmd_output.get('BGP') \ .get('data') \ .get('bgp') \ .get('instance') \ .get('instance-as') \ .get('four-byte-as') \ .get('vrfs') \ .get('vrf'): if vrf.get('vrf-name') == v.get('vrf-name'): if ( 'vrf-global' in vrf.keys() and 'route-distinguisher' in vrf.get('vrf-global').keys() ): rd = vrf.get('vrf-global') \ .get('route-distinguisher') \ .get('as') + ":" + \ vrf.get('vrf-global') \ .get('route-distinguisher') \ .get('as-index') vrf_list.vrf_lst.append( VRF( vrf_name=v.get('vrf-name'), vrf_id=NOT_SET, vrf_type=NOT_SET, l3_vni=NOT_SET, rd=rd, rt_imp=f"{rias}:{riin}" if rias is not None else NOT_SET, rt_exp=f"{reas}:{rein}" if reas is not None else NOT_SET, imp_targ=NOT_SET, exp_targ=NOT_SET, options=options ) ) elif isinstance( cmd_output.get('VRF').get('data').get('vrfs').get('vrf'), list ): for v in cmd_output.get('VRF').get('data').get('vrfs').get('vrf'): rias = None riin = None reas = None rein = None if ( 'afs' in v.keys() and 'af' in v.get('afs').keys() and 'bgp' in v.get('afs').get('af').keys() ): rias = v.get('afs').get('af').get('bgp') \ .get('import-route-targets') \ .get('route-targets') \ .get('route-target') \ .get('as-or-four-byte-as') \ .get('as') riin = v.get('afs').get('af').get('bgp') \ .get('import-route-targets') \ .get('route-targets') \ .get('route-target') \ .get('as-or-four-byte-as') \ .get('as-index') reas = v.get('afs').get('af').get('bgp') \ .get('export-route-targets') \ .get('route-targets') \ .get('route-target') \ .get('as-or-four-byte-as') \ .get('as') rein = v.get('afs').get('af').get('bgp') \ .get('export-route-targets') \ .get('route-targets') \ .get('route-target') \ .get('as-or-four-byte-as') \ .get('as-index') rd = NOT_SET if ( cmd_output.get('BGP') is not None and 'data' in cmd_output.get('BGP').keys() and 'bgp' in cmd_output.get('BGP') .get('data').keys() and 'instance' in cmd_output.get('BGP') .get('data') .get('bgp').keys() and 'instance-as' in cmd_output.get('BGP') .get('data') .get('bgp') .get('instance').keys() and 'four-byte-as' in cmd_output.get('BGP') .get('data') .get('bgp') .get('instance') .get('instance-as').keys() and 'vrfs' in cmd_output.get('BGP') .get('data') .get('bgp') .get('instance') .get('instance-as') .get('four-byte-as').keys() and 'vrf' in cmd_output.get('BGP') .get('data') .get('bgp') .get('instance') .get('instance-as') .get('four-byte-as') .get('vrfs').keys() ): if isinstance(cmd_output.get('BGP') .get('data') .get('bgp') .get('instance') .get('instance-as') .get('four-byte-as') .get('vrfs') .get('vrf'), dict): vrf = cmd_output.get('BGP') \ .get('data') \ .get('bgp') \ .get('instance') \ .get('instance-as') \ .get('four-byte-as') \ .get('vrfs') \ .get('vrf') if vrf.get('vrf-name') == v.get('vrf-name'): if ( 'vrf-global' in vrf.keys() and 'route-distinguisher' in vrf.get('vrf-global') .keys() ): rd = vrf.get('vrf-global') \ .get('route-distinguisher') \ .get('as') + ":" + \ vrf.get('vrf-global') \ .get('route-distinguisher') \ .get('as-index') elif isinstance(cmd_output.get('BGP') .get('data') .get('bgp') .get('instance') .get('instance-as') .get('four-byte-as') .get('vrfs') .get('vrf'), list): for vrf in cmd_output.get('BGP') \ .get('data') \ .get('bgp') \ .get('instance') \ .get('instance-as') \ .get('four-byte-as') \ .get('vrfs') \ .get('vrf'): if vrf.get('vrf-name') == v.get('vrf-name'): if ( 'vrf-global' in vrf.keys() and 'route-distinguisher' in vrf.get('vrf-global').keys() ): rd = vrf.get('vrf-global') \ .get('route-distinguisher') \ .get('as') + ":" + \ vrf.get('vrf-global') \ .get('route-distinguisher') \ .get('as-index') vrf_list.vrf_lst.append( VRF( vrf_name=v.get('vrf-name'), vrf_id=NOT_SET, vrf_type=NOT_SET, l3_vni=NOT_SET, rd=rd, rt_imp=f"{rias}:{riin}" if rias is not None else NOT_SET, rt_exp=f"{reas}:{rein}" if reas is not None else NOT_SET, imp_targ=NOT_SET, exp_targ=NOT_SET, options=options ) ) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1 ): printline() print(f">>>>> {hostname}") PP.pprint(vrf_list.to_json()) return vrf_list