コード例 #1
0
ファイル: ex2b.py プロジェクト: anejolazaro70/python_july19
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)
コード例 #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)
コード例 #3
0
ファイル: week6ex2b.py プロジェクト: suhaibasaeed/PyNet-Plus
"""
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)

コード例 #4
0
ファイル: 2b.py プロジェクト: rauoid/class_exercises
#!/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)