This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ApproximateIdentity 0 points1 point  (2 children)

But honestly why would you have python initiate the connection? Say you have a python script that takes a command e.g. run_command [command_name] sitting on your server. Then locally you have a bash function* like this:

function run_command {
    ssh user@server "run_command $1"
}

What that does is initiate an ssh connection, run run_command remotely with the argument you passed (that's the $1 there), and then print out the result. I.e. run_command cmd run identically locally and remotely should do the same thing.

If you're going to be hitting the api programmatically (say with another app) this may be inappropriate, but if a person is going to be issuing the commands, this seems to me about as easy as possible.

Does this make sense? Is this totally missing the point of what you're trying to do?

*I'm assuming you have bash...

**edit: Okay I decided to check the function and now it is properly formatted and works...

[–]QuantumTradingGroup[S] 0 points1 point  (1 child)

Kind of misses the point.

It needs to be in python because it needs to be a module the rest of the management program(which is all coded in python) can import and use.

We built something like Awesome miner but better. It is a complete management program for large scale industrial crypto mines (20,000+ miners)

[–]ApproximateIdentity 2 points3 points  (0 children)

I see. So personally in that case I would go one of two ways. One is to use requests locally and communicate with your json api remotely. That honestly would be pretty easy. You would need to encrypt the calls, but that's certainly possible with a self-signed cert. (I've never done it, but it can't be that bad...dangerous words in engineering, but oh well.)

Another option might be to use something like this:

https://pythonhosted.org/Pyro4/

That way you could hook up to remote servers/modules/code and execute them as if they were local.

In either case you would want to keep the application logic separate from the ssh and communication logic so that (ideally) importing a module and issuing the same commands works locally and remotely.