Пример #1
0
def BF_assert_no_unusedStructures(task: Task) -> Result:
    result = bfq.unusedStructures().answer()

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

    assert result['Summary']['numResults'] == 0, '\n' + pformat(result)
    return Result(host=task.host, result=result)
Пример #2
0
def test_config_sanity(isFailed):
    logging.info("Progress: Searching for unused and undefined data structures")
    # Find all undefined data structures
    undefined = bfq.undefinedReferences().answer().frame()
    if len(undefined) >  0:
        logging.error("Found undefined data structures")
        logging.error(undefined)
        isFailed = True
    else:
        logging.info("No undefined data structures found")

    # Find all unused data structures
    unused = bfq.unusedStructures().answer().frame()
    if len(unused) >  0:
        logging.error("Found unused data structures")
        logging.error(unused)
        isFailed = True
    else:
        logging.info("No unused data structures found")

    return isFailed
Пример #3
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")