Ejemplo n.º 1
0
def main():
    routers_yaml = my_funcs.read_yaml(PATH + FILE)
    for router in routers_yaml:
        router["password"] = password

    device_conn = pyeapi.client.connect(**routers_yaml[0])
    device_node = pyeapi.client.Node(device_conn)
    show_arp = device_node.enable("show ip arp")

    my_funcs.print_arp(show_arp)
Ejemplo n.º 2
0
def main():
    routers = my_funcs.read_yaml(PATH + YAML_FILE)
    # update router's details with password
    for device in routers:
        device["password"] = password
        # we shold do action with aristat4, so that assigned connection details
        if device["host"] == "arista4.lasthop.io":
            device_conn = pyeapi.client.connect(**device)

    device_node = pyeapi.client.Node(device_conn)
    show_route = device_node.enable("show ip route")
    # parse routes and print
    route_table = show_route[0]["result"]["vrfs"]["default"]["routes"]
    ipdb.set_trace()
    for route, route_details in route_table.items():
        if route_details["directlyConnected"]:
            print(f'{route}\t\t directly connected')
        if route_details["routeType"] == "static":
            print(
                f'{route}\t\t static \t\t{route_details["vias"][0]["nexthopAddr"]}'
            )
Ejemplo n.º 3
0
import pyeapi
import yaml
import my_funcs
from getpass import getpass

password = getpass()
device_dict = my_funcs.read_yaml(password)

connection = pyeapi.client.connect(**device_dict)
device = pyeapi.client.Node(connection)
output = device.enable("show ip arp")
arp_list = output[0]['result']['ipV4Neighbors']

my_funcs.out_yaml(arp_list)
Ejemplo n.º 4
0
#!/usr/bin/env python
"""
3. Using your external YAML file and your function located in my_funcs.py, 
use pyeapi to connect to arista4.lasthop.io and retrieve "show ip route". 
From this routing table data, extract all of the static and connected routes from the default VRF. 
Print these routes to the screen and indicate whether the route is a connected route or a static route. 
In the case of a static route, print the next hop address.
"""

from pprint import pprint
from my_funcs import read_yaml, arp_output
import pyeapi
import json
from pprint import pprint

data = read_yaml("inventory.yaml")

for k in data:
    if k == "arista4":
        connection = pyeapi.client.connect(**data[k])

device = pyeapi.client.Node(connection)

output = device.enable("show ip route")

default_rib = output[0]["result"]["vrfs"]["default"]["routes"]

for route in default_rib:
    if default_rib[route]["routeType"] == "static":
        next_hop = default_rib[route]["vias"][0]["nexthopAddr"]
        print(f"{route} via Next Hop: {next_hop} ======> static route")
Ejemplo n.º 5
0
import pyeapi
from pprint import pprint
import yaml
from my_funcs import read_yaml
from jinja2 import FileSystemLoader, StrictUndefined
from jinja2.environment import Environment

yaml_devices = read_yaml("devices.yaml")

env = Environment(undefined=StrictUndefined)
env.loader = FileSystemLoader('.')

template_file = 'ex4.j2'
template = env.get_template(template_file)

arista_devs = yaml_devices.keys()

for elem in arista_devs:
    arista_output = template.render(**yaml_devices[elem]["data"])
    cmds = arista_output.splitlines()
    
    connection = pyeapi.client.connect(**yaml_devices[elem])
    device = pyeapi.client.Node(connection)
    device.config(cmds)
    output = device.enable("show ip interface brief")
    pprint(output)

Ejemplo n.º 6
0
import pyeapi
from pprint import pprint
import yaml
from my_funcs import read_yaml, print_out

yaml_device = read_yaml("device.yaml")

connection = pyeapi.client.connect(**yaml_device)
device = pyeapi.client.Node(connection)
output = device.enable("show ip arp")

print_out(output)
Ejemplo n.º 7
0
Use pyeapi to push this configuration to the four Arista switches. 
Use pyeapi and "show ip interface brief" to display the IP address table after the configuration changes have been made.
"""

from pprint import pprint
from my_funcs import read_yaml, arp_output
import pyeapi
import json
from jinja2 import FileSystemLoader, StrictUndefined
from jinja2.environment import Environment
from pprint import pprint

env = Environment(undefined=StrictUndefined)
env.loader = FileSystemLoader('.')

data = read_yaml("arista_hosts.yaml")

for k in data:
    intf_vars = dict()
    intf_vars["intf_name"] = data[k]["data"]["intf_name"]
    intf_vars["intf_ip"] = data[k]["data"]["intf_ip"]
    intf_vars["intf_mask"] = data[k]["data"]["intf_mask"]

    template_file = "arista_intf.j2"
    template = env.get_template(template_file)
    intf_config = template.render(**intf_vars)
    intf_config = intf_config.splitlines()
    pprint(intf_config)

    connection = pyeapi.client.connect(**data[k])
    device = pyeapi.client.Node(connection)