cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
274
Views
0
Helpful
0
Replies
Beginner

Multiple versions of Cobra SDK in a single python environment

Cross posting from https://supportforums.cisco.com/discussion/13273456/multiple-versions-cobra-sdk-single-python-environment

Hi,

I've been developing an internal orchestration tool for ACI based on Cobra SDK with webservices/web-interface provided by Flask. I'd like to have a single application (in a single environment) which manages different APIC clusters. Unfortunately these APIC clusters, being deployed at different times in different datacenters run different versions of code - 1.2.1m and 2.0.2n. 

When initially tried to use login to 2.0.2n using eggs from 1.2.1m it failed right there. I'm assuming for safety and sanity of everyone involved, I should be using appropriate Cobra SDK library downloaded from the APIC to be managed to each cluster. And there comes a problem - both Cobra SDK packages are in the same namepaces. What's more, the individual modules inside Cobra SDK are using absolute imports, meaning that I can't just move each SDK package into a different folder without requirement to edit every single file in the Cobra SDK package to import from a different namespace.

Based on discussions I had with other Python developers, it appears we're down to 3 options:

  • Completely separate applications running in different virtual environments each with appropriate Cobra SDK version. The downside is that either user has to connect to different URLs or some other infrastructure (such as HA proxy) needed in front of app servers to redirect to appropriate application based on some criteria.
  • Bite the bullet, move each Cobra SDK version to a separate Python package and find/replace all absolute references to "cobra." with "<new top package name>.cobra." in all files inside Cobra SDK. Dynamically load top package (using importlib) based on which APIC Cluster user of the application wants to manage.
  • Perform some other magic hackery with Python internals, such as sys.paths and/or sys.modules. (I don't have a clear plan on this one yet).

I'm hoping someone has already faced and dealt with this issue previously or to get a recommendation from Cobra SDK developers.

Thanks!

Everyone's tags (3)