Open netwolk opened 1 year ago
The debug posted above doesn't complete (i.e. I don't see the trailing router prompt in the output)?
I see this in the output:
DEBUG:netmiko:read_channel:
% Screen-length configuration is disabled for current user.
You probably need to execute screen-length disable
(which Netmiko tries to do automatically).
You might want to look at the Netmiko session_log and see what you see there.
# Where hp_comware_device contains (will create a file named "output.txt" in the script directory).
hp_comware_device["session_log"] = "output.txt"
connection = ConnectHandler(**hp_comware_device)
hi,
I adjusted the script to write the session log. it gives me the output in the log as expected, And the screen-length disable is sent. `
when i run this code:
from netmiko import ConnectHandler
from datetime import datetime
import time
device = {
'device_type':'hp_comware',
'ip':"10.75.130.1",
'username':"Username",
'password':"Pass",
}
start_time = datetime.now()
print(start_time)
net_connect = ConnectHandler(**device, session_log=r"C:\Users\dellaerb\OneDrive - Katoen Natie\Documents\IT\Scripts\Arp_Lookup\Logs\Comware_Driver_TEST_LOG.txt")
print("connected to device")
# Disable screen-length and set the expected string as the device prompt
net_connect.send_command("screen-length disable")
print("screen-length disabled")
# Send the 'display version' command but don't immediately capture its output
net_connect.write_channel("display arp\n")
# Wait for a few seconds for the device to return the output
time.sleep(5)
# Read the output
output = net_connect.read_channel()
name = net_connect.find_prompt() + device['ip']
net_connect.disconnect()
print(name)
print(output)
print(">>>>>>>>>>>>>>>>>>>>>End<<<<<<<<<<<<<<<<<<<<<<")
end_time = datetime.now()
print(end_time)
i get my ouput as expected, The log file is the same:
Maybe try adding:
global_cmd_verify=True
As an argument to ConnectHandler (or alternatively add cmd_verify=True
to your send_command call). HP Comware has no way of setting the terminal width (as far as I know) and this causes a lot of problems.
If you know of a way to do this on Comware, let me know.
Let me know if the above works.
Maybe try adding:
global_cmd_verify=True
As an argument to ConnectHandler (or alternatively add
cmd_verify=True
to your send_command call). HP Comware has no way of setting the terminal width (as far as I know) and this causes a lot of problems.If you know of a way to do this on Comware, let me know.
Let me know if the above works.
I think it is necessary to remove the extra newline character ("\n") because users may not be familiar with the mechanism of cmd_verify. By using this parameter, users can avoid the issue, but they need to be aware of this mechanism. Netmiko aims to simplify user operations, so removing the newline character ("\n") allows users to avoid incorrect echoing caused by the extra newline character in the "cancel paging" command, regardless of whether the cmd_verify mechanism is enabled.
You can try setting global_cmd_verify to True when creating the connection in the ConnectHandler function. This can help avoid the bug where the echoing is misaligned with the command. ref link:https://github.com/ktbyers/netmiko/pull/3141
@jiujing I doubt the above problem is related to #3141.
I think it is related to global_cmd_verify=False
on Comware (due to Comware lacking any way of setting the terminal width).
But I will merge #3141 in and the user can test using the develop
branch and see if it helps or not.
global_cmd_verify
This issue is indeed related to global_cmd_verify, and setting it to False can help avoid this problem.However, the root cause lies in the extra newline character ("\n") before the "cancel paging" command. The "\n" in that piece of code doesn't serve any purpose. You should simply add a carriage return after each command you send, without adding a newline character before the command. Additionally, global_cmd_verify may affect send_config_set. If global_cmd_verify is set to True and cmd_verify is set to False, Netmiko will keep writing data to the channel without reading data. When a large configuration is being pushed, this continuous sending of data may cause the remote network device to close the channel.
@jiujing
Yeah, it is a bit hard to tell with the above output, but I don't think the extra
Additionally, global_cmd_verify may affect send_config_set. If global_cmd_verify is set to True and cmd_verify
is set to False, Netmiko will keep writing data to the channel without reading data. When a large configuration
is being pushed, this continuous sending of data may cause the remote network device to close the channel.
Yes, this is known (i.e. that is what cmd_verify does and why it was implemented in general), but the Comware (as far as I am aware) does not have a way to set the terminal width. Consequently, cmd_verify will break on Comware for commands that exceed a certain length (this is why Comware is one of the very few Netmiko drivers where cmd_verify is disabled by default).
So we either have Comware break for long commands or we have Comware break due to writing commands too fast (or sending too many config commands).
I am somewhat open to switching the default for global_cmd_verify back on Comware, but it will cause the driver to break for other users.
We could add in more logic in the initial session_preparation where we cmd_verify that the output paging disable works properly, before moving on...so that at least this part works reliably.
thx for al the feedback.
the difference i have found:
on Comware v7 its working with no issues. the issues only occurs on Comware v5
To Come back to this issue, about the difference i was working on a script to get the LLDP neighbor information.
when using write channel and read channel then i get my output as expected below working code:
`try:
print("start connecting")
net_connect = ConnectHandler(**device)
print(f"Connected to {device['ip']} ")
# Disable screen-length and set the expected string as the device prompt
net_connect.send_command("screen-length disable")
print("screen-length disabled")
# Get hostname
hostname = get_hostname(net_connect)
# Send the 'display lldp neighbor-information' command but don't immediately capture its output
net_connect.write_channel("display lldp neighbor-information\n")
# Wait for a few seconds for the device to return the output
time.sleep(5)
# Read the output
output = net_connect.read_channel()
net_connect.disconnect()
return output,hostname`
when using the send command, i don't get any returned output: below "non" woking code. the ouput is just blank, but i do get a hostname of the device !
` try:
print("start connecting")
connection = ConnectHandler(**device)
print(f"Connected to {device['ip']} ")
# Get Hostname
hostname = get_hostname(connection)
# Sending a command to the device to retrieve LLDP neighbor information.
output = connection.send_command("display lldp neighbor-information")
# Closing the connection to the device.
connection.disconnect()
# Returning the output from the device.
return output, hostname`
attached the both debugs
LOG_LLDP_NeighborInformation_ComwareV5_LLDP-Output OK.txt LOG_LLDP_NeighborInformation_ComwareV5_LLDP-Output_NOK.txt
Hi
I'm trying to do a basic thing: Retreiving the ARP table from a comware 7 switch:
The issue i have is that when running the script, the command get executed, but the output is empty. i have no return value if i check my DEBUG Logs, authentication is fine, the command is performed, but the output is not parsed ?
THx for your help
` from netmiko import ConnectHandler from netmiko import NetMikoTimeoutException, NetMikoAuthenticationException
import logging
Setup logging
LOG_FILENAME = r"C:\Users\Logs\TEST_HP-COMMWARE_Arp_Lookup_log_V2.txt" logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG) logger = logging.getLogger("netmiko")
def get_arp_table(ip, username, password):
Define the device type and credentials
def write_to_file(filename, content): with open(filename, 'w') as file: file.write(content)
Example usage
ip_address = "10.75.130.1" username = "My_Username" password = "My_Pass" output_file_path = r"C:\Users_ArpLookup.txt"
arp_table = get_arp_table(ip_address, username, password) print(arp_table)
Writing the arp_table to a file
if arp_table: print(arp_table) write_to_file(output_file_path, arp_table) else: print("Failed to retrieve ARP table.") `
when i run the script i get:
` arp_Lookup/Test_HP-COMWARE_Get_ARP_V2.py"