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


Python ConnectHandler.clear_buffer方法代码示例

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


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

示例1: CiscoSwitch

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import clear_buffer [as 别名]

#.........这里部分代码省略.........

        Takes a port name, such as Gi1/0/48 or GigabitEthernet1/0/48 and
        returns the shorthand notation.

        :param port: port name
        :return: shorthand port name
        """
        if port is None:
            return ""

        lower = port.lower()
        output = port

        if any(lower.find(port) == 0 for port in self.PORT_NOTATION):
            for item in self.PORT_NOTATION.items():
                if lower.startswith(item[0]):
                    output = lower.replace(item[0], item[1])
                    break

        return output

    def _send_command(self, command):
        """Send command.

        Sends a command to the switch.

        :param command: command to send
        :return: output of the command
        """
        read_buffer = ""
        if self._client is None:
            return read_buffer

        self._client.clear_buffer()
        read_buffer = self._client.send_command(command)

        return read_buffer

    def _send_config(self, configs):
        """Configure switch.

        Sends a series of configuration options to the switch.

        :param configs: config commands
        """
        if self._client is None:
            return

        self._client.clear_buffer()
        self._client.send_config_set(configs)

    @staticmethod
    def _parse_version_output(output):
        """Version parsing.

        :param output: the output of the command
        :return: version string
        """
        lines = [line.strip() for line in output.splitlines()]
        version = ""
        search = True
        while len(lines) > 0 and search:
            line = lines.pop()

            if line.find("Cisco IOS") < 0:
                continue
开发者ID:SimplicityGuy,项目名称:pynoc,代码行数:70,代码来源:cisco.py

示例2: pingTest

# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import clear_buffer [as 别名]
def pingTest(device1,device2,aIntf,bIntf,latencyValue,latency):
                                try:
                                                                username,password=common.getRouterCredentials()
                                                                #password="WAnoharan!123"
                                                                delayFactor,loop = common.getSendCommandDelayFactor() 
                                                                timeout=getTimeout()
                                                                slaState="0"
                                                                AEnddevice = ConnectHandler(device_type="cisco_ios", ip=device1, username=username, password=password)
                                                                command='sh run interface '+aIntf
                                                                AEnddevice.clear_buffer()
                                                                output1 = AEnddevice.send_command(command,int(delayFactor),int(loop))
                                                                output1 = str(output1)
                                                                log.info("Device %s. Command %s. Output %s",str(device1),str(command),str(output1))
                                                                match=re.match(r'.*ip\s+address\s+(.*)\s+255.*',output1,re.DOTALL)
                                                                if match:
                                                                                AEndIntf=match.group(1)
                                
                                                                BEnddevice = ConnectHandler(device_type="cisco_ios", ip=device2, username=username, password=password)
                                                                command='sh run interface '+bIntf
                                                                BEnddevice.clear_buffer()
                                                                output1 = BEnddevice.send_command(command,int(delayFactor),int(loop))
                                                                output1 = str(output1)
                                                                log.info("Device %s. Command %s. Output %s",str(device2),str(command),str(output1))
                                                                match=re.match(r'.*ip\s+address\s+(.*)\s+255.*',output1,re.DOTALL)
                                                                if match:
                                                                                                BEndIntf=match.group(1)
                                                                command='ping '+BEndIntf.strip()+' source '+AEndIntf.strip()+' repeat 30 timeout '+timeout
                                                                AEnddevice.clear_buffer()
                                                                output1 = AEnddevice.send_command(command,int(delayFactor),int(loop))
                                                                output1 = str(output1)
                                                                pingA = output1
                                                                log.info("Device %s.Ping  Command %s. Output %s",str(device1),str(command),str(output1))
                                                                Alatency=1
                                                                pingResultA=-1
                                                                match=re.match(r'.*rate\s+is\s+(.*)\s+percent.*',output1,re.DOTALL)
                                                                if match:
  
                                                                                pingResultA=match.group(1)
                                                                                try:
                                                                                   if "latency" in latency.lower():
                                                                                                    lValue=latencyValue.split(",")
                                                                                                    match1=re.match(r'.*min/avg/max\s*=\s*(\d+)/(\d+)/(\d+).*',output1,re.DOTALL)
                                                                                                    if match1:
                                                                                                        AminValue=match1.group(1)
                                                                                                        AavgValue=match1.group(2)
                                                                                                        AmaxValue=match1.group(3)
                                                                                                        if int(lValue[0]) > int(AavgValue) or int(lValue[2]) < int(AavgValue):
                                                                                                                if int(lValue[0]) > int(AavgValue) and int(lValue[2]) < int(AavgValue):
                                                                                                                    slaState="Latency-Above & Below threshold"
                                                                                                                elif int(lValue[0]) > int(AavgValue):
                                                                                                                    slaState="Latency-Below threshold"
                                                                                                                else:
                                                                                                                    slaState="Latency-Above threshold"
                                                                                                                Alatency=0   
                                                                                except Exception as e:
                                                                                            log.warning("parsing Latency Message got failed.Error info : %s",str(e))
                                                                                                                                                                         
                                                                else:
                                                                                if "Invalid" in output1:
                                                                                        pingResultA="0" 
                                                                                elif pingResultA == -1:
                                                                                    pingResultA = output1                                                                              
                                                                                
                                                                               # pingResultA="0"  
                                                                command='ping '+AEndIntf.strip()+' source '+BEndIntf.strip()+' time '+timeout+' repeat 30'
                                                                BEnddevice.clear_buffer()
                                                                output1 = BEnddevice.send_command(command,int(delayFactor),int(loop))
                                                                output1 = str(output1)
                                                                pingB = output1
                                                                print "PingB",pingB
                                                                log.info("Device %s. Ping Command %s. Output %s",str(device2),str(command),str(output1))
                                                                Blatency=1
                                                                pingResultB=-1
                                                                match=re.match(r'.*rate\s+is\s+(.*)\s+percent.*',output1,re.DOTALL)
                                                                if match:
  
                                                                                pingResultB=match.group(1)
                                                                                try: 
                                                                                   if "latency" in latency.lower():
                                                                                                    lValue=latencyValue.split(",")
                                                                                                    match1=re.match(r'.*min/avg/max\s*=\s*(\d+)/(\d+)/(\d+).*',output1,re.DOTALL)
                                                                                                    if match1:
                                                                                                        BminValue=match1.group(1)
                                                                                                        BavgValue=match1.group(2)
                                                                                                        BmaxValue=match1.group(3)
                                                                                                        if int(lValue[0]) > int(BavgValue) or int(lValue[2]) < int(BavgValue):
                                                                                                                if int(lValue[0]) > int(BavgValue) and lValue[2] < int(BavgValue) :
                                                                                                                    slaState="Latency-Above & Below threshold"
                                                                                                                elif int(lValue[0]) > int(BavgValue):
                                                                                                                    slaState="Latency-Below threshold"
                                                                                                                else:
                                                                                                                    slaState="Latency-Above threshold"
                                                                                                                    Blatency=0    
                                                                                except Exception as e:
                                                                                            log.warning("parsing Latency Message got failed.Error info : %s",str(e))
                                                                                                                                                                     
                                                                else:
                                                                                if "Invalid" in output1:
                                                                                        pingResultB="0" 
                                                                                elif pingResultB == -1:
#.........这里部分代码省略.........
开发者ID:GowdhamAppu,项目名称:LogCorrelator,代码行数:103,代码来源:sendMail.py


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