Commit 5ecfd413 authored by Vangelis Koukis's avatar Vangelis Koukis
Browse files

Support dynamic port allocation for VNC console

Add new version of vapclient.py from commit 48b1400eff
of vncauthproxy (dynamic port pool allocation, JSON control
requests and replies).

Modify api/actions.py to request dynamic port allocation
and handle error conditions gracefully.
parent c1d23fe5
......@@ -68,16 +68,21 @@ def get_console(request, vm, args):
raise ServiceUnavailable()
# Let vncauthproxy decide on the source port.
# FIXME
# sport = 0
sport = console_data['port'] - 1000
# The alternative: static allocation, e.g.
# sport = console_data['port'] - 1000]
sport = 0
daddr = console_data['host']
dport = console_data['port']
passwd = random_password()
if not request_vnc_forwarding(sport, daddr, dport, passwd):
raise ServiceUnavailable("Could not allocate VNC console port")
vnc = { 'host': getfqdn(), 'port': sport, 'password': passwd }
try:
fwd = request_vnc_forwarding(sport, daddr, dport, passwd)
if fwd['status'] != "OK":
raise ServiceUnavailable("Could not allocate VNC console port")
vnc = { 'host': getfqdn(), 'port': fwd['source_port'], 'password': passwd }
except Exception:
#raise ServiceUnavailable("Could not allocate VNC console port")
raise
# Format to be reviewed by [verigak], FIXME
if request.serialization == 'xml':
......
......@@ -21,25 +21,33 @@
import sys
import socket
try:
import simplejson as json
except ImportError:
import json
CTRL_SOCKET = "/tmp/vncproxy.sock"
def request_forwarding(sport, daddr, dport, password):
sport = str(int(sport))
dport = str(int(dport))
assert(len(password) > 0)
request = ":".join([sport, daddr, dport, password])
req = {
"source_port": int(sport),
"destination_address": daddr,
"destination_port": int(dport),
"password": password
}
ctrl = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
ctrl.connect(CTRL_SOCKET)
ctrl.send(request)
ctrl.send(json.dumps(req))
response = ctrl.recv(1024)
if response == "OK\n":
return True
else:
return False
res = json.loads(response)
return res
if __name__ == '__main__':
if not request_forwarding(*sys.argv[1:]):
sys.exit(1)
res = request_forwarding(*sys.argv[1:])
if res['status'] == "OK":
sys.exit(0)
else:
sys.exit(1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment