コード例 #1
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
コード例 #2
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
コード例 #3
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
コード例 #4
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)
コード例 #5
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
コード例 #6
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