Пример #1
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
Пример #2
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")
Пример #3
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")
Пример #4
0
def select_from_dict(selected_dict, selection_type, default=""):
    print("\n")
    value = None
    key = None
    while value is None:
        try:
            for key in selected_dict.keys():
                print("- " + key)
            key = input("Please select a" + selection_type +
                        " from the list above: [" + default + "]\t") or default
            value = selected_dict[key]
        except KeyError:
            print("\n" + get_error_string("Please try again with these keys:"))
            value = None

    Map = collections.namedtuple('Map', ['key', 'value'])
    return Map(key, value)
Пример #5
0
def alter_config(m, alter_config_xml):
    # Thanks to Carl Moberg from Cisco:
    #  - code: https://github.com/cmoberg/netconf-yang-training/blob/master/example-csr1000v/08_cmd-add-mpls-lsp-full.py
    #  - slided: https://github.com/cmoberg/netconf-yang-training/tree/master/slides

    # Check if requirements are done. Otherwise enable candidate-datastore
    assert (":candidate" in m.server_capabilities)
    assert (":validate" in m.server_capabilities)

    # This is best practice to prevent simultaneously edit of the candidate storage.
    with m.locked(target="candidate"):
        m.discard_changes()
        m.edit_config(config=alter_config_xml, target="candidate")
        m.validate()
        res = m.commit()

        if "ok" in res.xml:
            print("\n" +
                  get_successful_string("Sucessfully altered the config"))
        else:
            print("\n" +
                  get_error_string("Error occured with the altering process"))
Пример #6
0
def check_connection(m):
    if not m.connected:
        print("\n\n" + get_error_string(
            "Connection was closed. You were not longer connected to the server"
        ))
        exit(1)