def _juniper_bgp_api_converter(hostname: str, cmd_output: dict, options={}) -> BGP: bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) for k, v in cmd_output.items(): if not isinstance(v.get('bgp'), dict): v['bgp'] = format_xml_output(v.get('bgp')) if not isinstance(v.get('rid'), dict): v['rid'] = format_xml_output(v.get('rid')) if verbose_mode(user_value=os.environ.get('NETESTS_VERBOSE', NOT_SET), needed_value=LEVEL3): printline() PP.pprint(v) bgp_sessions_lst = ListBGPSessions(list()) if ('bgp' in v.keys() and 'bgp-information' in v.get('bgp').keys() and v.get('bgp').get('bgp-information') is not None and 'bgp-peer' in v.get('bgp').get('bgp-information').keys()): for n in v.get('bgp').get('bgp-information').get('bgp-peer'): bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname=hostname, peer_ip=n.get('peer-address', NOT_SET), peer_hostname=NOT_SET, remote_as=n.get('peer-as', NOT_SET), state_brief=get_bgp_state_brief( n.get('peer-state', NOT_SET)), session_state=n.get('peer-state', NOT_SET), state_time=NOT_SET, prefix_received=NOT_SET, options=options)) as_number = n.get('bgp-option-information').get('local-as') router_id = NOT_SET if ('rid' in v.keys() and 'instance-information' in v.get('rid').keys() and 'instance-core' in v.get('rid').get('instance-information').keys()): router_id = v.get('rid') \ .get('instance-information') \ .get('instance-core') \ .get('router-id') bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name=k, as_number=as_number, router_id=router_id, bgp_sessions=bgp_sessions_lst)) bgp = BGP(hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst) if verbose_mode(user_value=os.environ.get('NETESTS_VERBOSE', NOT_SET), needed_value=LEVEL1): printline() print(f'>>>>> {hostname}') PP.pprint(bgp.to_json()) return bgp
def _extreme_vsp_bgp_ssh_converter(hostname: str, cmd_output, options={}) -> BGP: if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL3): printline() PP.pprint(cmd_output) bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) if cmd_output is not None: for vrf in cmd_output: cmd_output[vrf] = parse_textfsm( content=str(cmd_output[vrf]), template_file="extreme_vsp_show_ip_bgp_summary.textfsm") bgp_sessions_lst = ListBGPSessions(bgp_sessions=list()) asn = NOT_SET router_id = NOT_SET for v in cmd_output.get(vrf): if v[3] != '': asn = v[1] router_id = v[2] bgp_sessions_lst.bgp_sessions.append( BGPSession( src_hostname=hostname, peer_ip=v[3], peer_hostname=NOT_SET, remote_as=v[4], state_brief=get_bgp_state_brief(v[5]), session_state=v[5], state_time=_extreme_vsp_peer_uptime_converter( day=v[13], hour=v[14], min=v[15], sec=v[16], ), prefix_received=NOT_SET, )) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF( vrf_name=vrf, as_number=asn, router_id=router_id, bgp_sessions=bgp_sessions_lst, )) bgp = BGP(hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() print(f">>>>> {hostname}") PP.pprint(bgp.to_json()) return bgp
def _cumulus_bgp_api_converter(hostname: str, cmd_output, options={}) -> BGP: bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) for k, v in cmd_output.items(): if not isinstance(v, dict): v = json.loads(v) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL3): printline() PP.pprint(v) peer = False if ('ipv4 unicast' in v.keys() and 'ipv4Unicast' in v.get('ipv4 unicast').keys() and 'peers' in v.get('ipv4 unicast').get('ipv4Unicast').keys()): sub_dict = v.get('ipv4 unicast').get('ipv4Unicast') peer = True elif ('ipv4 unicast' in v.keys() and 'peers' in v.get('ipv4 unicast').keys()): sub_dict = v.get('ipv4 unicast') peer = True if peer: bgp_vrf = BGPSessionsVRF( vrf_name=k, as_number=sub_dict.get('as', NOT_SET), router_id=sub_dict.get('routerId', NOT_SET), bgp_sessions=ListBGPSessions(bgp_sessions=list())) for i, p in sub_dict.get('peers').items(): bgp_vrf.bgp_sessions.bgp_sessions.append( BGPSession(src_hostname=hostname, peer_ip=i, peer_hostname=p.get('hostname', NOT_SET), remote_as=p.get('remoteAs', NOT_SET), state_brief=get_bgp_state_brief( p.get('state', NOT_SET)), session_state=p.get('state', NOT_SET), state_time=get_bgp_peer_uptime( value=p.get('peerUptimeMsec', NOT_SET), format=BGP_UPTIME_FORMAT_MS), prefix_received=p.get('prefixReceivedCount', NOT_SET), options=options)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append(bgp_vrf) bgp = BGP(hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() print(f">>>>> {hostname}") PP.pprint(bgp.to_json()) return bgp
def _iosxr_bgp_ssh_converter(hostname: str, cmd_output: dict, options={}) -> BGP: bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) for k, v in cmd_output.items(): v['peers'] = parse_textfsm( content=v.get('peers'), template_file='cisco_xr_show_bgp_neighbors.textfsm') v['rid'] = parse_textfsm(content=v.get('rid'), template_file='cisco_xr_show_bgp.textfsm') if verbose_mode(user_value=os.environ.get('NETESTS_VERBOSE', NOT_SET), needed_value=LEVEL3): printline() print(v) bgp_sessions_lst = ListBGPSessions(list()) asn = NOT_SET if len(v['peers']) > 0: for i in v['peers']: asn = i[3] bgp_sessions_lst.bgp_sessions.append( BGPSession( src_hostname=hostname, peer_ip=i[0], peer_hostname=NOT_SET, remote_as=i[2], state_brief=get_bgp_state_brief(i[4]), session_state=i[4], state_time=NOT_SET, prefix_received=NOT_SET, )) if len(v['rid']) > 0: rid = v['rid'][0][0] else: rid = NOT_SET bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF( vrf_name=k, as_number=asn, router_id=rid, bgp_sessions=bgp_sessions_lst, )) bgp = BGP(hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst) if verbose_mode(user_value=os.environ.get('NETESTS_VERBOSE', NOT_SET), needed_value=LEVEL1): printline() print(f'>>>>> {hostname}') PP.pprint(bgp.to_json()) return bgp
def step_impl(context): bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf04", peer_ip="10.1.1.1", peer_hostname=NOT_SET, remote_as="65333", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=NOT_SET, prefix_received=NOT_SET)) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf04", peer_ip="10.2.2.2", peer_hostname=NOT_SET, remote_as="65333", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=NOT_SET, prefix_received=NOT_SET)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="CUSTOMER_AWS", as_number="65444", router_id="9.9.9.9", bgp_sessions=bgp_sessions_lst)) context.o0501 = BGP(hostname="leaf04", bgp_sessions_vrf_lst=bgp_sessions_vrf_lst)
def _arista_bgp_api_converter(hostname: str, cmd_output, options={}) -> BGP: bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL3): printline() PP.pprint(cmd_output) bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) for vrf in cmd_output.get('result', []): if 'vrfs' in vrf.keys() and len(vrf.get('vrfs').keys()) > 0: bgp_sessions_lst = ListBGPSessions(list()) for name, facts in vrf.get("vrfs", NOT_SET).items(): for n, f in facts.get('peers').items(): bgp_sessions_lst.bgp_sessions.append( BGPSession( src_hostname=hostname, peer_ip=n, peer_hostname=f.get("hostname", NOT_SET), remote_as=f.get("asn", NOT_SET), state_brief=get_bgp_state_brief( state=f.get('peerState')), session_state=f.get("peerState", NOT_SET), state_time=f.get("upDownTime", NOT_SET), prefix_received=f.get("prefixReceived", NOT_SET), )) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF( vrf_name=name, as_number=facts.get('asn', NOT_SET), router_id=facts.get("routerId", NOT_SET), bgp_sessions=bgp_sessions_lst, )) bgp = BGP(hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() print(f">>>>> {hostname}") PP.pprint(bgp.to_json()) return bgp
def _napalm_bgp_converter(hostname: str(), cmd_output: json, options={}) -> BGP: bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) local_as = "" if "get_bgp_neighbors" in cmd_output.keys(): for k, v in cmd_output.get("get_bgp_neighbors").items(): bgp_sessions_lst = ListBGPSessions(list()) for peer_ip, facts in v.get("peers").items(): bgp_obj = BGPSession( src_hostname=hostname, peer_ip=peer_ip, peer_hostname=facts.get("hostname", NOT_SET), remote_as=facts.get("remote_as", NOT_SET), state_brief=_napalm_bgp_status_converter( facts.get("is_up", NOT_SET)), session_state=facts.get("session_state", NOT_SET), state_time=facts.get("uptime", NOT_SET), prefix_received=facts.get("address_family").get( "ipv4").get("received_prefixes"), ) local_as = facts.get("local_as", NOT_SET) bgp_sessions_lst.bgp_sessions.append(bgp_obj) bgp_session_vrf = BGPSessionsVRF( vrf_name=_napalm_bgp_vrf_converter(k), as_number=local_as, router_id=v.get("router_id"), bgp_sessions=bgp_sessions_lst, ) bgp_sessions_vrf_lst.bgp_sessions_vrf.append(bgp_session_vrf) bgp = BGP(hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst) if verbose_mode(user_value=os.environ.get('NETESTS_VERBOSE', NOT_SET), needed_value=LEVEL1): printline() print(f'>>>>> {hostname}') PP.pprint(bgp.to_json()) return bgp
def step_impl(context): bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf05", peer_ip="33.3.3.3", peer_hostname=NOT_SET, remote_as="3", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=get_bgp_peer_uptime(value=0, format=BGP_UPTIME_FORMAT_MS), prefix_received=NOT_SET)) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf05", peer_ip="33.33.33.33", peer_hostname=NOT_SET, remote_as="3", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=get_bgp_peer_uptime(value=0, format=BGP_UPTIME_FORMAT_MS), prefix_received=NOT_SET)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="CUSTOMER_APPLE", as_number="33333", router_id="33.33.33.33", bgp_sessions=bgp_sessions_lst)) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf05", peer_ip="15.15.15.15", peer_hostname=NOT_SET, remote_as="15", state_brief=get_bgp_state_brief("fsm-idle"), session_state="fsm-idle", state_time=get_bgp_peer_uptime(value=0, format=BGP_UPTIME_FORMAT_MS), prefix_received=NOT_SET)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="CUSTOMER_NETESTS", as_number="33333", router_id="33.33.33.33", bgp_sessions=bgp_sessions_lst)) context.o0301 = BGP(hostname="leaf05", bgp_sessions_vrf_lst=bgp_sessions_vrf_lst)
def step_impl(context): bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf03", peer_ip="100.100.100.100", peer_hostname=NOT_SET, remote_as="100", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=1588518931.27118, prefix_received=0)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="CUSTOMER_WEJOB", as_number="1111", router_id="1.2.3.4", bgp_sessions=bgp_sessions_lst)) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf03", peer_ip="11.11.11.11", peer_hostname=NOT_SET, remote_as="11", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=1588518176.788854, prefix_received=0)) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf03", peer_ip="12.12.12.12", peer_hostname=NOT_SET, remote_as="12", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=1588518913.789179, prefix_received=0)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="CUSTOMER_NETESTS", as_number="1111", router_id="66.66.66.66", bgp_sessions=bgp_sessions_lst)) context.o0001 = BGP(hostname="leaf03", bgp_sessions_vrf_lst=bgp_sessions_vrf_lst)
def step_impl(context): bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf02", peer_ip="172.16.0.2", peer_hostname=NOT_SET, remote_as="65535", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=NOT_SET, prefix_received=NOT_SET)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="default", as_number="65535", router_id="172.16.0.1", bgp_sessions=bgp_sessions_lst)) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf02", peer_ip="11.1.1.1", peer_hostname=NOT_SET, remote_as="1", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=NOT_SET, prefix_received=NOT_SET)) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf02", peer_ip="22.2.2.2", peer_hostname=NOT_SET, remote_as="2", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=NOT_SET, prefix_received=NOT_SET)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="CUSTOMER_GOOGLE", as_number="65535", router_id="0.0.0.0", bgp_sessions=bgp_sessions_lst)) bgp_sessions_lst = ListBGPSessions(list()) context.o0701 = BGP(hostname="leaf02", bgp_sessions_vrf_lst=bgp_sessions_vrf_lst)
def step_impl(context): bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf01", peer_ip="10.1.1.2", peer_hostname=NOT_SET, remote_as="65102", state_brief=get_bgp_state_brief("Connect"), session_state="Connect", state_time=get_bgp_peer_uptime(value=0, format=BGP_UPTIME_FORMAT_MS), prefix_received=NOT_SET)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="default", as_number="65101", router_id="1.1.1.1", bgp_sessions=bgp_sessions_lst)) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="leaf01", peer_ip="10.1.2.2", peer_hostname=NOT_SET, remote_as="65203", state_brief=get_bgp_state_brief("Connect"), session_state="Connect", state_time=get_bgp_peer_uptime(value=0, format=BGP_UPTIME_FORMAT_MS), prefix_received=NOT_SET)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="IOS_XR_VRF", as_number="65201", router_id="10.10.10.10", bgp_sessions=bgp_sessions_lst)) context.o0101 = BGP(hostname="leaf01", bgp_sessions_vrf_lst=bgp_sessions_vrf_lst)
def step_impl(context): bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="spine02", peer_ip="10.1.1.1", peer_hostname=NOT_SET, remote_as="65101", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=get_bgp_peer_uptime(value="10892000", format=BGP_UPTIME_FORMAT_MS), prefix_received=NOT_SET)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="default", as_number="65101", router_id="2.2.2.2", bgp_sessions=bgp_sessions_lst)) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="spine02", peer_ip="10.20.20.2", peer_hostname=NOT_SET, remote_as="65202", state_brief=get_bgp_state_brief("Idle"), session_state="Idle", state_time=get_bgp_peer_uptime(value=0, format=BGP_UPTIME_FORMAT_MS), prefix_received=NOT_SET)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="mgmt_vrf", as_number="65101", router_id="20.20.20.20", bgp_sessions=bgp_sessions_lst)) context.o0201 = BGP(hostname="spine02", bgp_sessions_vrf_lst=bgp_sessions_vrf_lst)
def step_impl(context): bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) bgp_sessions_lst = ListBGPSessions(list()) bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname="spine03", peer_ip="15.15.15.15", peer_hostname=NOT_SET, remote_as="1515", state_brief="DOWN", session_state="Active", state_time=NOT_SET, prefix_received=NOT_SET)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name="CUSTOMER_NETESTS", as_number="1515", router_id="2.2.2.2", bgp_sessions=bgp_sessions_lst)) context.o0421 = BGP(hostname="spine03", bgp_sessions_vrf_lst=bgp_sessions_vrf_lst)
def _ios_bgp_netconf_converter(hostname: str, cmd_output: dict, options={}) -> BGP: bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) cmd_output = format_xml_output(cmd_output) if verbose_mode(user_value=os.environ.get('NETESTS_VERBOSE', NOT_SET), needed_value=LEVEL3): printline() print(cmd_output) if ('data' in cmd_output.keys() and 'bgp-state-data' in cmd_output.get('data').keys() and 'address-families' in cmd_output.get('data').get('bgp-state-data').keys() and 'address-family' in cmd_output.get('data').get( 'bgp-state-data').get('address-families').keys()): for v in cmd_output.get('data') \ .get('bgp-state-data') \ .get('address-families') \ .get('address-family'): bgp_sessions_lst = ListBGPSessions(list()) if ('bgp-neighbor-summaries' in v.keys() and 'bgp-neighbor-summary' in v.get('bgp-neighbor-summaries').keys()): if isinstance( v.get('bgp-neighbor-summaries').get( 'bgp-neighbor-summary'), list): for n in v.get('bgp-neighbor-summaries') \ .get('bgp-neighbor-summary'): bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname=hostname, peer_ip=n.get('id', NOT_SET), peer_hostname=NOT_SET, remote_as=n.get('as', NOT_SET), state_brief=get_bgp_state_brief( state=n.get('state', NOT_SET)), session_state=n.get('state', NOT_SET), state_time=n.get('up-time', NOT_SET), prefix_received=n.get( 'prefixes-received', 0), options=options)) elif isinstance( v.get('bgp-neighbor-summaries').get( 'bgp-neighbor-summary'), dict): bgp_sessions_lst.bgp_sessions.append( BGPSession( src_hostname=hostname, peer_ip=v.get('bgp-neighbor-summaries').get( 'bgp-neighbor-summary').get('id', NOT_SET), peer_hostname=NOT_SET, remote_as=v.get('bgp-neighbor-summaries').get( 'bgp-neighbor-summary').get('as', NOT_SET), state_brief=get_bgp_state_brief( state=v.get('bgp-neighbor-summaries').get( 'bgp-neighbor-summary').get( 'state', NOT_SET)), session_state=v.get('bgp-neighbor-summaries').get( 'bgp-neighbor-summary').get('state', NOT_SET), state_time=v.get('bgp-neighbor-summaries').get( 'bgp-neighbor-summary').get( 'up-time', NOT_SET), prefix_received=v.get('bgp-neighbor-summaries'). get('bgp-neighbor-summary').get( 'prefixes-received', 0), options=options)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF( vrf_name=v.get('vrf-name'), as_number=v.get('local-as'), router_id=v.get('router-id'), bgp_sessions=bgp_sessions_lst, )) bgp = BGP(hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst) if verbose_mode(user_value=os.environ.get('NETESTS_VERBOSE', NOT_SET), needed_value=LEVEL1): printline() print(f'>>>>> {hostname}') PP.pprint(bgp.to_json()) return bgp
def _nxos_bgp_ssh_converter(hostname: str, cmd_output, options={}) -> BGP: bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) for k, v in cmd_output.items(): if not isinstance(v, dict): v = json.loads(v) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL3): printline() PP.pprint(v) bgp_sessions_lst = ListBGPSessions(list()) if ('TABLE_vrf' in v.keys() and 'ROW_vrf' in v.get('TABLE_vrf').keys() and 'TABLE_neighbor' in v.get('TABLE_vrf').get('ROW_vrf').keys() and 'ROW_neighbor' in v.get('TABLE_vrf').get('ROW_vrf').get( 'TABLE_neighbor').keys()): if isinstance( v.get("TABLE_vrf").get("ROW_vrf").get( "TABLE_neighbor").get("ROW_neighbor", NOT_SET), list, ): for n in v.get("TABLE_vrf", NOT_SET) \ .get("ROW_vrf", NOT_SET) \ .get("TABLE_neighbor", NOT_SET) \ .get("ROW_neighbor", NOT_SET): bgp_sessions_lst.bgp_sessions.append( BGPSession(src_hostname=hostname, peer_ip=n.get("neighbor-id", NOT_SET), peer_hostname=n.get("interfaces", NOT_SET), remote_as=n.get("remoteas", NOT_SET), state_brief=get_bgp_state_brief( n.get("state", NOT_SET)), session_state=n.get("state", NOT_SET), state_time=n.get("LastUpDn", NOT_SET), prefix_received=n.get( "prefixReceived", NOT_SET), options=options)) elif isinstance( v.get("TABLE_vrf", NOT_SET).get("ROW_vrf", NOT_SET).get( "TABLE_neighbor", NOT_SET).get("ROW_neighbor", NOT_SET), dict, ): bgp_sessions_lst.bgp_sessions.append( BGPSession( src_hostname=hostname, peer_ip=v.get("TABLE_vrf", NOT_SET).get( "ROW_vrf", NOT_SET).get("TABLE_neighbor", NOT_SET).get( "ROW_neighbor", NOT_SET).get("neighbor-id", NOT_SET), peer_hostname=v.get("TABLE_vrf", NOT_SET).get( "ROW_vrf", NOT_SET).get("TABLE_neighbor", NOT_SET).get( "ROW_neighbor", NOT_SET).get("interfaces", NOT_SET), remote_as=v.get("TABLE_vrf", NOT_SET).get( "ROW_vrf", NOT_SET).get("TABLE_neighbor", NOT_SET).get( "ROW_neighbor", NOT_SET).get("remoteas", NOT_SET), state_brief=get_bgp_state_brief(state=v.get( "TABLE_vrf", NOT_SET).get("ROW_vrf", NOT_SET).get( "TABLE_neighbor", NOT_SET).get( "ROW_neighbor", NOT_SET).get( "state", NOT_SET)), session_state=v.get("TABLE_vrf", NOT_SET).get( "ROW_vrf", NOT_SET).get("TABLE_neighbor", NOT_SET).get( "ROW_neighbor", NOT_SET).get("state", NOT_SET), state_time=v.get("TABLE_vrf", NOT_SET).get( "ROW_vrf", NOT_SET).get("TABLE_neighbor", NOT_SET).get( "ROW_neighbor", NOT_SET).get("LastUpDn", NOT_SET), prefix_received=v.get("TABLE_vrf", NOT_SET).get( "ROW_vrf", NOT_SET).get("TABLE_neighbor", NOT_SET).get( "ROW_neighbor", NOT_SET).get("prefixReceived", NOT_SET), options=options)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append( BGPSessionsVRF(vrf_name=v.get("TABLE_vrf", NOT_SET).get( "ROW_vrf", NOT_SET).get("vrf-name-out", NOT_SET), as_number=v.get("TABLE_vrf", NOT_SET).get( "ROW_vrf", NOT_SET).get("local-as", NOT_SET), router_id=v.get("TABLE_vrf", NOT_SET).get( "ROW_vrf", NOT_SET).get("router-id", NOT_SET), bgp_sessions=bgp_sessions_lst)) bgp = BGP(hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() print(f">>>>> {hostname}") PP.pprint(bgp.to_json()) return bgp
def _compare_bgp( host_keys, hostname, groups, bgp_host_data: BGP, test=False, options={}, task=Task ): if ( 'own_vars' in options.keys() and options.get('own_vars') is not None and 'enable' in options.get('own_vars').keys() and options.get('own_vars').get('enable') is True ): raise NetestsOverideTruthVarsKeyUnsupported() else: if test: bgp_yaml_data = open_file( path="tests/features/src/bgp_tests.yml" ).get(hostname) else: bgp_yaml_data = select_host_vars( hostname=hostname, groups=groups, protocol="bgp" ) bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) if BGP_SESSIONS_HOST_KEY in host_keys: for vrf_name, facts in bgp_yaml_data.items(): bgp_sessions_lst = ListBGPSessions( list() ) for n in facts.get('neighbors', []): bgp_sessions_lst.bgp_sessions.append( BGPSession( src_hostname=hostname, peer_ip=n.get('peer_ip', NOT_SET), peer_hostname=n.get('peer_hostname', NOT_SET), remote_as=n.get('remote_as', NOT_SET), state_brief=n.get('state_brief', NOT_SET), session_state=n.get('session_state', NOT_SET), state_time=n.get('state_time', NOT_SET), prefix_received=n.get('prefix_received', NOT_SET), ) ) bgp_session_vrf = BGPSessionsVRF( vrf_name=vrf_name, as_number=facts.get('as_number', NOT_SET), router_id=facts.get('router_id', NOT_SET), bgp_sessions=bgp_sessions_lst ) bgp_sessions_vrf_lst.bgp_sessions_vrf.append(bgp_session_vrf) verity_bgp = BGP( hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst ) return verity_bgp == bgp_host_data else: print(f"Key {BGP_SESSIONS_HOST_KEY} is missing for {hostname}") return False
def _nxos_bgp_api_converter(hostname: str, cmd_output, options={}) -> BGP: bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) for k, v in cmd_output.items(): if not isinstance(v, dict): v = json.loads(v) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL3): printline() PP.pprint(v) if ('ins_api' in v.keys() and 'outputs' in v.get('ins_api').keys() and 'output' in v.get('ins_api').get('outputs').keys() and 'body' in v.get('ins_api').get('outputs').get('output').keys() and v.get('ins_api').get('outputs').get('output').get('code') == '200'): bgp_vrf = BGPSessionsVRF( vrf_name=v.get('ins_api').get('outputs').get('output').get( 'body').get('TABLE_vrf').get('ROW_vrf').get( 'vrf-name-out', NOT_SET), as_number=v.get('ins_api').get('outputs').get('output').get( 'body').get('TABLE_vrf').get('ROW_vrf').get( 'local-as', NOT_SET), router_id=v.get('ins_api').get('outputs').get('output').get( 'body').get('TABLE_vrf').get('ROW_vrf').get( 'router-id', NOT_SET), bgp_sessions=ListBGPSessions(bgp_sessions=list())) if isinstance( v.get('ins_api').get('outputs').get('output').get( 'body').get('TABLE_vrf').get('ROW_vrf').get( 'TABLE_neighbor').get('ROW_neighbor'), dict): bgp_vrf.bgp_sessions.bgp_sessions.append( BGPSession( src_hostname=hostname, peer_ip=v.get('ins_api').get('outputs').get( 'output').get('body').get('TABLE_vrf').get( 'ROW_vrf').get('TABLE_neighbor').get( 'ROW_neighbor').get('neighbor-id'), peer_hostname=NOT_SET, remote_as=v.get('ins_api').get('outputs').get( 'output').get('body').get('TABLE_vrf').get( 'ROW_vrf').get('TABLE_neighbor').get( 'ROW_neighbor').get('remoteas'), state_brief=get_bgp_state_brief( state=v.get('ins_api').get('outputs').get( 'output').get('body').get('TABLE_vrf').get( 'ROW_vrf').get('TABLE_neighbor').get( 'ROW_neighbor').get('state')), session_state=v.get('ins_api').get('outputs').get( 'output').get('body').get('TABLE_vrf').get( 'ROW_vrf').get('TABLE_neighbor').get( 'ROW_neighbor').get('state'), state_time=v.get('ins_api').get('outputs').get( 'output').get('body').get('TABLE_vrf').get( 'ROW_vrf').get('TABLE_neighbor').get( 'ROW_neighbor').get('lastflap'), prefix_received=NOT_SET, options=options)) elif isinstance( v.get('ins_api').get('outputs').get('output').get( 'body').get('TABLE_vrf').get('ROW_vrf').get( 'TABLE_neighbor').get('ROW_neighbor'), list): for n in v.get('ins_api') \ .get('outputs') \ .get('output') \ .get('body') \ .get('TABLE_vrf') \ .get('ROW_vrf') \ .get('TABLE_neighbor') \ .get('ROW_neighbor'): bgp_vrf.bgp_sessions.bgp_sessions.append( BGPSession(src_hostname=hostname, peer_ip=n.get('neighbor-id'), peer_hostname=NOT_SET, remote_as=n.get('remoteas'), state_brief=get_bgp_state_brief( state=n.get('state')), session_state=n.get('state'), state_time=n.get('lastflap'), prefix_received=NOT_SET, options=options)) bgp_sessions_vrf_lst.bgp_sessions_vrf.append(bgp_vrf) bgp = BGP(hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() print(f">>>>> {hostname}") PP.pprint(bgp.to_json()) return bgp
def step_impl(context): context.o0411 = BGP(hostname="spine03", bgp_sessions_vrf_lst=list())
def _juniper_bgp_ssh_converter(hostname: str, cmd_output: dict, options={}) -> BGP: bgp_sessions_vrf_lst = ListBGPSessionsVRF(list()) for k, v in cmd_output.items(): if not isinstance(v.get('bgp'), dict): v['bgp'] = json.loads(v.get('bgp')) if not isinstance(v.get('rid'), dict): v['rid'] = json.loads(v.get('rid')) if verbose_mode(user_value=os.environ.get('NETESTS_VERBOSE', NOT_SET), needed_value=LEVEL3): printline() PP.pprint(v) bgp_sessions_lst = ListBGPSessions(list()) local_as = '' if ('bgp' in v.keys() and 'bgp-peer' in v.get('bgp').get('bgp-information')[0].keys()): for bgp_peer in v.get('bgp') \ .get('bgp-information')[0] \ .get('bgp-peer'): local_as = bgp_peer.get('local-as')[0] \ .get('data', NOT_SET) if 'bgp-rib' in bgp_peer.keys(): prefix_rcv = bgp_peer.get('bgp-rib')[0] \ .get('received-prefix-count')[0] \ .get('data', NOT_SET) else: prefix_rcv = NOT_SET bgp_session = BGPSession( src_hostname=hostname, peer_ip=_juniper_bgp_addr_filter( bgp_peer.get('peer-address')[0].get('data', NOT_SET)), peer_hostname=NOT_SET, remote_as=bgp_peer.get('peer-as')[0].get('data', NOT_SET), state_brief=get_bgp_state_brief( bgp_peer.get('peer-state')[0].get('data', NOT_SET), ), session_state=(bgp_peer.get('peer-state')[0].get( 'data', NOT_SET)), state_time=NOT_SET, prefix_received=prefix_rcv, ) bgp_sessions_lst.bgp_sessions.append(bgp_session) router_id = NOT_SET if ('rid' in v.keys() and 'instance-information' in v.get('rid').keys()): router_id = v.get('rid') \ .get('instance-information')[0] \ .get('instance-core')[0] \ .get('router-id')[0] \ .get('data', NOT_SET) bgp_session_vrf = BGPSessionsVRF( vrf_name=k, as_number=local_as, router_id=router_id, bgp_sessions=bgp_sessions_lst, ) bgp_sessions_vrf_lst.bgp_sessions_vrf.append(bgp_session_vrf) bgp = BGP(hostname=hostname, bgp_sessions_vrf_lst=bgp_sessions_vrf_lst) if verbose_mode(user_value=os.environ.get('NETESTS_VERBOSE', NOT_SET), needed_value=LEVEL1): printline() print(f'>>>>> {hostname}') PP.pprint(bgp.to_json()) return bgp