bitkeeper revision 1.1550.1.2 (4294a1f1_I9jQ97QY8OTqDCx1kDIUA)

SrvDaemon.py, XendRoot.py, relocate.py:
  Add relocation server.
XendCheckpoint.py:
  Import XendError.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
This commit is contained in:
cl349@firebug.cl.cam.ac.uk committed 2005-05-25 16:04:01 +00:00
1 parent 1c31240ab2
commit 8553e6167e
5 files changed
+156

No files matched your search

+1
View File
@@ -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"
+27
View File
@@ -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.
"""
@@ -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()
+125
View File
@@ -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)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.