basics to get proxied ajaxterm working with virsh
This commit is contained in:
31
bin/nova-ajax-proxy
Executable file
31
bin/nova-ajax-proxy
Executable 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
40
nova/boto_extensions.py
Normal 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
|
||||
Reference in New Issue
Block a user