Exemplo n.º 1
0
def set_chaos_trace_graph(source, destination, submit, choose_node,
                          deactivate_node, deactivated_interface, src_ports,
                          dst_ports, applications, ip_protocols,
                          change_configuration_switch, host_value,
                          network_value, snapshot_value):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]
    deactivated_nodes = []
    deactivated_interfaces = []

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

    src_ports = src_ports.split(',') if src_ports else None
    dst_ports = dst_ports.split(',') if dst_ports else None
    applications = applications.split(',') if applications else None
    ip_protocols = ip_protocols.split(',') if ip_protocols else None
    batfish = Batfish(host_value)
    batfish.set_network(network_value)

    bidir = False
    if change_configuration_switch:
        reference_snapshot = snapshot_value + "_CHANGED"
        batfish.init_snapshot(reference_snapshot)
    else:
        reference_snapshot = snapshot_value + "_FAIL"
        deactivated_nodes.append(choose_node)
        if not deactivate_node:
            deactivated_interfaces.append(deactivated_interface)
        batfish.network_failure(snapshot_value, reference_snapshot,
                                deactivated_nodes, deactivated_interfaces)

    result = batfish.traceroute(source, destination, bidir, reference_snapshot,
                                src_ports, dst_ports, applications,
                                ip_protocols)
    chaos_flow_details = get_traceroute_details('forward', result, False, True)
    chaos_flow_graph = chaos_flow_details[0]
    chaos_flow_traces = chaos_flow_details[1]
    delete_old_files()

    return chaos_flow_graph, chaos_flow_traces
Exemplo n.º 2
0
def create_snapshot_modal(
        device_configs_upload_content, host_configs_upload_content,
        iptables_configs_upload_content, aws_configs_upload_content,
        misc_configs_upload_content, batfish_network, submit, snapshot_name,
        device_config_filenames, host_config_filenames,
        iptables_config_filenames, aws_config_filenames, misc_config_filenames,
        batfish_host):
    device_html_list = None
    host_html_list = None
    iptable_html_list = None
    aws_html_list = None
    misc_html_list = None

    if device_config_filenames is not None:
        device_html_list = html.Ul(
            [html.Li(x) for x in device_config_filenames])
    if host_config_filenames is not None:
        host_html_list = html.Ul([html.Li(x) for x in host_config_filenames])
    if iptables_config_filenames is not None:
        iptable_html_list = html.Ul(
            [html.Li(x) for x in iptables_config_filenames])
    if aws_config_filenames is not None:
        aws_html_list = html.Ul([html.Li(x) for x in aws_config_filenames])
    if misc_config_filenames is not None:
        misc_html_list = html.Ul([html.Li(x) for x in misc_config_filenames])

    all_children = html.Div([
        html.Ul(children=[
            html.Li(['Device Configs', device_html_list]),
            html.Li(['Host Configs', host_html_list]),
            html.Li(['IP Table Configs', iptable_html_list]),
            html.Li(['AWS Configs', aws_html_list]),
            html.Li(['Misc Configs', misc_html_list]),
        ], )
    ])
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if not batfish_network:
        raise PreventUpdate

    if button_id == "create_snapshot_submit_button":
        if snapshot_name == "":
            return all_children, True
        if device_config_filenames is not None:
            for name, data in zip(device_config_filenames,
                                  device_configs_upload_content):
                save_file("device_config", name, data)
        if host_config_filenames is not None:
            for name, data in zip(host_config_filenames,
                                  host_configs_upload_content):
                save_file("host_config", name, data)
        if iptables_config_filenames is not None:
            for name, data in zip(iptables_config_filenames,
                                  iptables_configs_upload_content):
                save_file("iptable_config", name, data)
        if aws_config_filenames is not None:
            for name, data in zip(aws_config_filenames,
                                  aws_configs_upload_content):
                save_file("aws_config", name, data)
        if misc_config_filenames is not None:
            for name, data in zip(misc_config_filenames,
                                  misc_configs_upload_content):
                save_file("misc_config", name, data)
        batfish = Batfish(batfish_host)
        batfish.set_network(batfish_network)
        batfish.init_snapshot(snapshot_name)
        delete_old_files()
        device_html_list = None
        host_html_list = None
        iptable_html_list = None
        aws_html_list = None
        misc_html_list = None

        all_children = html.Div([
            html.Ul(children=[
                html.Li(['Device Configs', device_html_list]),
                html.Li(['Host Configs', host_html_list]),
                html.Li(['IP Table Configs', iptable_html_list]),
                html.Li(['AWS Configs', aws_html_list]),
                html.Li(['Misc Configs', misc_html_list]),
            ], )
        ])
        return all_children, False
    return all_children, False