Python pyeapi.connect_to() Examples
The following are 8
code examples of pyeapi.connect_to().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyeapi
, or try the search function
.
Example #1
Source File: ex1_eapi_interfaces.py From python_course with Apache License 2.0 | 6 votes |
def main(): """Use Arista's eAPI to obtain 'show interfaces' from the switch.""" eapi_conn = pyeapi.connect_to("pynet-sw2") interfaces = eapi_conn.enable("show interfaces") interfaces = pyeapi_result(interfaces) # Strip off unneeded dictionary interfaces = interfaces['interfaces'] # inOctets/outOctets are fields inside 'interfaceCounters' dict data_stats = {} for interface, int_values in interfaces.items(): int_counters = int_values.get('interfaceCounters', {}) data_stats[interface] = (int_counters.get('inOctets'), int_counters.get('outOctets')) # Print output data print("\n{:20} {:<20} {:<20}".format("Interface:", "inOctets", "outOctets")) for intf, octets in sorted(data_stats.items()): print("{:20} {:<20} {:<20}".format(intf, six.text_type(octets[0]), six.text_type(octets[1]))) print()
Example #2
Source File: ex1_eapi_interfaces.py From pynet with Apache License 2.0 | 6 votes |
def main(): ''' Use Arista's eAPI to obtain 'show interfaces' from the switch. ''' eapi_conn = pyeapi.connect_to("pynet-sw2") interfaces = eapi_conn.enable("show interfaces") interfaces = pyeapi_result(interfaces) # Strip off unneeded dictionary interfaces = interfaces['interfaces'] # inOctets/outOctets are fields inside 'interfaceCounters' dict data_stats = {} for interface, int_values in interfaces.items(): int_counters = int_values.get('interfaceCounters', {}) data_stats[interface] = (int_counters.get('inOctets'), int_counters.get('outOctets')) # Print output data print "\n{:20} {:<20} {:<20}".format("Interface:", "inOctets", "outOctets") for intf, octets in sorted(data_stats.items()): print "{:20} {:<20} {:<20}".format(intf, octets[0], octets[1]) print
Example #3
Source File: pyeapi_1.py From Mastering-Python-Networking-Second-Edition with MIT License | 5 votes |
def __init__(self, config_file_location, device): # loads the config file pyeapi.client.load_config(config_file_location) self.node = pyeapi.connect_to(device) self.hostname = self.node.enable('show hostname')[0]['result']['hostname'] self.running_config = self.node.enable('show running-config')
Example #4
Source File: pyeapi_1.py From Mastering-Python-Networking-Third-Edition with MIT License | 5 votes |
def __init__(self, config_file_location, device): # loads the config file pyeapi.client.load_config(config_file_location) self.node = pyeapi.connect_to(device) self.hostname = self.node.enable('show hostname')[0]['result']['hostname'] self.running_config = self.node.enable('show running-config')
Example #5
Source File: pyeapi_1.py From Python-Network-Programming with MIT License | 5 votes |
def __init__(self, config_file_location, device): # loads the config file pyeapi.client.load_config(config_file_location) self.node = pyeapi.connect_to(device) self.hostname = self.node.enable('show hostname')[0]['result']['hostname'] self.running_config = self.node.enable('show running-config')
Example #6
Source File: pyeapi_1.py From Mastering-Python-Networking with MIT License | 5 votes |
def __init__(self, config_file_location, device): # loads the config file pyeapi.client.load_config(config_file_location) self.node = pyeapi.connect_to(device) self.hostname = self.node.enable('show hostname')[0]['result']['hostname'] self.running_config = self.node.enable('show running-config')
Example #7
Source File: eapi_vlan.py From python_course with Apache License 2.0 | 4 votes |
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() vlan_id = cli_args.vlan_id remove = cli_args.remove vlan_name = six.text_type(cli_args.vlan_name) # Check if VLAN already exists check_vlan = check_vlan_exists(eapi_conn, vlan_id) # check if action is remove or add if remove: if check_vlan: print("VLAN exists, removing it") command_str = 'no vlan {}'.format(vlan_id) eapi_conn.config([command_str]) else: print("VLAN does not exist, no action required") else: if check_vlan: if vlan_name is not None and check_vlan != vlan_name: print("VLAN already exists, setting VLAN name") configure_vlan(eapi_conn, vlan_id, vlan_name) else: print("VLAN already exists, no action required") else: print("Adding VLAN including vlan_name (if present)") configure_vlan(eapi_conn, vlan_id, vlan_name)
Example #8
Source File: eapi_vlan.py From pynet with Apache License 2.0 | 4 votes |
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() vlan_id = cli_args.vlan_id remove = cli_args.remove vlan_name = cli_args.vlan_name # Check if VLAN already exists check_vlan = check_vlan_exists(eapi_conn, vlan_id) # check if action is remove or add if remove: if check_vlan: print "VLAN exists, removing it" command_str = 'no vlan {}'.format(vlan_id) eapi_conn.config([command_str]) else: print "VLAN does not exist, no action required" else: if check_vlan: if vlan_name is not None and check_vlan != vlan_name: print "VLAN already exists, setting VLAN name" configure_vlan(eapi_conn, vlan_id, vlan_name) else: print "VLAN already exists, no action required" else: print "Adding VLAN including vlan_name (if present)" configure_vlan(eapi_conn, vlan_id, vlan_name)