consolidate boto_extensions.py and euca-get-ajax-console, fix bugs
from previous trunk merge
This commit is contained in:
		@@ -24,6 +24,7 @@ from eventlet import greenthread
 | 
			
		||||
from eventlet.green import urllib2
 | 
			
		||||
 | 
			
		||||
import exceptions
 | 
			
		||||
import gettext
 | 
			
		||||
import logging
 | 
			
		||||
import os
 | 
			
		||||
import sys
 | 
			
		||||
@@ -38,9 +39,12 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
 | 
			
		||||
if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
 | 
			
		||||
    sys.path.insert(0, possible_topdir)
 | 
			
		||||
 | 
			
		||||
gettext.install('nova', unicode=1)
 | 
			
		||||
 | 
			
		||||
from nova import flags
 | 
			
		||||
from nova import utils
 | 
			
		||||
from nova import log as logging
 | 
			
		||||
from nova import rpc
 | 
			
		||||
from nova import utils
 | 
			
		||||
from nova import wsgi
 | 
			
		||||
 | 
			
		||||
FLAGS = flags.FLAGS
 | 
			
		||||
@@ -48,6 +52,10 @@ FLAGS = flags.FLAGS
 | 
			
		||||
flags.DEFINE_integer('ajax_console_idle_timeout', 300,
 | 
			
		||||
                     'Seconds before idle connection destroyed')
 | 
			
		||||
 | 
			
		||||
LOG = logging.getLogger('nova.ajax_console_proxy')
 | 
			
		||||
LOG.setLevel(logging.DEBUG)
 | 
			
		||||
LOG.addHandler(logging.StreamHandler())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AjaxConsoleProxy(object):
 | 
			
		||||
    tokens = {}
 | 
			
		||||
@@ -83,6 +91,9 @@ class AjaxConsoleProxy(object):
 | 
			
		||||
            start_response("200 OK", info.dict.items())
 | 
			
		||||
            return body
 | 
			
		||||
        except (exceptions.KeyError):
 | 
			
		||||
            if env['PATH_INFO'] != '/favicon.ico':
 | 
			
		||||
                LOG.audit("Unauthorized request %s, %s"
 | 
			
		||||
                          % (req_url, str(env)))
 | 
			
		||||
            start_response("401 NOT AUTHORIZED", [])
 | 
			
		||||
            return "Not Authorized"
 | 
			
		||||
        except Exception:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,40 +0,0 @@
 | 
			
		||||
import base64
 | 
			
		||||
import boto
 | 
			
		||||
from boto.ec2.connection import EC2Connection
 | 
			
		||||
 | 
			
		||||
class AjaxConsole:
 | 
			
		||||
    def __init__(self, parent=None):
 | 
			
		||||
        self.parent = parent
 | 
			
		||||
        self.instance_id = None
 | 
			
		||||
        self.url = None
 | 
			
		||||
 | 
			
		||||
    def startElement(self, name, attrs, connection):
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
    def endElement(self, name, value, connection):
 | 
			
		||||
        if name == 'instanceId':
 | 
			
		||||
            self.instance_id = value
 | 
			
		||||
        elif name == 'url':
 | 
			
		||||
            self.url = value
 | 
			
		||||
        else:
 | 
			
		||||
            setattr(self, name, value)
 | 
			
		||||
 | 
			
		||||
class NovaEC2Connection(EC2Connection):
 | 
			
		||||
    def get_ajax_console(self, instance_id):
 | 
			
		||||
        """
 | 
			
		||||
        Retrieves a console connection for the specified instance.
 | 
			
		||||
 | 
			
		||||
        :type instance_id: string
 | 
			
		||||
        :param instance_id: The instance ID of a running instance on the cloud.
 | 
			
		||||
 | 
			
		||||
        :rtype: :class:`AjaxConsole`
 | 
			
		||||
        """
 | 
			
		||||
        params = {}
 | 
			
		||||
        self.build_list_params(params, [instance_id], 'InstanceId')
 | 
			
		||||
        return self.get_object('GetAjaxConsole', params, AjaxConsole)
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
def override_connect_ec2(aws_access_key_id=None, aws_secret_access_key=None, **kwargs):
 | 
			
		||||
    return NovaEC2Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
 | 
			
		||||
 | 
			
		||||
boto.connect_ec2 = override_connect_ec2
 | 
			
		||||
		Reference in New Issue
	
	Block a user