[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] SrvDaemon.py, XendRoot.py, relocate.py:



ChangeSet 1.1550.1.2, 2005/05/25 17:04:01+01:00, cl349@xxxxxxxxxxxxxxxxxxxx

        SrvDaemon.py, XendRoot.py, relocate.py:
          Add relocation server.
        XendCheckpoint.py:
          Import XendError.
        Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>



 XendCheckpoint.py   |    1 
 XendRoot.py         |   27 +++++++++++
 server/SrvDaemon.py |    2 
 server/relocate.py  |  125 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 155 insertions(+)


diff -Nru a/tools/python/xen/xend/XendCheckpoint.py 
b/tools/python/xen/xend/XendCheckpoint.py
--- a/tools/python/xen/xend/XendCheckpoint.py   2005-05-25 14:02:09 -04:00
+++ b/tools/python/xen/xend/XendCheckpoint.py   2005-05-25 14:02:09 -04:00
@@ -13,6 +13,7 @@
 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 -Nru a/tools/python/xen/xend/XendRoot.py 
b/tools/python/xen/xend/XendRoot.py
--- a/tools/python/xen/xend/XendRoot.py 2005-05-25 14:02:09 -04:00
+++ b/tools/python/xen/xend/XendRoot.py 2005-05-25 14:02:09 -04:00
@@ -51,12 +51,21 @@
     """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 @@
         """
         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 @@
         """
         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.
@@ -266,6 +285,14 @@
         to the HTTP and event ports.
         """
         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 -Nru a/tools/python/xen/xend/server/SrvDaemon.py 
b/tools/python/xen/xend/server/SrvDaemon.py
--- a/tools/python/xen/xend/server/SrvDaemon.py 2005-05-25 14:02:09 -04:00
+++ b/tools/python/xen/xend/server/SrvDaemon.py 2005-05-25 14:02:09 -04:00
@@ -30,6 +30,7 @@
 import channel
 import controller
 import event
+import relocate
 from params import *
 
 DAEMONIZE = 0
@@ -302,6 +303,7 @@
             log.info("Xend Daemon started")
             self.createFactories()
             event.listenEvent(self)
+            relocate.listenRelocation()
             self.listenChannels()
             servers = SrvServer.create()
             self.daemonize()
diff -Nru a/tools/python/xen/xend/server/relocate.py 
b/tools/python/xen/xend/server/relocate.py
--- /dev/null   Wed Dec 31 16:00:00 196900
+++ b/tools/python/xen/xend/server/relocate.py  2005-05-25 14:02:09 -04:00
@@ -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)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.