KVM SR: Remove brain overhead of having a dict created from another dict.
[slapos.git] / slapos / recipe / kvm / template / kvm_controller_run.in
1 #!%(python-path)s
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 socket_path = '%(socket-path)s'
10 vnc_password = '%(vnc-passwd)s'
11
12 # Connect to KVM qmp socket
13 so = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
14 connected = False
15 while not connected:
16   try:
17     so.connect(socket_path)
18   except socket.error:
19     time.sleep(1)
20   else:
21     connected = True
22 data = so.recv(1024)
23
24 # Enable qmp
25 so.send('{ "execute": "qmp_capabilities" }')
26 data = so.recv(1024)
27
28 # Set VNC password
29 so.send('{ "execute": "change", ' \
30         '"arguments": { "device": "vnc", "target": "password", ' \
31         '               "arg": "' + vnc_password + '" } }')
32 data = so.recv(1024)
33
34 # Finish
35 so.close()