Exemplo n.º 1
0
def set_change_configuration(changed_configuration,
                             changed_configuration_submit,
                             chaos_traceroute_submit, choose_node,
                             batfish_host, batfish_network, batfish_snapshot):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id not in [
            "change_configuration_submit", "chaos_traceroute_submit"
    ]:
        raise PreventUpdate
    if button_id == "chaos_traceroute_submit":
        return False

    batfish = Batfish(batfish_host)
    batfish.set_network(batfish_network)
    batfish.set_snapshot(batfish_snapshot)

    with open(r"assets\snapshot_holder\configs\\" + choose_node + ".txt",
              'w') as f:
        f.write(changed_configuration)

    nodes_df = batfish.get_info('fileParseStatus')
    for key, value in nodes_df.iterrows():
        if choose_node.lower() not in value['Nodes']:
            with open(
                    r"assets\snapshot_holder\configs\\" + value['Nodes'][0] +
                    ".txt", 'w') as f:
                f.write(
                    batfish.get_configuration(value['File_Name'],
                                              batfish_snapshot))
    return True
Exemplo n.º 2
0
def display_interfaces_for_node(choose_node, batfish_host, batfish_network,
                                original_snapshot):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "traceroute_deactivate_node":
        raise PreventUpdate

    batfish = Batfish(batfish_host)
    batfish.set_network(batfish_network)
    batfish.set_snapshot(original_snapshot)

    batfish_df = batfish.get_info("nodeProperties")
    batfish_df = batfish_df.set_index('Node')

    interfaces = batfish_df.loc[choose_node].at['Interfaces']

    interfaces_dict = [{'label': '', 'value': ''}]

    interfaces_dict += [{
        'label': interface,
        'value': interface
    } for interface in interfaces]
    options = interfaces_dict
    return options
Exemplo n.º 3
0
def set_dst_type_input(dst_type, host_value, network_value, snapshot_value):
    if not dst_type:
        raise PreventUpdate

    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    batfish.set_snapshot(snapshot_value)

    if dst_type == 'Interface':
        batfish_df = batfish.get_layer3_edges
        options = [str(x) for x in batfish_df["Interface"]]
        interfaces = [{
            'label': interface,
            'value': interface
        } for interface in options]

        children = dcc.Dropdown(
            id="traceroute_dst",
            placeholder='Select Destination',
            options=interfaces,
        )
    else:

        children = dcc.Input(id="traceroute_dst",
                             type="text",
                             placeholder="Input IP Address",
                             className="traceroute_dst_ip_input",
                             style=dict(borderTopLeftRadius="0px",
                                        borderBottomLeftRadius="0px",
                                        height="36px")),

    return children
Exemplo n.º 4
0
def get_acl_configuration_modal(n, batfish_host, batfish_network,
                                batfish_snapshot):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "acl_get_config_button":
        raise PreventUpdate

    batfish = Batfish(batfish_host)
    batfish.set_network(batfish_network)
    batfish.set_snapshot(batfish_snapshot)
    nodes_df = batfish.get_info('nodeProperties')
    options = [{'label': node, 'value': node} for node in nodes_df['Node']]
    return options
Exemplo n.º 5
0
def get_change_configuration(choose_node, batfish_host, batfish_network,
                             batfish_snapshot):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "acl_choose_node":
        raise PreventUpdate

    batfish = Batfish(batfish_host)
    batfish.set_network(batfish_network)
    batfish.set_snapshot(batfish_snapshot)
    nodes_df = batfish.get_info('fileParseStatus')
    for key, value in nodes_df.iterrows():
        if choose_node.lower() in value['Nodes']:
            return batfish.get_configuration(value['File_Name'],
                                             batfish_snapshot)
Exemplo n.º 6
0
def set_update_tab_content(content_type, snapshot_value, host_value,
                           network_value):
    if not snapshot_value:
        raise PreventUpdate
    time.sleep(.05)
    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    batfish.set_snapshot(snapshot_value)

    tab_content = {
        'layer3': get_layer3_graph(batfish.get_layer3_edges),
        'ospf': get_ospf_graph(batfish.get_ospf_edges),
        'bgp': get_bgp_graph(batfish.get_bgp_edges),
        'traceroute': get_traceroute_content(batfish.get_layer3_edges),
        'all_things_acl': get_acl_content()
    }
    return tab_content.get(content_type)
Exemplo n.º 7
0
def acl_table(original_platform, original_acl, refractored_platform,
              refractored_acl, submit, host_value, network_value,
              snapshot_value):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "acl_analyze_button":
        raise PreventUpdate
    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    batfish.set_snapshot(snapshot_value)
    compare_acl_df = batfish.compare_acls(original_acl, refractored_acl,
                                          original_platform,
                                          refractored_platform)
    batfish.delete_snapshot("refractored")
    batfish.delete_snapshot("original")
    children = dash_table.DataTable(id='table',
                                    columns=[{
                                        "name": i,
                                        "id": i,
                                        "deletable": True
                                    } for i in compare_acl_df.columns],
                                    data=compare_acl_df.to_dict('records'),
                                    filter_action="native",
                                    style_cell={
                                        'fontSize': 12,
                                        'font-family': 'sans-serif'
                                    },
                                    style_data_conditional=[{
                                        'if': {
                                            'row_index': 'odd'
                                        },
                                        'backgroundColor':
                                        'rgb(248, 248, 248)'
                                    }],
                                    style_header={
                                        'backgroundColor':
                                        'rgb(230, 230, 230)',
                                        'fontWeight': 'bold'
                                    })
    return children
Exemplo n.º 8
0
def ask_a_question_modal_table(question, host_value, network_value,
                               snapshot_value):
    if question is None:
        raise PreventUpdate
    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    batfish.set_snapshot(snapshot_value)
    batfish_df = batfish.get_info(question)
    batfish_df.to_csv('test.csv', index=False)
    new_df = pd.read_csv('test.csv')
    children = dash_table.DataTable(id='table',
                                    columns=[{
                                        "name": i,
                                        "id": i,
                                        "deletable": True
                                    } for i in batfish_df.columns],
                                    data=new_df.to_dict('records'),
                                    filter_action="native",
                                    export_format="csv",
                                    style_cell={
                                        'fontSize': 12,
                                        'font-family': 'sans-serif'
                                    },
                                    style_data_conditional=[{
                                        'if': {
                                            'row_index': 'odd'
                                        },
                                        'backgroundColor':
                                        'rgb(248, 248, 248)'
                                    }],
                                    style_header={
                                        'backgroundColor':
                                        'rgb(230, 230, 230)',
                                        'fontWeight': 'bold'
                                    })
    return children
Exemplo n.º 9
0
def get_chaos_form(n, graph_elements, batfish_host, batfish_network,
                   original_snapshot):

    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "traceroute_chaos_switch":
        raise PreventUpdate

    if not n:
        return None, None

    traceroute_nodes = []
    try:
        for traceroute_node in graph_elements:
            traceroute_nodes.append(traceroute_node['data']['label'])
    except KeyError:
        pass

    batfish = Batfish(batfish_host)
    batfish.set_network(batfish_network)
    batfish.set_snapshot(original_snapshot)

    batfish_df = batfish.get_info("nodeProperties")
    batfish_df = batfish_df.set_index('Node')

    nodes_dict = [{
        'label': node,
        'value': node
    } for node in set(traceroute_nodes)]
    node = nodes_dict[0]['value']
    interfaces = batfish_df.loc[node].at['Interfaces']

    interfaces_dict = [{'label': '', 'value': ''}]

    interfaces_dict += [{
        'label': interface,
        'value': interface
    } for interface in interfaces]

    form_children = [
        dbc.Col(children=[
            html.Fieldset(
                id="traceroute_source_fieldset",
                children=[
                    html.Legend("Choose Node"),
                    dbc.InputGroup([
                        dbc.Select(
                            id="traceroute_choose_node",
                            options=nodes_dict,
                            value=node,
                        ),
                    ]),
                ],
            ),
        ], ),
        dbc.Col(children=[
            html.Fieldset(
                id="traceroute_source_fieldset",
                children=[
                    html.Legend("Deactivate Node?"),
                    daq.BooleanSwitch(
                        id='deactivate_node_switch',
                        on=False,
                    ),
                ],
            ),
        ], ),
        dbc.Col(
            id="traceroute_deactivate_interface_col",
            children=[
                html.Fieldset(
                    id="traceroute_source_fieldset",
                    children=[
                        html.Legend("Deactivate Interface"),
                        dbc.InputGroup([
                            dbc.Select(
                                id="traceroute_deactivate_interface",
                                options=interfaces_dict,
                                value='',
                            ),
                        ]),
                    ],
                ),
            ],
        ),
        dbc.Col(children=[
            html.Div(
                dbc.Button("Change Configuration?",
                           id="chaos_traceroute_change_config_button")),
            daq.BooleanSwitch(id='change_configuration_switch',
                              on=False,
                              style={"display": "none"}),
        ]),
        dbc.Col(html.Div(dbc.Button("Chaos!",
                                    id="chaos_traceroute_submit")), ),
    ]

    fieldset_children = [
        html.Legend("Chaos Trace Route"),
        html.Div(id="chaos_traceroute_graph"),
        html.Div(dcc.Tabs(id="chaos_traceroute_tabs")),
    ]

    return form_children, fieldset_children