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


Python IOSXR.show_lldp_neighbors方法代码示例

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


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

示例1: IOSXRDriver

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import show_lldp_neighbors [as 别名]

#.........这里部分代码省略.........
                description = ""
                if "line protocol" in line:
                    lp = line.split()
                    interface_name = lp[0]
                    is_enabled = lp[2] == "up,"
                    is_up = lp[6] == "up"
                elif "bia" in line:
                    mac_address = line.split()[-1].replace(")", "")
                elif "Description" in line:
                    description = " ".join(line.split()[1:])
                elif "BW" in line:
                    speed = int(line.split()[4]) / 1000
            result[interface_name] = {
                "is_enabled": is_enabled,
                "is_up": is_up,
                "mac_address": unicode(mac_address),
                "description": unicode(description),
                "speed": speed,
                "last_flapped": -1.0,
            }

        return result

    # def get_bgp_neighbors(self):
    #
    #     # init result dict
    #     result = {}
    #     # todo vrfs
    #     result['default'] = {}
    #     result['default']['peers'] = {}
    #
    #     # fetch sh ip bgp output
    #     sh_bgp = self.device.show_ip_bgp_neighbors()
    #     # split per bgp neighbor
    #     bgp_list = sh_bgp.rstrip().split('\n\nBGP')
    #     # for each neigh...
    #     for neighbor in bgp_list:
    #
    #         peer_lines = neighbor.split('\n')
    #
    #         # init variables
    #         is_up = None
    #         is_enabled = None
    #         uptime = None
    #         description = None
    #         received_prefixes = None
    #         sent_prefixes = None
    #         accepted_prefixes = None
    #         remote_as = None
    #
    #         for line in peer_lines:
    #
    #             match1 = re.search('(BGP)? neighbor is (.*)',line)
    #             if match1 is not None:
    #                 peer_ip = match1.group(2)
    #
    #             match2 = re.search('BGP state = (.*)',line)
    #             if match2 is not None:
    #                 if match2.group(1) == 'Active':
    #                     is_up = False
    #                     is_enabled = True
    #
    #             match3 = re.search('Description: (.*)$',line)
    #             if match3 is not None:
    #                 description = match3.group(1)
    #
    #             match4 = re.search('Remote AS (\d*)',line)
    #             if match4 is not None:
    #                 remote_as = int(match4.group(1))
    #
    #
    #         result['default']['peers'][peer_ip] = {
    #             'is_up': is_up,
    #             'is_enabled': is_enabled,
    #             'uptime': uptime,
    #             'description': description,
    #             'received_prefixes': received_prefixes,
    #             'sent_prefixes': sent_prefixes,
    #             'accepted_prefixes': accepted_prefixes,
    #             'remote_as': remote_as,
    #         }
    #
    #     return result

    def get_lldp_neighbors(self):

        # init result dict
        lldp = {}

        # fetch sh ip bgp output
        sh_lldp = self.device.show_lldp_neighbors().splitlines()[5:-3]

        for n in sh_lldp:
            local_interface = n.split()[1]
            if local_interface not in lldp.keys():
                lldp[local_interface] = list()

            lldp[local_interface].append({"hostname": unicode(n.split()[0]), "port": unicode(n.split()[4])})

        return lldp
开发者ID:jmay00,项目名称:napalm,代码行数:104,代码来源:iosxr.py

示例2: IOSXRDriver

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import show_lldp_neighbors [as 别名]

#.........这里部分代码省略.........
        
        rpc_command = "<Get><AdminOperational><MemorySummary></MemorySummary></AdminOperational></Get>"
        result_tree = ET.fromstring(self.device.make_rpc_call(rpc_command))

        for node in result_tree.iter('Node'):
            print 
            if node.find('Naming/NodeName/Slot').text == active_modules['RSP'][0]:    # first enabled RSP
                available_ram = int(node.find('Summary/SystemRAMMemory').text)
                free_ram = int(node.find('Summary/FreeApplicationMemory').text)
                break    # we're only looking at one of the RSP's

        if available_ram and free_ram:
            used_ram = available_ram - free_ram
            memory = dict()
            memory['available_ram'] = available_ram
            memory['used_ram'] = used_ram
            environment_status['memory'] = memory

        #
        # Fans
        #

        for fan in active_modules['FT']:
            rpc_command = get_module_xml_query(fan,'')
            result_tree = ET.fromstring(self.device.make_rpc_call(rpc_command))
            for module in result_tree.iter('Module'):
                for sensortype in module.iter('SensorType'):
                    for sensorname in sensortype.iter('SensorNameTable'):
                        if sensorname.find('SensorName/Naming/Name').text == "host__FanSpeed_0":
                            environment_status['fans'][fan] = {'status': int(sensorname.find(
                                'SensorName/ValueDetailed/Status').text) is 1}

        #
        # CPU
        #
        cpu = dict()
 
        rpc_command = "<Get><Operational><SystemMonitoring></SystemMonitoring></Operational></Get>"
        result_tree = ET.fromstring(self.device.make_rpc_call(rpc_command))

        for module in result_tree.iter('CPUUtilization'):
            this_cpu = dict()
            this_cpu["%usage"] = float(module.find('TotalCPUFiveMinute').text)

            rack = module.find('Naming/NodeName/Rack').text
            slot = module.find('Naming/NodeName/Slot').text
            instance = module.find('Naming/NodeName/Instance').text
            position =  "%s/%s/%s" % (rack,slot,instance)

            cpu[position] = this_cpu

        environment_status["cpu"] = cpu

        #
        # Temperature
        #

        temperature = dict()

        slot_list = set()
        for category, slot in active_modules.iteritems():
            slot_list |= set(slot)

        for slot in slot_list:
            rpc_command = get_module_xml_query(slot,'')
            result_tree = ET.fromstring(self.device.make_rpc_call(rpc_command))

            for sensor in result_tree.findall(".//SensorName"):
                if not sensor.find('Naming/Name').text == "host__Inlet0":
                    continue
                this_reading = dict()
                this_reading['temperature'] = float(sensor.find('ValueBrief').text)

                threshold_value = [float(x.text) for x in sensor.findall("ThresholdTable/Threshold/ValueBrief")]

                this_reading['is_alert'] = threshold_value[2] <= this_reading['temperature'] <= threshold_value[3]
                this_reading['is_critical'] = threshold_value[4] <= this_reading['temperature'] <= threshold_value[5]

                this_reading['temperature'] = this_reading['temperature']/10

                environment_status["temperature"][slot] = this_reading

        return environment_status

    def get_lldp_neighbors(self):

        # init result dict
        lldp = {}

        # fetch sh ip bgp output
        sh_lldp = self.device.show_lldp_neighbors().splitlines()[5:-3]

        for n in sh_lldp:
            local_interface = n.split()[1]
            if local_interface not in lldp.keys():
                lldp[local_interface] = list()

            lldp[local_interface].append({'hostname': unicode(n.split()[0]), 'port': unicode(n.split()[4]), })

        return lldp
开发者ID:t2d,项目名称:napalm,代码行数:104,代码来源:iosxr.py

示例3: IOSXRDriver

# 需要导入模块: from pyIOSXR import IOSXR [as 别名]
# 或者: from pyIOSXR.IOSXR import show_lldp_neighbors [as 别名]

#.........这里部分代码省略.........
                    'InterfaceStatistics/FullInterfaceStats/BytesReceived').text)
                interface_stats['tx_unicast_packets'] = int(interface.find(
                    'InterfaceStatistics/FullInterfaceStats/PacketsSent').text)
                interface_stats['rx_errors'] = int(interface.find(
                    'InterfaceStatistics/FullInterfaceStats/InputErrors').text)
                interface_stats['tx_broadcast_packets'] = int(interface.find(
                    'InterfaceStatistics/FullInterfaceStats/BroadcastPacketsSent').text)
                interface_stats['rx_multicast_packets'] = int(interface.find(
                    'InterfaceStatistics/FullInterfaceStats/MulticastPacketsReceived').text)
                interface_stats['rx_broadcast_packets'] = int(interface.find(
                    'InterfaceStatistics/FullInterfaceStats/BroadcastPacketsReceived').text)
                interface_stats['rx_discards'] = int(interface.find(
                    'InterfaceStatistics/FullInterfaceStats/InputDrops').text)
                interface_stats['rx_unicast_packets'] = int(interface.find(
                    'InterfaceStatistics/FullInterfaceStats/PacketsReceived').text)

            interface_counters[interface_name] = interface_stats

        return interface_counters

    # def get_bgp_neighbors(self):
    #
    #     # init result dict
    #     result = {}
    #     # todo vrfs
    #     result['default'] = {}
    #     result['default']['peers'] = {}
    #
    #     # fetch sh ip bgp output
    #     sh_bgp = self.device.show_ip_bgp_neighbors()
    #     # split per bgp neighbor
    #     bgp_list = sh_bgp.rstrip().split('\n\nBGP')
    #     # for each neigh...
    #     for neighbor in bgp_list:
    #
    #         peer_lines = neighbor.split('\n')
    #
    #         # init variables
    #         is_up = None
    #         is_enabled = None
    #         uptime = None
    #         description = None
    #         received_prefixes = None
    #         sent_prefixes = None
    #         accepted_prefixes = None
    #         remote_as = None
    #
    #         for line in peer_lines:
    #
    #             match1 = re.search('(BGP)? neighbor is (.*)',line)
    #             if match1 is not None:
    #                 peer_ip = match1.group(2)
    #
    #             match2 = re.search('BGP state = (.*)',line)
    #             if match2 is not None:
    #                 if match2.group(1) == 'Active':
    #                     is_up = False
    #                     is_enabled = True
    #
    #             match3 = re.search('Description: (.*)$',line)
    #             if match3 is not None:
    #                 description = match3.group(1)
    #
    #             match4 = re.search('Remote AS (\d*)',line)
    #             if match4 is not None:
    #                 remote_as = int(match4.group(1))
    #
    #
    #         result['default']['peers'][peer_ip] = {
    #             'is_up': is_up,
    #             'is_enabled': is_enabled,
    #             'uptime': uptime,
    #             'description': description,
    #             'received_prefixes': received_prefixes,
    #             'sent_prefixes': sent_prefixes,
    #             'accepted_prefixes': accepted_prefixes,
    #             'remote_as': remote_as,
    #         }
    #
    #     return result

    def get_lldp_neighbors(self):

        # init result dict
        lldp = {}

        # fetch sh ip bgp output
        sh_lldp = self.device.show_lldp_neighbors().splitlines()[5:-3]

        for n in sh_lldp:
            local_interface = n.split()[1]
            if local_interface not in lldp.keys():
                lldp[local_interface] = list()

            lldp[local_interface].append({
                'hostname': unicode(n.split()[0]),
                'port': unicode(n.split()[4]),
            })

        return lldp
开发者ID:mileswdavis,项目名称:napalm,代码行数:104,代码来源:iosxr.py


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