diff options
-rw-r--r-- | .rootkeys | 1 | ||||
-rw-r--r-- | tools/python/xen/xend/XendCheckpoint.py | 1 | ||||
-rw-r--r-- | tools/python/xen/xend/XendRoot.py | 27 | ||||
-rw-r--r-- | tools/python/xen/xend/server/SrvDaemon.py | 2 | ||||
-rw-r--r-- | tools/python/xen/xend/server/relocate.py | 125 |
5 files changed, 156 insertions, 0 deletions
@@ -866,6 +866,7 @@ 40c9c46925x-Rjb0Cv2f1-l2jZrPYg tools/python/xen/xend/server/netif.py 40c9c469ZqILEQ8x6yWy0_51jopiCg tools/python/xen/xend/server/params.py 4266169eI_oX3YBjwaeC0V-THBRnjg tools/python/xen/xend/server/pciif.py +4294a1bf8rMUcddot-B2-pOxORimOg tools/python/xen/xend/server/relocate.py 41ee5e8dq9NtihbL4nWKjuSLOhXPUg tools/python/xen/xend/server/usbif.py 40c9c469LNxLVizOUpOjEaTKKCm8Aw tools/python/xen/xend/sxp.py 40d05079aFRp6NQdo5wIh5Ly31c0cg tools/python/xen/xm/__init__.py diff --git a/tools/python/xen/xend/XendCheckpoint.py b/tools/python/xen/xend/XendCheckpoint.py index 66887efc2a..e3908df885 100644 --- a/tools/python/xen/xend/XendCheckpoint.py +++ b/tools/python/xen/xend/XendCheckpoint.py @@ -13,6 +13,7 @@ from struct import pack, unpack, calcsize from xen.util.xpopen import xPopen3 import xen.lowlevel.xc; xc = xen.lowlevel.xc.new() +from XendError import XendError from XendLogging import log SIGNATURE = "LinuxGuestRecord" diff --git a/tools/python/xen/xend/XendRoot.py b/tools/python/xen/xend/XendRoot.py index 74f736616c..cae7c7608c 100644 --- a/tools/python/xen/xend/XendRoot.py +++ b/tools/python/xen/xend/XendRoot.py @@ -51,12 +51,21 @@ class XendRoot: """Default interface address xend listens at. """ xend_address_default = '' + """Default for the flag indicating whether xend should run a relocation server.""" + xend_relocation_server_default = 'yes' + + """Default interface address the xend relocation server listens at. """ + xend_relocation_address_default = '' + """Default port xend serves HTTP at. """ xend_port_default = '8000' """Default port xend serves events at. """ xend_event_port_default = '8001' + """Default port xend serves relocation at. """ + xend_relocation_port_default = '8002' + """Default for the flag indicating whether xend should run a unix-domain server.""" xend_unix_server_default = 'yes' @@ -249,6 +258,11 @@ class XendRoot: """ return self.get_config_bool("xend-http-server", self.xend_http_server_default) + def get_xend_relocation_server(self): + """Get the flag indicating whether xend should run a relocation server. + """ + return self.get_config_bool("xend-relocation-server", self.xend_relocation_server_default) + def get_xend_port(self): """Get the port xend listens at for its HTTP interface. """ @@ -259,6 +273,11 @@ class XendRoot: """ return self.get_config_int('xend-event-port', self.xend_event_port_default) + def get_xend_relocation_port(self): + """Get the port xend listens at for connection to its relocation server. + """ + return self.get_config_int('xend-relocation-port', self.xend_relocation_port_default) + def get_xend_address(self): """Get the address xend listens at for its HTTP and event ports. This defaults to the empty string which allows all hosts to connect. @@ -267,6 +286,14 @@ class XendRoot: """ return self.get_config_value('xend-address', self.xend_address_default) + def get_xend_relocation_address(self): + """Get the address xend listens at for its HTTP and event ports. + This defaults to the empty string which allows all hosts to connect. + If this is set to 'localhost' only the localhost will be able to connect + to the HTTP and event ports. + """ + return self.get_config_value('xend-relocation-address', self.xend_relocation_address_default) + def get_xend_unix_server(self): """Get the flag indicating whether xend should run a unix-domain server. """ diff --git a/tools/python/xen/xend/server/SrvDaemon.py b/tools/python/xen/xend/server/SrvDaemon.py index 85c1c23560..6e297b92fa 100644 --- a/tools/python/xen/xend/server/SrvDaemon.py +++ b/tools/python/xen/xend/server/SrvDaemon.py @@ -30,6 +30,7 @@ from xen.xend.XendLogging import log import channel import controller import event +import relocate from params import * DAEMONIZE = 0 @@ -302,6 +303,7 @@ class Daemon: log.info("Xend Daemon started") self.createFactories() event.listenEvent(self) + relocate.listenRelocation() self.listenChannels() servers = SrvServer.create() self.daemonize() diff --git a/tools/python/xen/xend/server/relocate.py b/tools/python/xen/xend/server/relocate.py new file mode 100644 index 0000000000..f41872c385 --- /dev/null +++ b/tools/python/xen/xend/server/relocate.py @@ -0,0 +1,125 @@ +import sys +import StringIO + +from xen.web import reactor, protocol + +from xen.xend import scheduler +from xen.xend import sxp +from xen.xend import EventServer; eserver = EventServer.instance() +from xen.xend.XendError import XendError +from xen.xend import XendRoot; xroot = XendRoot.instance() +from xen.xend.XendLogging import log +from xen.xend import XendCheckpoint + +DEBUG = 0 + +class RelocationProtocol(protocol.Protocol): + """Asynchronous handler for a connected relocation socket. + """ + + def __init__(self): + #protocol.Protocol.__init__(self) + self.parser = sxp.Parser() + + def dataReceived(self, data): + try: + self.parser.input(data) + if self.parser.ready(): + val = self.parser.get_val() + res = self.dispatch(val) + self.send_result(res) + if self.parser.at_eof(): + self.loseConnection() + except SystemExit: + raise + except: + self.send_error() + + def loseConnection(self): + if self.transport: + self.transport.loseConnection() + if self.connected: + scheduler.now(self.connectionLost) + + def connectionLost(self, reason=None): + pass + + def send_reply(self, sxpr): + io = StringIO.StringIO() + sxp.show(sxpr, out=io) + print >> io + io.seek(0) + if self.transport: + return self.transport.write(io.getvalue()) + else: + return 0 + + def send_result(self, res): + if res is None: + resp = ['ok'] + else: + resp = ['ok', res] + return self.send_reply(resp) + + def send_error(self): + (extype, exval) = sys.exc_info()[:2] + return self.send_reply(['err', + ['type', str(extype)], + ['value', str(exval)]]) + + def opname(self, name): + return 'op_' + name.replace('.', '_') + + def operror(self, name, req): + raise XendError('Invalid operation: ' +name) + + def dispatch(self, req): + op_name = sxp.name(req) + op_method_name = self.opname(op_name) + op_method = getattr(self, op_method_name, self.operror) + return op_method(op_name, req) + + def op_help(self, name, req): + def nameop(x): + if x.startswith('op_'): + return x[3:].replace('_', '.') + else: + return x + + l = [ nameop(k) for k in dir(self) if k.startswith('op_') ] + return l + + def op_quit(self, name, req): + self.loseConnection() + + def op_receive(self, name, req): + if self.transport: + self.send_reply(["ready", name]) + self.transport.sock.setblocking(1) + xd = xroot.get_component("xen.xend.XendDomain") + XendCheckpoint.restore(xd, self.transport.sock.fileno()) + self.transport.sock.setblocking(0) + else: + log.error(name + ": no transport") + raise XendError(name + ": no transport") + +class RelocationFactory(protocol.ServerFactory): + """Asynchronous handler for the relocation server socket. + """ + + def __init__(self): + #protocol.ServerFactory.__init__(self) + pass + + def buildProtocol(self, addr): + return RelocationProtocol() + +def listenRelocation(): + factory = RelocationFactory() + if xroot.get_xend_unix_server(): + path = '/var/lib/xend/relocation-socket' + reactor.listenUNIX(path, factory) + if xroot.get_xend_relocation_server(): + port = xroot.get_xend_relocation_port() + interface = xroot.get_xend_relocation_address() + reactor.listenTCP(port, factory, interface=interface) |