cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Bookmark
|
Subscribe
|
2550
Views
1
Helpful
10
Replies

How can my python wait until all the commands execute

Tapas970
Level 1
Level 1

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. 

 

10 Replies 10

Tapas970
Level 1
Level 1

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")

 

 

 

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)

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

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)

 

 

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)

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

 

=> it takes arround 2min to complete specially on my nexus 7k.

=>Earlier I tried time.sleep (120sec)

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.

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

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. 

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.

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

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.

 

how can we tell python to wait until all configuration command execute.  <-- use  expect

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help