コード例 #1
0
def get_connection():
    parameters = connection_parameters.copy()
    print("\nThe default connection setup uses the PE switch " +
          get_bold_string(parameters["host"]) + ".")
    choice = input(
        "Would you like to setup your own connection: [N/y]\t") or "N"
    if choice == "y" or not is_netconf_socket_open(parameters.get("host"),
                                                   parameters.get("port")):

        parameters = clean_connection_parameters.copy()

        while is_a_parameter_none(parameters):
            parameters["host"] = input("Please enter the " +
                                       get_info_string("host") + ":\t") or None
            parameters["port"] = input("Please enter the " +
                                       get_info_string("port") + ":\t") or None
            parameters["username"] = input("Please enter the " +
                                           get_info_string("username") +
                                           ":\t") or None
            parameters["password"] = input("Please enter the " +
                                           get_info_string("password") +
                                           ":\t") or None

            if not is_netconf_socket_open(parameters.get("host"),
                                          parameters.get("port")):
                parameters = clean_connection_parameters.copy()

    return parameters
コード例 #2
0
def __get_bgp_delete_xml(filename):
    parameters = bgp_delete_parameters.copy()

    while is_a_parameter_none(parameters):
        parameters["as_id"] = input(
            "Please enter the current used " + get_info_string("local bgp as id") + ": \t") or None
        parameters["remote_id"] = input(
            "Please enter the " + get_info_string("remote id") + ": \t") or None

    return replace_variables_in_file(filename, parameters)
コード例 #3
0
def __get_vrf_delete_xml(filename):
    parameters = vrf_delete_parameters.copy()

    while is_a_parameter_none(parameters):
        parameters["name"] = input(
            "Please enter the " + get_info_string("name from the vrf") + " to delete: \t") or None
        parameters["as_id"] = input(
            "Please enter the current used " + get_info_string("local bgp as id") + " from the vrf: \t") or None

    return replace_variables_in_file(filename, parameters)
コード例 #4
0
def __get_vlan_add_xml(filename):
    parameters = vlan_add_parameters.copy()

    while is_a_parameter_none(parameters):
        parameters["vlan_id"] = input(
            "Please enter the  " + get_info_string("vlan id") + " from the vlan: \t") or None
        parameters["vrf_name"] = input(
            "Please enter the " + get_info_string("vrf name") + ": \t") or None

    return replace_variables_in_file(filename, parameters)
コード例 #5
0
def __get_bgp_add_xml(filename):
    parameters = bgp_add_parameters.copy()

    while is_a_parameter_none(parameters):
        parameters["as_id"] = input(
            "Please enter the " + get_info_string("local as id") + " from the router: \t") or None
        parameters["remote_id"] = input(
            "Please enter the " + get_info_string("remote id") + " from the other bgp router: \t") or None
        parameters["remote_as"] = input(
            "Please enter the " + get_info_string("remote as id") + " from the other bgp router: \t") or None

    return replace_variables_in_file(filename, parameters)
コード例 #6
0
def __get_vlan_delete_xml(filename):
    parameters = vlan_delete_parameters.copy()

    while is_a_parameter_none(parameters):
        parameters["vlan_id"] = input("Please enter the " + get_info_string("vlan id") + " to delete: \t") or None

    return replace_variables_in_file(filename, parameters)
コード例 #7
0
def alter_second_router(alter_type):
    alter_now = input("Would you like to do that now. [Y/n]") or "Y"
    if alter_now != "Y":
        return

    print(
        get_info_string(
            "OK, please enter the new connection parameters to continue:"))
    connection_parameters = get_connection()
    m2 = generate_connection(connection_parameters)

    print(
        get_info_string("Now enter the parameters to " + alter_type +
                        " the remote bgp connection:"))

    if alter_type is "add":
        alter_config_map = get_bgp_neighbor_add_config()
    else:
        alter_config_map = get_bgp_neighbor_delete_config()

    alter_config(m2, alter_config_map.xml)
    print(get_info_string("Closing connection from external router"))
    m2.close_session()
コード例 #8
0
def is_netconf_socket_open(ip, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        if ip is None or port is None:
            return False

        s.connect((ip, int(port)))
        s.shutdown(2)
        print("\n" + get_info_string(
            "Socket is open. Try to connect with given credentials..."))
        return True
    except socket.gaierror:
        print("\n" + get_error_string(
            "No connection to the system possible. Please try again."))
        return False
コード例 #9
0
def delete_xml_config(m, socket_string):
    delete_config = get_delete_configs()

    if delete_config.key is not None:
        alter_config(m, delete_config.xml)
    else:
        print(get_error_string("Nothing selected"))
        return

    if delete_config.key == "bgp":
        print(
            "\nYou have deleted the bgp neighborship from this router. Now you "
            + get_info_string("could switch to another router") +
            " to delete the neighborship there as well.")
        alter_second_router("delete")
コード例 #10
0
def add_xml_config(m, socket_string):
    add_config = get_add_configs()

    if add_config.key is not None:
        alter_config(m, add_config.xml)
    else:
        print(get_error_string("Nothing selected"))
        return

    if add_config.key == "bgp":
        print(
            "\nYou have added a new bgp neighborship to this router. Now you "
            + get_info_string("could switch to another router") +
            " to create the neighborship there as well.")
        print_connection(socket_string)
        alter_second_router("add")
コード例 #11
0
def get_delete_configs():
    print("\n\n" +
          get_info_string(
              "Note to delete the vlan first if you'd like to delete a vrf with a newly created vlan for it"))
    config_file = select_from_dict(delete_xml_files, " delete config file")
    Map = collections.namedtuple('Map', ['key', 'xml'])

    if config_file.key == "bgp":
        return Map("bgp", __get_bgp_delete_xml(config_file.value))

    if config_file.key == "vlanWithVrf":
        return Map("vlanWithVrf", __get_vlan_delete_xml(config_file.value))

    if config_file.key == "vrf":
        return Map("vrf", __get_vrf_delete_xml(config_file.value))

    return Map(None, None)
コード例 #12
0
def __get_vrf_add_xml(filename):
    parameters = vrf_add_parameters.copy()

    while is_a_parameter_none(parameters):
        parameters["name"] = input(
            "Please enter the " + get_info_string("name from the vrf") + ": \t") or None
        parameters["rd_address"] = input(
            "Please enter the " + get_info_string("rd address") + ": \t") or None
        parameters["rd_port"] = input(
            "Please enter the " + get_info_string("rd port") + ": \t") or None
        parameters["asn_address"] = input(
            "Please enter the " + get_info_string("route-target export address") + ": \t") or None
        parameters["asn_port"] = input(
            "Please enter the " + get_info_string("route-arget export port") + ": \t") or None
        parameters["as_id"] = input(
            "Please enter the " + get_info_string("local bgp as id") + ": \t") or None

    return replace_variables_in_file(filename, parameters)
コード例 #13
0
def check_and_close_connection(m):
    if m.connected:
        m.close_session()
        if not m.connected:
            print("\n\n" + get_info_string("Session closed."))