示例#1
0
def main():

    arp_ntp()
    print("\n")
    print("Creating Backup")
    print("-" * 20)
    create_backup(connection_objects)
示例#2
0
from my_functions import napalm_connect, create_backup
from my_devices import device_list
from pprint import pprint

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

#requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

if __name__ == "__main__":
    connection = []
    for device in device_list:
        conn = napalm_connect(device)
        connection.append(conn)
    for conn in connection:
        output = conn.get_arp_table()
        pprint(output)
    for conn in connection:
        try:
            pprint(conn.get_ntp_peers())
        except NotImplementedError:
            print("NTP peers not implemented for this device {}".format(
                conn.platform))
    for conn in connection:
        create_backup(conn)
        conn.close()
    print("\n\n")
示例#3
0
# Exercise 2b
for device in napalm_objects:
    hostname = device.hostname
    print("\n")
    print(f"{hostname}'s ARP Table:")
    print("-" * 40)
    pprint(device.get_arp_table())

print("=" * 40)

# Exercise 2b
for device in napalm_objects:
    hostname = device.hostname
    print()
    print(f"NTP Peers of {hostname}: ")
    try:
        output = device.get_ntp_peers()
        print(output)
    except:
        print("Unable to gather NTP peers!")

print("=" * 40)

# Exercise 2c
for device in napalm_objects:
    print(f"Creating backup for {device.hostname}...")
    create_backup(device)

print()
示例#4
0
from my_functions import open_napalm_connection, create_backup

my_device_conn_objects = []

my_cisco3_device = open_napalm_connection(cisco3)
my_device_conn_objects.append(my_cisco3_device)

my_arista1_device = open_napalm_connection(arista1)
my_device_conn_objects.append(my_arista1_device)

for my_device_conn_object in my_device_conn_objects:
    # 2a
    print("Napalm connection object: ")
    print(my_device_conn_object)
    print()
    my_device_conn_object.open()
    # 2b get arp table
    print("Get arp table: ")
    pprint(my_device_conn_object.get_arp_table())
    print()
    # 2c get ntp peers
    print("Get NTP peers: ")
    try:
        print("NTP peers: {}".format(my_device_conn_object.get_ntp_peers()))
    except NotImplementedError:
        print("Command not implemented")
        print()
# 2d create backup
    create_backup(my_device_conn_object)
    print()
示例#5
0
from pprint import pprint
from napalm import get_network_driver
from my_devices import cisco3, nxos1, arista1
from my_functions import open_napalm_connection, create_backup
import ipdb

# Supress SSL Certificate Warnings
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

if __name__ == "__main__":

    spacer = ('-' * 80)
    devices = [cisco3, arista1]
    conn_obj_list = list()

    for device in devices:
        #ipdb.set_trace()
        conn_obj_list.append(open_napalm_connection(device))

    for obj in conn_obj_list:
        #ipdb.set_trace()
        print('\n')
        print('Backing up - ' + obj.get_facts()['hostname'])
        print(spacer)
        pprint(create_backup(obj))
        print(spacer + '\n' + spacer)

#    ipdb.set_trace()
示例#6
0
            print("#" * 50)
            print(f"Printing {device['hostname']} ntp peers: ")
            print("#" * 50)
            pprint(ntp_output)

        except NotImplementedError:

            print("#" * 50)
            print(
                f"{device['hostname']} does not support 'get_ntp_peers' getter"
            )
            print("#" * 50)

        # Create and backing up running config

        running_conf = create_backup(device_conn)['running']

        print("#" * 50)
        print(f"Printing {device['hostname']} running config: ")
        print("#" * 50)

        pprint(running_conf)

        filename = f"{device['hostname']}_config"

        with open(filename, "w") as f:
            f.write(running_conf)

        device_conn.close()
#!/usr/bin/env/python

from pprint import pprint
from my_devices import network_devices
from my_functions import open_napalm_connection, create_backup

if __name__ == "__main__":
    connections = []
    for device in network_devices:
        connection = open_napalm_connection(device)
        connections.append(connection)

    print("Printing the ARP table of all the devices")

    for connection in connections:
        pprint(connection.get_arp_table())

    print("Now print NTP peers if any")

    for connection in connections:
        try:
            pprint(connection.get_ntp_peers())
        except NotImplementedError:
            print("NTP peers not available on the platform {}".format(
                connection.platform))

    print("Make a backup of the running configurations")
    for connection in connections:
        create_backup(connection)
        connection.close()
示例#8
0
文件: 2.py 项目: bartd20/napalm
con_list = []

arista = create_con(arista1)
con_list.append(arista)

cisco =  create_con(cisco3)
con_list.append(cisco)

for elem in con_list:
    elem.open()
    print("Platform: "+elem.platform)
    print("Arp table:")
    pprint(elem.get_arp_table())
    print("----------")
    elem.close()

for elem in con_list:
    elem.open()
    print("Platform: "+elem.platform)
    print("NTP peers:")
    try:
        print(elem.get_ntp_peers())
    except Exception:
        print("Error")
    print("-----------")
    elem.close()

create_backup(cisco)
create_backup(arista)
示例#9
0
from my_devices import cisco3, eos1
from pprint import pprint
from my_functions import connection, create_backup

conn_list = [connection(cisco3), connection(eos1)]

for element in conn_list:

    print("The object is: ")
    print(element)
    print('-' * 20)
    print("The ARP table: ")
    pprint(element.get_arp_table())
    print('-' * 20)
    print("The NTP peers: ")

    try:
        pprint(element.get_ntp_peers())
    except:
        print('Some Error is occured')

    create_backup(element)

    element.close()

    print('#' * 100)