kvm: move slapos.cookbook:kvm recipe to buildout+jinja
[slapos.git] / software / kvm / template / kvm-controller-run.in
1 #!{{ parameter_dict.get('python-path') }}
2 # BEWARE: This file is operated by slapgrid
3 # BEWARE: It will be overwritten automatically
4
5 # Echo client program
6 import socket
7 import time
8
9 # XXX: to be factored with slapos.toolbox qemu qmp wrapper.
10
11 socket_path = '{{ parameter_dict.get("socket-path") }}'
12 vnc_password = '{{ parameter_dict.get("vnc-passwd") }}'
13
14 # Connect to KVM qmp socket
15 so = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
16 connected = False
17 while not connected:
18   try:
19     so.connect(socket_path)
20   except socket.error:
21     time.sleep(1)
22   else:
23     connected = True
24 data = so.recv(1024)
25
26 # Enable qmp
27 so.send('{ "execute": "qmp_capabilities" }')
28 data = so.recv(1024)
29
30 # Set VNC password
31 so.send('{ "execute": "change", ' \
32         '"arguments": { "device": "vnc", "target": "password", ' \
33         '               "arg": "' + vnc_password + '" } }')
34 data = so.recv(1024)
35
36 # Finish
37 so.close()