Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netmiko with Palo Alto firewall - limited characters to send with send_command #1925

Closed
llbdn73 opened this issue Sep 7, 2020 · 3 comments
Closed

Comments

@llbdn73
Copy link

llbdn73 commented Sep 7, 2020

Hello Dear Experts,
I'm a new user of Netmiko, I'd like to use it instead of Paramiko in order to get the result of my commands.
My Python script is working fine with less than around 40 characters.
e.g. ssh.send_command("set address toto") --> It is working fine,
But, ssh.send_command(" set address-group "tototootototototoototototo") --> It blocks for around 1 minute and finish with a Timeout message error (entire message below)

My pieces of codes and some explanations
I use a code to get the commands lines to push to the firewall, all the command lines are included in a list
At the end, all the short commands works fine, toto, tata, titi, the security rule "Offload Skype" are correctly created because they are all under 40 characters, but as soon as a command with more than 40 characters is sent (e.g. set address-group "tototootototototoototototo" => 46 characters, the entry is created within the firewall but the script stops with the error described below.
I hope there is an option to fix it in Netmiko, I saw some posts with a "cmd_verify = False" but I can't use it with the paloalto_panos it looks ...
Thank you by advance for your support.

paloalto = {
        'device_type': "paloalto_panos",
        'ip': hostname,
        'username': username,
        'password': password,
        'session_log': "output.txt",
    }
ssh = ConnectHandler(**paloalto)
confmode = ssh.send_command("configure\n", expect_string=r"#")
print(confmode)
for conf in listconf:
        print(conf)
        error = ssh.send_command(conf)
        sleep(1)
        if error != "":
            print("".center(100, "!"))
            print(f"ERROR: The previous command finished with the message:{error}")
            print("".center(100, "!"))

Please see below the result of my script from the Python shell

Please enter the admin usersame to connect to the Palo Alto >>>>> toto-admin

Warning (from warnings module):
File "C:\Program Files (x86)\Python37-32\lib\getpass.py", line 100
return fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.
Please enter the password >>>>> passwordtoto


********************* Start the connection to the firewall fw-toto*********************


You are connected to the firewall fw-toto

Entering configuration mode
set address toto
set address tata
set address titi
set rulebase security rules "Offload Skype"
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ERROR: The previous command finished with the message:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
set address-group "tototootototototoototototo"
Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\paramiko\channel.py", line 699, in recv
out = self.in_buffer.read(nbytes, self.timeout)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\paramiko\buffered_pipe.py", line 164, in read
raise PipeTimeout()
paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\base_connection.py", line 541, in _read_channel_expect
new_data = self.remote_conn.recv(MAX_BUFFER)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\paramiko\channel.py", line 701, in recv
raise socket.timeout()
socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Temp\Script-to-check.py", line 123, in
pushconf(connect, listFW)
File "C:\Temp\Script-to-check.py", line 94, in pushconf
error = ssh.send_command(conf)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\paloalto\paloalto_panos.py", line 160, in send_command
return super().send_command(*args, **kwargs)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\base_connection.py", line 1366, in send_command
new_data = self.read_until_pattern(pattern=re.escape(cmd))
File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\base_connection.py", line 618, in read_until_pattern
return self._read_channel_expect(*args, **kwargs)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\base_connection.py", line 552, in _read_channel_expect
"Timed-out reading channel, data not available."
netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.

@llbdn73
Copy link
Author

llbdn73 commented Sep 7, 2020

I attached also the debug file
output.txt

@rjithu
Copy link

rjithu commented Mar 6, 2021

try with "set cli scripting-mode on"

@ktbyers
Copy link
Owner

ktbyers commented Aug 19, 2021

I think this is probably fixed here (in develop branch).

#2227

If you are still seeing a problem, you can re-open or create a new issue:

@ktbyers ktbyers closed this as completed Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants