Exemplo n.º 1
0
from pprint import pprint
from napalm import get_network_driver
from my_devices import nxos1
from my_functions import create_con,create_checkpoint
 
nxos1_con = create_con(nxos1)

create_checkpoint(nxos1_con)

print("Open connection")
nxos1_con.open()
print("Load the change:")
nxos1_con.load_replace_candidate(filename="nxos1.conf.new")
print("Config diff:")
print(nxos1_con.compare_config())
print("Discard the change")
nxos1_con.discard_config()
print("Config diff:")
print(nxos1_con.compare_config())
print("Close connection")
nxos1_con.close()
Exemplo n.º 2
0
from my_devices import nxos1
from pprint import pprint
from my_functions import connection, create_checkpoint


if __name__ == "__main__":
 connect = connection(nxos1)
 create_checkpoint(connect)
 connect.load_replace_candidate("nxos1.lasthop.io-cfg_NEW.txt")
 print(connect.compare_config())
 connect.discard_config()
 connect.close()
Exemplo n.º 3
0
from my_functions import napalm_connect, create_checkpoint
from my_devices import nxos1
from pprint import pprint

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

NXOS_REPLACE_CANDIDATE = "nxos1_replacement_cfg"

if __name__ == "__main__":
    conn = napalm_connect(nxos1)
    create_checkpoint(conn)
    conn.load_replace_candidate(NXOS_REPLACE_CANDIDATE)
    print("config staged {}".format(conn.hostname))
    print(conn.compare_config())
    print("Dsicarding candidate config {}".format(conn.hostname))
    conn.discard_config()
    print("Difference after discard candidate config {}".format(conn.hostname))
    print(conn.compare_config())
    print("\n\n")
    conn.close()

#This program will do a full configuration replace on the nxos1 device, changing the state of the device all at once

#This is needed just to get the error to handle because the device is using an unsigned certificate
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

NXOS_REPLACE_CANDIDATE_FILE = "nxos1_replacement_cfg"

if __name__ == "__main__":
    connection_handle = open_napalm_connection(nxos1)

    # Checkpoint the currently existing config so that we can roll back

    create_checkpoint(connection_handle)

    connection_handle.load_replace_candidate(NXOS_REPLACE_CANDIDATE_FILE)

    print("Replacement config staged, diff between existing and new config follows for {}".format(connection_handle.hostname))

    print(connection_handle.compare_config())

    #Don't actually apply any changes(!)

    print("Discarding the config changes for {}".format(connection_handle.hostname))

    connection_handle.discard_config()

    print("Diff of changes after discarding the proposed changes (should be none) for {}".format(connection_handle.hostname))
Exemplo n.º 5
0
#!/usr/bin/env python3
from pprint import pprint
from my_devices import cisco3, arista1, nxos1
from my_functions import open_napalm_connection, create_backup, create_checkpoint
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

my_nxos1_device = open_napalm_connection(nxos1)

print(my_nxos1_device)
# 4b
create_checkpoint(my_nxos1_device)

# 4c, file nxos1.config, added "int lo130"
## interface loopback130
##   description loopback130
##   !#no shutdown
nxos1_config_file = "nxos1.full_config"

# 4d
my_nxos1_device.open()
my_nxos1_device.load_replace_candidate(filename=nxos1_config_file)

print("Compare config:")
print(my_nxos1_device.compare_config())

print("Discarding candidate config:")
my_nxos1_device.discard_config()
Exemplo n.º 6
0
from my_devices import nxos1
from my_functions import get_device, create_checkpoint

device = get_device(nxos1)

create_checkpoint(device)
Exemplo n.º 7
0
4a. Add nxos1 to your my_devices.py file. Ensure that you include the necessary information to set the NX-API port to 8443. This is done using 'optional_args' in NAPALM so you should have the following key-value pair defined: 

"optional_args": {"port": 8443}

4b. Create a new function named 'create_checkpoint'. Add this function into your my_functions.py file. This function should take one argument, the NAPALM connection object. This function should use the NAPALM _get_checkpoint_file() method to retrieve a checkpoint from the NX-OS device. It should then write this checkpoint out to a file.

Recall that the NX-OS platform requires a 'checkpoint' file for configuration replace operations. Using this new function, retrieve a checkpoint from nxos1 and write it to the local file system.

4c. Manually copy the saved checkpoint to a new file and add an additional loopback interface to the configuration.

4d. Create a Python script that stages a complete configuration replace operation (using the checkpoint file that you just retrieved and modified). Once your candidate configuration is staged perform a compare_config (diff) on the configuration to see your pending changes. After the compare_config is complete, then use the discard_config() method to eliminate the pending changes. Next, perform an additional compare_config (diff) to verify that you have no pending configuration changes. Do not actually perform the commit_config as part of this exercise.
"""
from my_devices import nxos1
from napalm import get_network_driver
from pprint import pprint
from my_functions import napalm_connect, create_checkpoint

#4b
connection = napalm_connect(nxos1)
create_checkpoint(connection)

#4d
filename = f"{connection.hostname}.config.txt"
connection.load_replace_candidate(filename)
print("Config Diff:")
print(connection.compare_config())
connection.discard_config()
print("Config Diff Post Discard:")
print(connection.compare_config())
Exemplo n.º 8
0
    nxos1 = my_devices.nxos1
    nxos1_hostname = nxos1['hostname']

    device_conn = napalm_conn(nxos1)

    print("#" * 50)
    print(f"Printing {nxos1_hostname} napalm connection: ")
    print("#" * 50)

    print(device_conn)

    # Creating the nxos checkpoint file

    filename = f"{nxos1_hostname}_checkpoint"

    checkpoint = create_checkpoint(device_conn, filename)

    # Napalm Config Replace staging

    device_conn.load_replace_candidate(filename=f"{nxos1_hostname}_config")

    print("#" * 50)
    print(
        f"Printing {nxos1_hostname} DIFFS candidate vs running before commiting: "
    )
    print("#" * 50)
    print(device_conn.compare_config())

    device_conn.discard_config()

    print("#" * 50)