basics to get proxied ajaxterm working with virsh

This commit is contained in:
root
2010-11-01 16:25:56 -07:00
parent d164cf44c0
commit 1c51f4e8ab
2 changed files with 71 additions and 0 deletions

31
bin/nova-ajax-proxy Executable file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/python
from twisted.internet import reactor
from twisted.web import http
from twisted.web.proxy import Proxy, ProxyRequest
import urlparse, exceptions
class AjaxProxyRequest(ProxyRequest):
def process(self):
if 'referer' in self.received_headers:
auth_uri = self.received_headers['referer']
else:
auth_uri = self.uri
try:
auth_params = urlparse.parse_qs(urlparse.urlparse(auth_uri).query)
parsed_uri = urlparse.urlparse(self.uri)
self.uri = "http://%s:%s%s?%s"% (auth_params['host'][0], auth_params['port'][0], parsed_uri.path, parsed_uri.query)
ProxyRequest.process(self)
except (exceptions.KeyError):
pass
class AjaxProxy(Proxy):
requestFactory = AjaxProxyRequest
factory = http.HTTPFactory()
factory.protocol = AjaxProxy
reactor.listenTCP(8000, factory)
reactor.run()

40
nova/boto_extensions.py Normal file
View File

@@ -0,0 +1,40 @@
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