From 08963a0df7a6d1c90ba12ce60cbf15c93b0b70e6 Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Tue, 21 Dec 2010 14:44:53 -0800 Subject: prototype works with kvm. now moving call from api to compute --- nova/api/ec2/cloud.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 469331a66..09fdd32da 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -27,6 +27,7 @@ import datetime import logging import os import random +import re import subprocess import time import uuid @@ -44,10 +45,13 @@ from nova import utils from nova.compute.instance_types import INSTANCE_TYPES from nova.api import cloud from nova.api.ec2 import images +from nova.virt import libvirt_conn +from xml.dom import minidom FLAGS = flags.FLAGS flags.DECLARE('storage_availability_zone', 'nova.volume.manager') +flags.DEFINE_string("console_dmz", "tonbuntu:8000", "location of console proxy") InvalidInputException = exception.InvalidInputException @@ -454,6 +458,7 @@ class CloudController(object): return {"InstanceId": ec2_id, "Timestamp": now, "output": base64.b64encode(output)} + def get_ajax_console(self, context, instance_id, **kwargs): """Create an AJAX Console""" @@ -461,7 +466,7 @@ class CloudController(object): internal_id = ec2_id_to_internal_id(ec2_id) instance_ref = db.instance_get_by_internal_id(context, internal_id) - def get_port(): + def get_open_port(): for i in xrange(0,100): # don't loop forever port = random.randint(10000, 12000) cmd = "netcat 0.0.0.0 %s -w 2 < /dev/null" % (port,) @@ -472,15 +477,33 @@ class CloudController(object): return port raise 'Unable to find an open port' - port = get_port() + def get_pty_for_instance(instance_id): + stdout, stderr = utils.execute('virsh dumpxml instance-%d' % int(instance_id)) + dom = minidom.parseString(stdout) + serials = dom.getElementsByTagName('serial') + for serial in serials: + if serial.getAttribute('type') == 'pty': + source = serial.getElementsByTagName('source')[0] + return source.getAttribute('path') + + port = get_open_port() token = str(uuid.uuid4()) host = instance_ref['host'] - cmd = "%s/tools/ajaxterm/ajaxterm.py --command 'virsh console instance-%d' -t %s -p %s" \ - % (utils.novadir(), internal_id, token, port) - port_is_unused = subprocess.Popen(cmd, shell=True) #TODO error check - dmz = 'tonbuntu' #TODO put correct value for dmz - return {'url': 'http://%s:%s/?token=%s&host=%s&port=%s' % (dmz, 8000, token, host, port)} + + if FLAGS.libvirt_type == 'uml': + pass #FIXME + elif FLAGS.libvirt_type == 'xen': + pass #FIXME + else: + ajaxterm_cmd = 'socat - %s' % get_pty_for_instance(internal_id) + + cmd = "%s/tools/ajaxterm/ajaxterm.py --command '%s' -t %s -p %s" \ + % (utils.novadir(), ajaxterm_cmd, token, port) + + subprocess.Popen(cmd, shell=True) + FLAGS.console_dmz = 'tonbuntu:8000' + return {'url': 'http://%s/?token=%s&host=%s&port=%s' % (FLAGS.console_dmz, token, host, port)} def describe_volumes(self, context, **kwargs): if context.user.is_admin(): -- cgit