How can my python wait until all the commands execute
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2023 09:12 AM
Hi Team,
How my pathon script will wait until the command executable?
im configuring acl on nexus switch and taking little longer due to 90% of tcam memory use.
While configuring acl through python it is not able to configure and how it can wait until all the command execute.
- Labels:
-
Routing Protocols
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2023 09:22 AM
Hi Team,
I’m able to configure 1st &2nd line “able to configure but 3rd line not able to configure in nexus via python
config_Command = [“ip access-List extended test”,
“permit ip 1.1.1.1/32 2.2.2.2/32”,
permit ip “2.2.2.2/32 1.1.1.1/32”]
conn.send_config_set (config_Command)
conn. exit_config_mode ()
print("conn send _config_set")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2023 09:35 AM - edited 03-18-2023 09:38 AM
You can do sleep :
check_command_status()
sleep(5)
But try the below and works for me : (with out sleep)
from netmiko import ConnectHandler
# define device parameters
device = {
'device_type': 'cisco_nxos',
'ip': 'nexus-switch-ip',
'username': 'your-username',
'password': 'your-password',
}
# create SSH connection
with ConnectHandler(**device) as net_connect:
# send CLI commands to configure the access-list
config_commands = [
'ip access-list extended my-acl',
'permit tcp any any eq 80',
'permit tcp any any eq 443',
'deny ip any any',
]
output = net_connect.send_config_set(config_commands)
# print the output
print(output)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2023 09:56 AM
Thank you for your input.
I have tried the above command without sleep. It is working in router and catalyst switches.
But in our nexus 7k, we have lots of acl and the tcam memory being utilised upto 96%, so while configuring the acl it usually takes less than minutes to save all configuration.
whenever I’m configuring acl by python in our Nexus 7k, till 2nd line it able to configure but 3rd to till next it is unable to configure and even I’m not getting any kind of error.
im suspecting I need to define some delay or waiting times, so python can wait until the entire configuration are complete.
==> where should I mention?
check_command_status()
sleep(5)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2023 11:03 AM
When you add manually some test ACL Lines, how long it taking?
if you like to use sleep for testing :
import time <-- add this to script
...
...
# send each command with a delay
for command in config_commands:
output = net_connect.send_command_timing(command)
time.sleep(5)
# print the output
print(output)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2023 08:27 PM
=> it takes arround 2min to complete specially on my nexus 7k.
=>Earlier I tried time.sleep (120sec)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 07:15 AM
Do you mean who syntax to complete 120seconds - that is very high
You can also print and check each line and how long it takes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 09:35 AM
When you add manually some test ACL Lines, how long it taking?
>>its tooks 2min to complete the below command.
Verify
Commit
Copy run-config startup-config
(Above command i used to apply manuallg and which tooks 2min to process all )
Below command i tried:
config_Command = [“ip access-List extended test”,
“permit ip 1.1.1.1/32 2.2.2.2/32”,
"permit ip “2.2.2.2/32 1.1.1.1/32”]
conn.send_config_set (config_Command)
time.sleep(120)
conn. exit_config_mode ()
=> later i saw only one line was co figured.
“permit ip 1.1.1.1/32 2.2.2.2/32”
You can also print and check each line and how long it takes.
>>> my configuration is not completing through python.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 10:09 AM
that too much delay you need to increase time but that not going to get optimal results here.
May be you can use expect with python need to test,
every time config push, you expect prompt before send another command.
you need to fix the TCAM issue not sure what is the issue of that, you need to provide more information on that or open a different threat for the TCAM issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 03:27 AM
Thank you Balaji
Actually my tcam memory has been utilised to >90%.
anyone can suggest here
how can we tell python to wait until all configuration command execute.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2023 01:01 AM - edited 03-23-2023 01:01 AM
how can we tell python to wait until all configuration command execute. <-- use expect
