Example #1
0
def main():

    devices = yaml_load_devices()
    password = getpass()

    # Loop through each device, connect with passowrd and sh ip route.
    for name, device_dict in devices.items():
        device_dict["password"] = password  # add the password to device_dict
        connection = pyeapi.client.connect(**device_dict)
        device = pyeapi.client.Node(connection)
        output = device.enable("show ip route")
        # Pull out the dictionary contents
        route_list = output[0]["result"]["vrfs"]["default"]["routes"]

    for prefix, route_dict in route_list.items():
        route_type = route_dict["routeType"]
        print()
        print(prefix)
        print("-" * 12)
        print(route_type)
        print(">" * 6)
        print(route_dict["vias"][0]["interface"])
        if route_dict["routeType"] == "static":
            print(route_dict["vias"][0]["nexthopAddr"])
        print("-" * 12)
    print()
Example #2
0
def main():

    devices = yaml_load_devices()
    password = os.getenv("PYNET_PASSWORD") if os.getenv("PYNET_PASSWORD") else getpass()

    for name, device_dict in devices.items():
        device_dict["password"] = password
        connection = pyeapi.client.connect(**device_dict)
        device = pyeapi.client.Node(connection)
        output = device.enable("show ip arp")
        arp_list = output[0]["result"]["ipV4Neighbors"]
        output_printer(arp_list)
Example #3
0
def main():

    devices = yaml_load_devices()
    password = getpass()

    # Loop through each device, connect with passowrd and sh ip arp.
    for name, device_dict in devices.items():
        device_dict["password"] = password  # add the password to device_dict
        connection = pyeapi.client.connect(**device_dict)
        device = pyeapi.client.Node(connection)
        output = device.enable("show ip arp")
        # Pull out the dictionary contents
        arp_list = output[0]["result"]["ipV4Neighbors"]
        output_printer(name, arp_list)
Example #4
0
def main():

    password = getpass()
    env = Environment(undefined=StrictUndefined)
    env.loader = FileSystemLoader(".")
    template_file = "loopback_intf.j2"

    yaml_out = yaml_load_devices("arista_devices_full.yml")
    my_devices = yaml_out["my_devices"]  # Get the names from the yaml file

    eapi_devices = []
    for device_name in my_devices:  # for each named device
        device_dict = yaml_out[
            device_name]  # get the dictionary for each device
        device_dict["password"] = password  # add the password

        # Generate config from template
        j2_vars = device_dict.pop("data")  # pop off the data sub dictionary
        template = env.get_template(template_file)  # open the .j2 template
        cfg_lines = template.render(**j2_vars)  # render the device config
        cfg_lines = cfg_lines.strip()  # strip off any whitespace
        cfg_lines = cfg_lines.splitlines()  # split into lines

        # Establish eAP connection and push config
        eapi_conn = pyeapi.client.connect(**device_dict)
        device_obj = pyeapi.client.Node(eapi_conn)
        eapi_devices.append(device_obj)  # keep track of the devices
        output = device_obj.config(cfg_lines)  # push the config
        print(output)

    # Verify interfaces
    for device_obj in eapi_devices:  # for each switch
        output = device_obj.enable("show ip interface brief")
        print()
        print("-" * 50)
        print(output[0]["result"]["output"].rstrip())
        print("-" * 50)
    print()
import os
import pyeapi
from jinja2 import FileSystemLoader, StrictUndefined
from jinja2.environment import Environment
from getpass import getpass
from my_funcs import yaml_load_devices

if __name__ == "__main__":
    password = os.getenv("PYNET_PASSWORD") if os.getenv(
        "PYNET_PASSWORD") else getpass()

    env = Environment(undefined=StrictUndefined)
    env.loader = FileSystemLoader(".")
    template_file = "loopback_intf.j2"

    yaml_out = yaml_load_devices("arista_devices_full.yml")
    my_devices = yaml_out["my_devices"]

    eapi_devices = []
    for device_name in my_devices:
        device_dict = yaml_out[device_name]
        device_dict["password"] = password

        # Generate config from template
        j2_vars = device_dict.pop("data")
        template = env.get_template(template_file)
        cfg_lines = template.render(**j2_vars)
        cfg_lines = cfg_lines.strip()
        cfg_lines = cfg_lines.splitlines()

        # Establish eAP connection and push config
import pyeapi
from getpass import getpass
from my_funcs import yaml_load_devices

if __name__ == "__main__":
    password = getpass()


    devices = yaml_load_devices()

    for name, device_dict in devices.items():
        device_dict["password"] = password
        connection = pyeapi.client.connect(**device_dict)
        device = pyeapi.client.Node(connection)
        output = device.enable("show ip route")
        routes = output[0]["result"]["vrfs"]["default"]["routes"]

        print()
        for prefix, route_dict in routes.items():
            route_type = route_dict["routeType"]
            print()
            print(prefix)
            print("-" * 12)
            print(">" * 6, route_type)
            print(route_dict["vias"][0]["interface"])
            if route_type == "static":
                print(route_dict["vias"][0]["nexthopAddr"])
            print("-" * 12)

        print()