How to use the pyeapi.connect_to function in pyeapi

To help you get started, we’ve selected a few pyeapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twr14152 / Network-Automation-Scripts_Python3 / pyeapi / eapi_ex2.py View on Github external
import pyeapi
from pprint import pprint as pp

host1 = pyeapi.connect_to("sw1")
host2 = pyeapi.connect_to("sw2")

devices = [host1, host2]

value = 0

for host in devices:
    value += 1
    print(str(value))
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("Pre-change State: ", host)
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    pp(host.enable(['show hostname', 'show running-config']))
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("Post-Change State:", host)
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    host.config(['interface loopback 0', 'ip address 1.1.1.{} 255.255.255.255'.format(value), 'description test', 'router ospf 1', 'network 0.0.0.0 255.255.255.255 area 0'])
github twr14152 / Network-Automation-Scripts_Python3 / pyeapi / eapi_ex1.py View on Github external
import pyeapi
from pprint import pprint as pp

host1 = pyeapi.connect_to("sw1")
host2 = pyeapi.connect_to("sw2")

devices = [host1, host2]

for host in devices: 
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("Connecting to: ", host)
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    pp(host.enable('show version'))
    pp(host.enable('show running-config'))
github ktbyers / python_course / class5 / eapi_vlan.py View on Github external
def main():
    """Add/remove vlans from Arista switch in an idempotent manner."""
    eapi_conn = pyeapi.connect_to("pynet-sw2")

    # Argument parsing
    parser = argparse.ArgumentParser(
        description="Idempotent addition/removal of VLAN to Arista switch"
    )
    parser.add_argument("vlan_id", help="VLAN number to create or remove", action="store", type=int)
    parser.add_argument(
        "--name",
        help="Specify VLAN name",
        action="store",
        dest="vlan_name",
        type=str
    )
    parser.add_argument("--remove", help="Remove the given VLAN ID", action="store_true")

    cli_args = parser.parse_args()
github twr14152 / Network-Automation-Scripts_Python3 / pyeapi / demo / script2.py View on Github external
import pyeapi
from pprint import pprint as pp

node1 = pyeapi.connect_to('veos5')
node2 = pyeapi.connect_to('veos6')

cmds = ["show ip route", "show ip ospf neighbor"]

pp(node1.run_commands(cmds))
pp(node2.run_commands(cmds))
github twr14152 / Network-Automation-Scripts_Python3 / pyeapi / eapi_validation_ex1.py View on Github external
import pyeapi
from pprint import pprint as pp

host1 = pyeapi.connect_to("sw1")
host2 = pyeapi.connect_to("sw2")

devices = [host1, host2]

value = 0

for host in devices:
    value += 1
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("Current State: ", host)
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    pp(host.enable(['show hostname', 'show running-config', 'show ip route', 'show ip ospf neighbor']))
github twr14152 / Network-Automation-Scripts_Python3 / pyeapi / eapi_ex1.py View on Github external
import pyeapi
from pprint import pprint as pp

host1 = pyeapi.connect_to("sw1")
host2 = pyeapi.connect_to("sw2")

devices = [host1, host2]

for host in devices: 
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("Connecting to: ", host)
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    pp(host.enable('show version'))
    pp(host.enable('show running-config'))
github twr14152 / Network-Automation-Scripts_Python3 / pyeapi / eapi_config_ex1.py View on Github external
import pyeapi
from pprint import pprint as pp

host1 = pyeapi.connect_to("sw1")
host2 = pyeapi.connect_to("sw2")

devices = [host1, host2]

value = 0

for host in devices:
    value += 1
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("Pre-change State: ", host)
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    pp(host.enable(['show running-config']))
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("Post-Change State:", host)
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    host.config(['interface loopback 0', 'ip address 1.1.1.{} 255.255.255.255'.format(value), 
                 'description test', 'router ospf 1', 'network 0.0.0.0 255.255.255.255 area 0'])
github twr14152 / Network-Automation-Scripts_Python3 / pyeapi / demo / script1.py View on Github external
import pyeapi
from pprint import pprint as pp

node1 = pyeapi.connect_to('veos5')
node2 = pyeapi.connect_to('veos6')

node1.api("ipinterfaces").create("Ethernet1")
node2.api("ipinterfaces").create("Ethernet1")

node1.config("ip name-server 8.8.8.8")
node1.config("ip route 0.0.0.0/0 192.168.1.1")

node2.config("ip name-server 8.8.8.8")
node2.config("ip route 0.0.0.0/0 192.168.1.1")

pp(node1.run_commands("ping cisco.com"))
pp(node2.run_commands("ping cisco.com"))

cmds = ["show version", "show running-config", "show management api http-commands"]
github twr14152 / Network-Automation-Scripts_Python3 / pyeapi / demo / script2.py View on Github external
import pyeapi
from pprint import pprint as pp

node1 = pyeapi.connect_to('veos5')
node2 = pyeapi.connect_to('veos6')

cmds = ["show ip route", "show ip ospf neighbor"]

pp(node1.run_commands(cmds))
pp(node2.run_commands(cmds))