diff --git a/doc/howtos/index.rst b/doc/howtos/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..2432bd05efb4b773ae8adf692aeeede3b5e5dfda --- /dev/null +++ b/doc/howtos/index.rst @@ -0,0 +1,9 @@ +Howtos +====== + +Contents: + +.. toctree:: + :maxdepth: 2 + + python_interpreter_client diff --git a/doc/howtos/python_interpreter_client.rst b/doc/howtos/python_interpreter_client.rst new file mode 100644 index 0000000000000000000000000000000000000000..c7f75095a1e6e0b315d7783be6c0761aae075304 --- /dev/null +++ b/doc/howtos/python_interpreter_client.rst @@ -0,0 +1,70 @@ +Simple client with python interpreter +===================================== + +You can easily connect on a CloudControl server with a Python shell for +debugging purpose. + +Before to start, make sure you have installed the ``python-sjrpc`` package:: + + aptitude install python-sjrpc + +1. Start a new Python shell +--------------------------- + +:: + + Python 2.6.6 (r266:84292, Oct 9 2010, 12:24:52) + [GCC 4.4.5] on linux2 + Type "help", "copyright", "credits" or "license" for more information. + >>> + +2. Import sjrpc +--------------- + +>>> from sjrpc.client import SimpleRpcClient +>>> from sjrpc.utils import ConnectionProxy + +3. Import socket & SSL modules +------------------------------ + +>>> import socket +>>> import ssl + +4. Create the socket object +--------------------------- + +>>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +>>> sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + +Wrap it into ssl socket wrapper to enable SSL (mandatory): + +>>> sock = ssl.wrap_socket(sock, certfile=None, cert_reqs=ssl.CERT_NONE, ssl_version=ssl.PROTOCOL_TLSv1) + +And connect it: + +>>> sock.connect(('ip.add.res.s', 1984)) + +5. Create the client object +--------------------------- + +>>> client = SimpleRpcClient(sock) + +You can also create a proxy object to easily call remote methods: + +>>> p = ConnectionProxy(client) + +6. Launch the client event loop +------------------------------- + +To keep control on the interpreter, you need to launch the event loop in a +new thread: + +>>> import threading +>>> threading.Thread(target=client.run).start() + +7. Authenticate & play ! +------------------------ + +>>> p.authentify('amillet', 'jeancloud') +>>> p.list_vm() +[] diff --git a/doc/index.rst b/doc/index.rst index c60b7e50075a410db2fbd444486e78a8ebb6c87d..b4573a893ae423fce4b1b04d1f6dff993adc3ddf 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -7,6 +7,7 @@ Contents: :maxdepth: 2 api + howtos/index Indices and tables ==================