views:

50

answers:

3

How can we call the CLI executables commands using Python

For example i have 3 linux servers which are at the remote location and i want to execute some commands on those servers like finding the version of the operating system or executing any other commands. So how can we do this in Python. I know this is done through some sort of web service (SOAP or REST) or API but i am not sure....... So could you all please guide me.

A: 

Depends on how you want to design your software.

You could do stand-alone scripts as servers listening for requests on specific ports, or you could use a webserver which runs python scripts so you just have to access a URL.

REST is one option to implement the latter. You should then look for frameworks for REST development with python, or if it’s simple logic with not so many possible requests can do it on your own as a web-script.

Kissaki
A: 

Maybe you should take a look at Pushy, which allows to connect to remote machines through SSH and make them execute various Python functions. I like using it because there are no server-side dependencies except the SSH server and a Python interpreter, and is therefore really easy to deploy.

Edit: But if you wish to code this by yourself, i think SOAP is a nice solution, the SOAPpy module is great and very easy to use.

MatToufoutu
A: 

You can use Twisted,

It is easy create ssh clients or servers.

Examples: http://twistedmatrix.com/documents/current/conch/examples/

cues7a
coding an ssh client/server just to call remote functions seems a bit overkill, doesn't it?
MatToufoutu
It depends, Twisted is oriented to network programing, it implements various network protocols and it is really easy to make clients and servers, If you look at the example of the server it is only a few lines of code.
cues7a