예제 #1
0
def test_loaded_hosts(init_bf):
    """ MAKE SURE ALL THE CONFIGS WERE LOADED """
    # gather the number of files that have the -confg suffix
    num_configs = len(list(Path(SNAPSHOT_DIR).glob("**/*-confg")))
    loaded_configs_df = bfq.fileParseStatus().answer().frame()
    # pytest will output this when the test is failed
    print(loaded_configs_df)
    # filter the frame for only configs marked as passed
    passed_df = loaded_configs_df[loaded_configs_df.Status == "PASSED"]
    assert passed_df.shape[0] == num_configs
예제 #2
0
def BF_init(task: Task, network_name: str, snapshot_name: str,
            snapshot_dir: str, overwrite: bool) -> Result:
    """
    init batfish
    """
    bf_set_network(network_name)
    bf_init_snapshot(snapshot_dir, name=snapshot_name, overwrite=overwrite)
    result = bfq.fileParseStatus().answer()

    result = {
        'Results': result['answerElements'][0]['rows'],
        'Summary': result['answerElements'][0]['summary'],
    }

    return Result(host=task.host, result=result)
def print_debugging_info():
    parse_status = bfq.fileParseStatus().answer().frame()

    print("----------------------")

    print(parse_status)

    print("----------------------")

    parse_warning = bfq.parseWarning().answer().frame()

    print("----------------------")

    print(parse_warning)

    print("----------------------")

    # vxlanEdges,layer3Edges
    node_properties_trunc = bfq.nodeProperties(
        properties="Interfaces").answer().frame()

    print(node_properties_trunc)

    print("---------")
    print(bfq.undefinedReferences().answer().frame())

    print("layer1Edges")
    print("----------------------")
    print(bfq.layer1Edges().answer().frame())
    print("LAYER3_EDGES")
    print("----------------------")
    print(bfq.layer3Edges().answer().frame())
    print("----------------------")

    print(bfq.undefinedReferences().answer().frame())

    # Get edges of type layer 3 (IP layer)
    print(bfq.edges(edgeType="layer3").answer().frame())
예제 #4
0
print("#"*100)
print("Detect forwarding loops.")
print("#"*100)
print(bfq.detectLoops().answer().frame())

# List edges types
print("#"*100)
print("Lists neighbor relationships of the specified type (layer3, BGP, ospf, etc. in the form of edges).")
print("#"*100)
print(bfq.edges().answer().frame())

# File parse status
print("#"*100)
print("For each file in a snapshot, returns the host(s) that were produced by the file and the parse status: pass, fail, partially parsed.")
print("#"*100)
print(bfq.fileParseStatus().answer().frame())

# IP Interfaces
print("#"*100)
print("List IPs configured on interfaces")
print("#"*100)
ip_owners_ans = bfq.ipOwners().answer()
print(ip_owners_ans.frame())

# Traceroute !!
print("#"*100)
print("Traceroute ! The killer feature :-p")
print("#"*100)
print((bfq.traceroute(startLocation='arista', headers={"dstIps": "ofLocation(n9k)"}).answer()).frame())
print((bfq.traceroute(startLocation='n9k', headers={"dstIps": "ofLocation(arista)"}).answer()).frame())
#print((bfq.traceroute(startLocation='arista', headers={"dstIps": "ofLocation(arista)"}).answer()).frame())
예제 #5
0
def analyse_network(report_dir):
    """
    This function runs batfish questions and captures the query results into 
    a spread sheet.

    :param report_dir: defines the directory in which the analysis report gets 
                        saved
    """
    # Captures the status of the configurations that were Parsed.
    parse_status = bfq.fileParseStatus().answer().frame()
    # Batfish question to extract node properties
    print(Fore.YELLOW + " ==> GETTING NODE PROPERTIES")
    np = bfq.nodeProperties().answer().frame()
    # Batfish question to extract interface properties
    print(Fore.YELLOW + " ==> GETTING INTERFACE PROPERTIES")
    interface = bfq.interfaceProperties().answer().frame()
    # Batfish question to extract VLAN properties
    print(Fore.YELLOW + " ==> GETTING VLAN PROPERTIES")
    vlan_prop = bfq.switchedVlanProperties().answer().frame()
    # Batfish question to extract IP Owners
    print(Fore.YELLOW + " ==> GETTING IPOWNERS")
    ip_owners = bfq.ipOwners().answer().frame()
    # Batfish question to extract L3 edges
    print(Fore.YELLOW + " ==> GETTING L3 EDGES")
    l3edge = bfq.layer3Edges().answer().frame()
    # Batfish question to extract MPLAG properties
    print(Fore.YELLOW + " ==> GETTING MLAG PROPERTIES")
    mlag = bfq.mlagProperties().answer().frame()
    # Batfish question to extract OSPF configuration
    print(Fore.YELLOW + " ==> GETTING OSPF CONFIGURATION")
    ospf_config = bfq.ospfProcessConfiguration().answer().frame()
    # Batfish question to extract OSPF area configuration
    print(Fore.YELLOW + " ==> GETTING OSPF AREA CONFIGURATION")
    ospf_area_config = bfq.ospfAreaConfiguration().answer().frame()
    # Batfish question to extract OSPF interface configuration
    print(Fore.YELLOW + " ==> GETTING OSPF INTERFACE CONFIGURATION")
    ospf_interface = bfq.ospfInterfaceConfiguration().answer().frame()
    # Batfish question to extract OSPF Session compatability
    print(Fore.YELLOW + " ==> GETTING OSPF SESSION COMPATABILITY")
    ospf_session = bfq.ospfSessionCompatibility().answer().frame()
    # Batfish question to extract BGP configuration
    print(Fore.YELLOW + " ==> GETTING BGP CONFIGURATION")
    bgp_config = bfq.bgpProcessConfiguration().answer().frame()
    # Batfish question to extract BGP peer configuration
    print(Fore.YELLOW + " ==> GETTING BGP PEER CONFIGURATION")
    bgp_peer_config = bfq.bgpPeerConfiguration().answer().frame()
    # Batfish question to extract BGP session compatibility
    print(Fore.YELLOW + " ==> GETTING BGP SESSION COMPATIBILITY")
    bgp_session = bfq.bgpSessionStatus().answer().frame()
    # Batfish question to extract routing table
    print(Fore.YELLOW + " ==> GETTING ROUTE TABLE")
    routing = bfq.routes().answer().frame()
    # Batfish question to extract F5 VIP configuration
    print(Fore.YELLOW + " ==> GETTING F5 VIP CONFIGURATION")
    f5_vip = bfq.f5BigipVipConfiguration().answer().frame()
    # Batfish question to extract Named Structures
    print(Fore.YELLOW + " ==> GETTING NAMED STRUCTURES")
    named_structure = bfq.namedStructures().answer().frame()
    # Batfish question to extract Structure deginitions
    print(Fore.YELLOW + " ==> GETTING STRUCTURE DEFINITIONS")
    def_structure = bfq.definedStructures().answer().frame()
    # Batfish question to extract referenced structures
    print(Fore.YELLOW + " ==> GETTING REFERENCED STRUCTURES")
    ref_structure = bfq.referencedStructures().answer().frame()
    # Batfish question to extract undefined references
    print(Fore.YELLOW + " ==> GETTING UNDEFINED STRUCTURE REFERENCES")
    undefined_references = bfq.undefinedReferences().answer().frame()
    # Batfish question to extract used structures
    print(Fore.YELLOW + " ==> GETTING UNUSED STRUCTURES")
    unused_structure = bfq.unusedStructures().answer().frame()
    # Setting the path and file name were the analysis report will be saved
    analysis_report_file = report_dir + "/" + NETWORK_NAME + "_analysis_report.xlsx"
    print(Fore.YELLOW + " ==> GENERATING REPORT")
    # Writes previously computed configuration analysis into a excel file
    with pd.ExcelWriter(analysis_report_file) as f:
        parse_status.to_excel(f, sheet_name="parse_satus", engine="xlsxwriter")
        np.to_excel(f, sheet_name="node_properties", engine="xlsxwriter")
        interface.to_excel(f,
                           sheet_name="interface_properties",
                           engine="xlsxwriter")
        vlan_prop.to_excel(f,
                           sheet_name="vlan_properties",
                           engine="xlsxwriter")
        ip_owners.to_excel(f, sheet_name="IPOwners", engine="xlsxwriter")
        l3edge.to_excel(f, sheet_name="l3edges", engine="xlsxwriter")
        mlag.to_excel(f, sheet_name="mlag", engine="xlsxwriter")
        ospf_session.to_excel(f,
                              sheet_name="ospf_session",
                              engine="xlsxwriter")
        ospf_config.to_excel(f, sheet_name="ospf_config", engine="xlsxwriter")
        ospf_area_config.to_excel(f,
                                  sheet_name="ospf_area_config",
                                  engine="xlsxwriter")
        ospf_interface.to_excel(f,
                                sheet_name="ospf_interface",
                                engine="xlsxwriter")
        bgp_config.to_excel(f, sheet_name="bgp_config", engine="xlsxwriter")
        bgp_peer_config.to_excel(f,
                                 sheet_name="bgp_peer_config",
                                 engine="xlsxwriter")
        bgp_session.to_excel(f, sheet_name="bgp_session", engine="xlsxwriter")
        routing.to_excel(f, sheet_name="routing_table", engine="xlsxwriter")
        f5_vip.to_excel(f, sheet_name="f5_vip", engine="xlsxwriter")
        named_structure.to_excel(f,
                                 sheet_name="named_structure",
                                 engine="xlsxwriter")
        def_structure.to_excel(f,
                               sheet_name="defined_structures",
                               engine="xlsxwriter")
        ref_structure.to_excel(f,
                               sheet_name="referrenced_structures",
                               engine="xlsxwriter")
        undefined_references.to_excel(f,
                                      sheet_name="undefined_references",
                                      engine="xlsxwriter")
        unused_structure.to_excel(f,
                                  sheet_name="unused_structure",
                                  engine="xlsxwriter")