Example #1
0
def main():
    all_table = list()
    hosts = function1('ex2b.yml')
    for host in hosts:
        print("Connecting to...", host.get('host'))
        connection = pyeapi.client.connect(**host, password=getpass())
        device = pyeapi.client.Node(connection)
        output = device.enable(['show ip arp'])
        ip_table = function2(output)
        entry = (host.get('host').split('.')[0], ip_table)
        all_table.append(entry)
    pprint(all_table)
Example #2
0
def main():
    hosts = function1('ex4.yml')
    for host in hosts:
        cfg = function3(host.get('data'))
        print("Connecting to...", host.get('host'))
        connection = pyeapi.client.connect(**host, password=getpass())
        device = pyeapi.client.Node(connection)
        device.api('ipinterfaces').delete(host.get('data')['intf_name'])
        device.api('ipinterfaces').create(host.get('data')['intf_name'])
        device.api('ipinterfaces').set_address(
            host.get('data')['intf_name'],
            value=host.get('data')['intf_ip'] + '/' +
            str(host.get('data')['intf_mask']))
        intf_ip = device.enable('show ip interface brief')
        output = function2(intf_ip)
        pprint(output)
Example #3
0
"""
2b. Create a Python module named 'my_funcs.py'. In this file create two functions:
function1 should read the YAML file you created in exercise 2a and return the corresponding data structure;

function2 should handle the output printing of the ARP entries
(in other words, create a separate function that handles all printing to standard out of the 'show ip arp' data).

Create new program based on ex2a but YAML file loading and the output printing done using the functions in my_funcs.py
"""

from my_funcs import function1, function2
import pyeapi

if __name__ == '__main__':
    # call function which will read in yaml file and format it properly
    device_dict = function1('arista4.yaml')

    # Create connection object and pull in device details using **kwargs
    connection = pyeapi.client.connect(**device_dict)
    # Create client.node object and pass in the connection object created above
    device = pyeapi.client.Node(connection)
    # Send show ip arp command to device
    output = device.run_commands('show ip arp')
    # Call function 2 to deal with output of show ip arp command and print mappings
    function2(output)

Example #4
0
#!/usr/bin/env python
import pyeapi
from getpass import getpass
import yaml
import my_funcs

arista4_yaml_file = "arista4.yaml"

# read arista4 connection params from yaml config file
arista4_conn = my_funcs.function1(arista4_yaml_file)

connection = pyeapi.client.connect(**arista4_conn)
device = pyeapi.client.Node(connection)

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

# print output
my_funcs.function2(output)
Example #5
0
from jinja2.environment import Environment
from pprint import pprint

arista_yaml_file = "arista.yaml"

## jinja
loopback_j2_file = "loopback.j2"
env = Environment(undefined=StrictUndefined)
env.loader = FileSystemLoader('.')
template = env.get_template(loopback_j2_file)

## one password for all devices
arista_password = getpass()

## get arista settings from yaml file
arista_devs = my_funcs.function1(arista_yaml_file)

for device_name in arista_devs:
    print(device_name)

    ## settings for current device
    arista_conf = arista_devs[device_name]

    ## set password
    arista_conf['password'] = arista_password

    ## create loopback dict
    arista_loopback = arista_conf['loopback']
    print(arista_loopback)

    ## remove loopback part from dict