I have a flask app running on my webserver to make calls to different remote servers based on hostname POST'ed from user selection. The webserver flask app makes SSH calls (using paramiko
) to user desired hostnames to run a python script.
Currently, I have to manually create a python script for each function I want to call in the backend or else I would run into import errors (since my webserver flask does not have the same python environment as the remote server).
For example, on my backend remote server if I want to call a function from my backend Python module I have to create something like this:
myScript.py:
#!/usr/bin/python3
from myPackage import myModule
myModule.myFunction()
And call it from the webserver flask app like this:
client.exec_command('(cd /myDir; ./myScript.py:)')
My question is, is there a way to stimulate the backend python environment and make calls directly to the python modules, or even some how be able to import the modules from the backend, so I don't have to create a separate script for each function I want to call?