summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Young <sleepsonthefloor@gmail.com>2010-12-21 18:20:55 -0800
committerAnthony Young <sleepsonthefloor@gmail.com>2010-12-21 18:20:55 -0800
commita84e2b9131e4c8b212c9de0b9ad4931f7743ff75 (patch)
tree4addf9e5ed6a40dbde93bc06baed145eea2086ec
parent08963a0df7a6d1c90ba12ce60cbf15c93b0b70e6 (diff)
move prototype code from api into compute worker
-rw-r--r--nova/api/ec2/cloud.py49
-rw-r--r--nova/compute/manager.py2
-rw-r--r--nova/virt/libvirt_conn.py49
3 files changed, 55 insertions, 45 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index 09fdd32da..4c9d882f1 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -26,11 +26,8 @@ import base64
import datetime
import logging
import os
-import random
import re
-import subprocess
import time
-import uuid
from nova import context
import IPy
@@ -45,13 +42,10 @@ 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
@@ -466,44 +460,13 @@ 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_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,)
- # this Popen will exit with 0 only if the port is in use,
- # so a nonzero return value implies it is unused
- port_is_unused = (subprocess.Popen(cmd, shell=True).wait() != 0)
- if port_is_unused:
- return port
- raise 'Unable to find an open 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']
-
- 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)
+ output = rpc.call(context,
+ '%s.%s' % (FLAGS.compute_topic,
+ instance_ref['host']),
+ {"method": "get_ajax_console",
+ "args": {"instance_id": instance_ref['id']}})
- 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)}
+ return {"url": output }
def describe_volumes(self, context, **kwargs):
if context.user.is_admin():
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 0897eee45..1fc71d1e5 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -161,7 +161,7 @@ class ComputeManager(manager.Manager):
logging.debug("instance %s: getting ajax console", instance_id)
instance_ref = self.db.instance_get(context, instance_id)
- return self.driver.get_console_output(instance_ref)
+ return self.driver.get_ajax_console(instance_ref)
@defer.inlineCallbacks
@exception.wrap_exception
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index 509ed97a0..f2110e4e8 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -42,6 +42,10 @@ from nova.compute import disk
from nova.compute import instance_types
from nova.compute import power_state
from nova.virt import images
+import subprocess
+import random
+import uuid
+from xml.dom import minidom
libvirt = None
libxml2 = None
@@ -71,7 +75,9 @@ flags.DEFINE_string('libvirt_uri',
flags.DEFINE_bool('allow_project_net_traffic',
True,
'Whether to allow in project network traffic')
-
+flags.DEFINE_string('console_dmz',
+ 'tonbuntu:8000',
+ 'location of console proxy')
def get_connection(read_only):
# These are loaded late so that there's no need to install these
@@ -310,6 +316,47 @@ class LibvirtConnection(object):
d.addCallback(self._dump_file)
return d
+ @exception.wrap_exception
+ def get_ajax_console(self, instance):
+ 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,)
+ # this Popen will exit with 0 only if the port is in use,
+ # so a nonzero return value implies it is unused
+ port_is_unused = (subprocess.Popen(cmd, shell=True).wait() != 0)
+ if port_is_unused:
+ return port
+ raise 'Unable to find an open port'
+
+ def get_pty_for_instance(instance_name):
+ stdout, stderr = utils.execute('virsh dumpxml %s' % instance_name)
+ 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['host']
+
+ if FLAGS.libvirt_type == 'uml':
+ pass #FIXME
+ elif FLAGS.libvirt_type == 'xen':
+ pass #FIXME
+ else:
+ ajaxterm_cmd = 'socat - %s' % get_pty_for_instance(instance['name'])
+
+ cmd = '%s/tools/ajaxterm/ajaxterm.py --command "%s" -t %s -p %s' \
+ % (utils.novadir(), ajaxterm_cmd, token, port)
+
+ subprocess.Popen(cmd, shell=True)
+ return 'http://%s/?token=%s&host=%s&port=%s' \
+ % (FLAGS.console_dmz, token, host, port)
+
@defer.inlineCallbacks
def _create_image(self, inst, libvirt_xml):
# syntactic nicety