diff options
| author | root <root@tonbuntu> | 2010-09-17 19:28:10 -0700 |
|---|---|---|
| committer | root <root@tonbuntu> | 2010-09-17 19:28:10 -0700 |
| commit | 4ee5ef25dcaa9d4235e97972acdbbcbf5067d88c (patch) | |
| tree | bf34cb86fcc54b8fd5e75b07c0a8cda76ec79264 /nova | |
| parent | 7b74343f2be9b49c0c359e00c64cf26b3da1cf44 (diff) | |
| download | nova-4ee5ef25dcaa9d4235e97972acdbbcbf5067d88c.tar.gz nova-4ee5ef25dcaa9d4235e97972acdbbcbf5067d88c.tar.xz nova-4ee5ef25dcaa9d4235e97972acdbbcbf5067d88c.zip | |
add in support for ajaxterm console access
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/adminclient.py | 22 | ||||
| -rw-r--r-- | nova/endpoint/admin.py | 29 | ||||
| -rw-r--r-- | nova/utils.py | 4 |
3 files changed, 55 insertions, 0 deletions
diff --git a/nova/adminclient.py b/nova/adminclient.py index 0ca32b1e5..9670b7186 100644 --- a/nova/adminclient.py +++ b/nova/adminclient.py @@ -24,6 +24,19 @@ import base64 import boto from boto.ec2.regioninfo import RegionInfo +class ConsoleInfo(object): + def __init__(self, connection=None, endpoint=None): + self.connection = connection + self.endpoint = endpoint + + def startElement(self, name, attrs, connection): + return None + + def endElement(self, name, value, connection): + if name == 'url': + self.url = str(value) + if name == 'kind': + self.url = str(value) class UserInfo(object): """ @@ -349,3 +362,12 @@ class NovaAdminClient(object): def get_hosts(self): return self.apiconn.get_list('DescribeHosts', {}, [('item', HostInfo)]) + def create_console(self, instance_id, kind='ajax'): + """ + Create a console + """ + console = self.apiconn.get_object('CreateConsole', {'Kind': kind, 'InstanceId': instance_id}, ConsoleInfo) + + if console.url != None: + return console + diff --git a/nova/endpoint/admin.py b/nova/endpoint/admin.py index 3d91c66dc..686e462b5 100644 --- a/nova/endpoint/admin.py +++ b/nova/endpoint/admin.py @@ -21,10 +21,14 @@ Admin API controller, exposed through http via the api worker. """ import base64 +import uuid +import subprocess +import random from nova import db from nova import exception from nova.auth import manager +from utils import novadir def user_dict(user, base64_file=None): @@ -211,3 +215,28 @@ class AdminController(object): def describe_host(self, _context, name, **_kwargs): """Returns status info for single node.""" return host_dict(db.host_get(name)) + + @admin_only + def create_console(self, _context, kind, instance_id, **_kwargs): + """Create a Console""" + #instance = db.instance_get(_context, instance_id) + host = '127.0.0.1' + + def get_port(): + for i in range(0,100): # don't loop forever + port = int(random.uniform(10000, 12000)) + cmd = "netcat 0.0.0.0 " + str(port) + " -w 2 < /dev/null" + # 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() + if port_is_unused: + return port + raise 'Unable to find an open port' + + port = str(get_port()) + token = str(uuid.uuid4()) + cmd = novadir() + "tools/ajaxterm//ajaxterm.py --command 'ssh root@" + host + "' -t " \ + + token + " -p " + port + port_is_unused = subprocess.Popen(cmd, shell=True) + return {'url': 'http://tonbuntu:' + port + '/?token=' + token } + diff --git a/nova/utils.py b/nova/utils.py index 536d722bb..ed703a9db 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -92,6 +92,10 @@ def abspath(s): return os.path.join(os.path.dirname(__file__), s) +def novadir(s): + return os.path.abspath(nova.__file__).split('nova/__init__.pyc')[0] + + def default_flagfile(filename='nova.conf'): for arg in sys.argv: if arg.find('flagfile') != -1: |
