cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
970
Views
10
Helpful
1
Replies

Execute configuration script on APIC server

andreas.blum
Level 1
Level 1

I wrote a python script to apply a baseline configuration to fresh ACI fabrics utilizing the REST API.
It uses the 'requests' module and I tested it from my laptop successfully in our LAB.

One issue I'm running into, is that after so many requests the next will fail with 'the host did reset the connection'.
This may be due to transport issues, because introducing a 5 sec sleep every now and then will have the whole script work through just fine.

However, the plan was anyway to have a deployment engineer run the script directly on one of the APIC servers in the cluster, to avoid requiring another machine with python installed.

Now, it appears that neither python 2.7 nor python 3.7 (we're on 4.2(4p)) come with the 'requests' module installed, which took me off guard.

I'm not sure why such an essential module is missing from the APIC, but I'm now facing a redo of my script and wonder what to use as I'm not too keen to go the bash/icurl way.
Any suggestions are very much appreciated.

 

1 Accepted Solution

Accepted Solutions

Sergiu.Daniluk
VIP Alumni
VIP Alumni

You can use urllib module which is built-in, but the best way to deal with this is venv and install requests there:

admin@apic1: cd /data/techsupport/
admin@apic1:techsupport> 
admin@apic1:techsupport> python3 -m venv venv
admin@apic1:techsupport> source venv/bin/activate
(venv) admin@apic1:techsupport> pip install requests
<snip>
Installing collected packages: chardet, urllib3, certifi, idna, requests
Successfully installed certifi-2020.11.8 chardet-3.0.4 idna-2.10 requests-2.25.0 urllib3-1.26.2
WARNING: You are using pip version 19.2.3, however version 20.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venv) admin@apic1:techsupport> python
Python 3.7.6 (default, Dec 20 2019, 15:05:20) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests

 

Edit: you just need to make sure you have internet access and DNS configured.

 

Stay safe,

Sergiu

View solution in original post

1 Reply 1

Sergiu.Daniluk
VIP Alumni
VIP Alumni

You can use urllib module which is built-in, but the best way to deal with this is venv and install requests there:

admin@apic1: cd /data/techsupport/
admin@apic1:techsupport> 
admin@apic1:techsupport> python3 -m venv venv
admin@apic1:techsupport> source venv/bin/activate
(venv) admin@apic1:techsupport> pip install requests
<snip>
Installing collected packages: chardet, urllib3, certifi, idna, requests
Successfully installed certifi-2020.11.8 chardet-3.0.4 idna-2.10 requests-2.25.0 urllib3-1.26.2
WARNING: You are using pip version 19.2.3, however version 20.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venv) admin@apic1:techsupport> python
Python 3.7.6 (default, Dec 20 2019, 15:05:20) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests

 

Edit: you just need to make sure you have internet access and DNS configured.

 

Stay safe,

Sergiu