Commit 152d7c69 authored by Giorgos Verigakis's avatar Giorgos Verigakis
Browse files

Merge branch 'api-current' of https://code.grnet.gr/git/synnefo into api-current

parents ab707096 5ecfd413
......@@ -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