shellsshautomationnetwork-programmingnetmiko

How do use netmiko to send a tab-complete command and read the output?


I'm new to netmiko (and network automation in general tbh), and I'm currently trying to use it to send a command that, when used manually, requires you to press tab a few times in order to get the full result (two tabs for output to appear, another to view the rest, pressing enter will give you a syntax error). So far, I haven't been able to make this work programmatically.

The first method I tried looked like this:

from netmiko import ConnectHandler

def send_commands_tab(self, command):
    net_connect = ConnectHandler(**self.device)
    net_connect.read_channel()
    time.sleep(1)
    net_connect.write_channel(command + '\t')
    time.sleep(1)
    return net_connect.read_channel()

This just returns the command itself with a tab's worth of whitespace (or more, if I add more \t). Adding a newline triggers the syntax error.

I also tried

def send_commands_tab(self, command):
        net_connect = ConnectHandler(**self.device)
        net_connect.read_channel()
        time.sleep(1)
        
        net_connect.send_command(command + '\t\t\t', normalize=False)
        time.sleep(1)
        return net_connect.read_channel()

This just returns user@machine, which is even more confusing, and nothing at all if I add a newline. I've tried some other minor variations with no luck printing anything resembling my desired result.

Any help greatly appreciated!


Solution

  • Solution - this was a netmiko version issue. downgrading netmiko to ver 3.3.2 from 4.8.0 (pip3 install netmiko==3.3.2) fixed the problem.