Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'])
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'))
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()
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))
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']))
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'))
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'])
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"]
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))