Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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()
[]