当前位置: 首页>>代码示例>>Python>>正文


Python pyeapi.connect_to方法代码示例

本文整理汇总了Python中pyeapi.connect_to方法的典型用法代码示例。如果您正苦于以下问题:Python pyeapi.connect_to方法的具体用法?Python pyeapi.connect_to怎么用?Python pyeapi.connect_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyeapi的用法示例。


在下文中一共展示了pyeapi.connect_to方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import pyeapi [as 别名]
# 或者: from pyeapi import connect_to [as 别名]
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() 
开发者ID:ktbyers,项目名称:python_course,代码行数:25,代码来源:ex1_eapi_interfaces.py

示例2: main

# 需要导入模块: import pyeapi [as 别名]
# 或者: from pyeapi import connect_to [as 别名]
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 
开发者ID:ktbyers,项目名称:pynet,代码行数:26,代码来源:ex1_eapi_interfaces.py

示例3: __init__

# 需要导入模块: import pyeapi [as 别名]
# 或者: from pyeapi import connect_to [as 别名]
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') 
开发者ID:PacktPublishing,项目名称:Mastering-Python-Networking-Second-Edition,代码行数:8,代码来源:pyeapi_1.py

示例4: main

# 需要导入模块: import pyeapi [as 别名]
# 或者: from pyeapi import connect_to [as 别名]
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) 
开发者ID:ktbyers,项目名称:python_course,代码行数:46,代码来源:eapi_vlan.py

示例5: main

# 需要导入模块: import pyeapi [as 别名]
# 或者: from pyeapi import connect_to [as 别名]
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) 
开发者ID:ktbyers,项目名称:pynet,代码行数:48,代码来源:eapi_vlan.py


注:本文中的pyeapi.connect_to方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。