kvm-controller-run.in 910 Bytes
#!{{ parameter_dict.get('python-path') }}
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically

# Echo client program
import socket
import time

# XXX: to be factored with slapos.toolbox qemu qmp wrapper.

socket_path = '{{ parameter_dict.get("socket-path") }}'
vnc_password = '{{ parameter_dict.get("vnc-passwd") }}'

# Connect to KVM qmp socket
so = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
connected = False
while not connected:
  try:
    so.connect(socket_path)
  except socket.error:
    time.sleep(1)
  else:
    connected = True
data = so.recv(1024)

# Enable qmp
so.send('{ "execute": "qmp_capabilities" }')
data = so.recv(1024)

# Set VNC password
so.send('{ "execute": "change", ' \
        '"arguments": { "device": "vnc", "target": "password", ' \
        '               "arg": "' + vnc_password + '" } }')
data = so.recv(1024)

# Finish
so.close()