direct-io.hg
changeset 4097:552e3748f0e7
bitkeeper revision 1.1159.269.1 (42319894M6nLc3wwj0MrCHle52x6Cg)
Merge xenbk@gandalf:/var/bk/xen-2.0-testing.bk
into wray-m-3.hpl.hp.com:/home/mjw/repos-bk/xen-2.0-testing.bk
Merge xenbk@gandalf:/var/bk/xen-2.0-testing.bk
into wray-m-3.hpl.hp.com:/home/mjw/repos-bk/xen-2.0-testing.bk
author | mjw@wray-m-3.hpl.hp.com |
---|---|
date | Fri Mar 11 13:09:40 2005 +0000 (2005-03-11) |
parents | b8af04b0a34c 6cf7424f52f1 |
children | c7837f5059f1 c738e3f51a55 |
files | tools/examples/xend-config.sxp tools/python/xen/xend/Args.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/server/SrvBase.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/SrvDir.py tools/python/xen/xend/server/console.py tools/python/xen/xend/server/params.py |
line diff
1.1 --- a/tools/examples/xend-config.sxp Thu Mar 10 18:09:19 2005 +0000 1.2 +++ b/tools/examples/xend-config.sxp Fri Mar 11 13:09:40 2005 +0000 1.3 @@ -3,11 +3,23 @@ 1.4 # Port xend should use for the HTTP interface. 1.5 (xend-port 8000) 1.6 1.7 -# Address xend should listen on. 1.8 +# Port xend should use for the event interface. 1.9 +(xend-event-port 8001) 1.10 + 1.11 +# Address xend should listen on for HTTP connections. 1.12 # Specifying 'localhost' prevents remote connections. 1.13 # Specifying the empty string '' allows all connections. 1.14 (xend-address '') 1.15 1.16 +# The port xend should start from when allocating a port 1.17 +# for a domain console. 1.18 +(console-port-base 9600) 1.19 + 1.20 +# Address xend should listen on for console connections. 1.21 +# Specifying 'localhost' prevents remote connections. 1.22 +# Specifying the empty string '' allows all connections. 1.23 +(console-address '') 1.24 + 1.25 ## Use the following if VIF traffic is routed. 1.26 # The script used to start/stop networking for xend. 1.27 #(network-script network-route)
2.1 --- a/tools/python/xen/xend/Args.py Thu Mar 10 18:09:19 2005 +0000 2.2 +++ b/tools/python/xen/xend/Args.py Fri Mar 11 13:09:40 2005 +0000 2.3 @@ -78,6 +78,8 @@ class Args: 2.4 val = str(v) 2.5 elif type == 'sxpr': 2.6 val = self.sxpr(v) 2.7 + elif type == 'bool': 2.8 + val = self.bool(v) 2.9 else: 2.10 raise ArgError('invalid type:' + str(type)) 2.11 return val 2.12 @@ -86,6 +88,9 @@ class Args: 2.13 except StandardError, ex: 2.14 raise ArgError(str(ex)) 2.15 2.16 + def bool(self, v): 2.17 + return (v.lower() in ['on', 'yes', '1', 'true']) 2.18 + 2.19 def sxpr(self, v): 2.20 if isinstance(v, types.ListType): 2.21 val = v
3.1 --- a/tools/python/xen/xend/XendRoot.py Thu Mar 10 18:09:19 2005 +0000 3.2 +++ b/tools/python/xen/xend/XendRoot.py Fri Mar 11 13:09:40 2005 +0000 3.3 @@ -2,6 +2,11 @@ 3.4 3.5 """Xend root class. 3.6 Creates the event server and handles configuration. 3.7 + 3.8 +Other classes get config variables by importing this module, 3.9 +using instance() to get a XendRoot instance, and then 3.10 +the config functions (e.g. get_xend_port()) to get 3.11 +configured values. 3.12 """ 3.13 3.14 import os 3.15 @@ -34,17 +39,33 @@ class XendRoot: 3.16 """Where block control scripts live.""" 3.17 block_script_dir = "/etc/xen/scripts" 3.18 3.19 + """Default path to the log file. """ 3.20 logfile_default = "/var/log/xend.log" 3.21 3.22 loglevel_default = 'DEBUG' 3.23 3.24 + """Default interface address xend listens at. """ 3.25 + xend_address_default = '' 3.26 + 3.27 + """Default port xend serves HTTP at. """ 3.28 + xend_port_default = '8000' 3.29 + 3.30 + """Default port xend serves events at. """ 3.31 + xend_event_port_default = '8001' 3.32 + 3.33 + """Default inteface address xend listens at for consoles.""" 3.34 + console_address_default = '' 3.35 + 3.36 + """Default port xend serves consoles at. """ 3.37 + console_port_base_default = '9600' 3.38 + 3.39 components = {} 3.40 3.41 def __init__(self): 3.42 self.dbroot = None 3.43 self.config_path = None 3.44 self.config = None 3.45 - self.logger = None 3.46 + self.logging = None 3.47 self.configure() 3.48 eserver.subscribe('xend.*', self.event_handler) 3.49 #eserver.subscribe('xend.domain.created', self.event_handler) 3.50 @@ -73,9 +94,9 @@ class XendRoot: 3.51 3.52 def _format(self, msg, args): 3.53 if args: 3.54 - return str(msg) 3.55 + return str(msg) % args 3.56 else: 3.57 - return str(msg) % args 3.58 + return str(msg) 3.59 3.60 def _log(self, mode, fmt, args): 3.61 """Logging function that uses the logger if it exists, otherwise 3.62 @@ -90,7 +111,7 @@ class XendRoot: 3.63 if log: 3.64 getattr(log, mode)(fmt, *args) 3.65 else: 3.66 - print >>stderr, "xend", "[%s]" % level, self._format(msg, args) 3.67 + print >>sys.stderr, "xend", "[%s]" % level, self._format(fmt, args) 3.68 3.69 def logDebug(self, fmt, *args): 3.70 """Log a debug message. 3.71 @@ -132,7 +153,6 @@ class XendRoot: 3.72 self.configure_logger() 3.73 self.dbroot = self.get_config_value("dbroot", self.dbroot_default) 3.74 3.75 - 3.76 def configure_logger(self): 3.77 logfile = self.get_config_value("logfile", self.logfile_default) 3.78 loglevel = self.get_config_value("loglevel", self.loglevel_default) 3.79 @@ -146,7 +166,7 @@ class XendRoot: 3.80 def get_logger(self): 3.81 """Get the logger. 3.82 """ 3.83 - return self.logging.getLogger() 3.84 + return self.logging and self.logging.getLogger() 3.85 3.86 def get_dbroot(self): 3.87 """Get the path to the database root. 3.88 @@ -160,14 +180,20 @@ class XendRoot: 3.89 """ 3.90 self.config_path = os.getenv(self.config_var, self.config_default) 3.91 if os.path.exists(self.config_path): 3.92 - fin = file(self.config_path, 'rb') 3.93 + #self.logInfo('Reading config file %s', self.config_path) 3.94 try: 3.95 - config = sxp.parse(fin) 3.96 + fin = file(self.config_path, 'rb') 3.97 + try: 3.98 + config = sxp.parse(fin) 3.99 + finally: 3.100 + fin.close() 3.101 config.insert(0, 'xend-config') 3.102 self.config = config 3.103 - finally: 3.104 - fin.close() 3.105 + except Exception, ex: 3.106 + self.logError('Reading config file %s: %s', self.config_path, str(ex)) 3.107 + raise 3.108 else: 3.109 + self.logError('Config file does not exist: %s', self.config_path) 3.110 self.config = ['xend-config'] 3.111 3.112 def get_config(self, name=None): 3.113 @@ -193,10 +219,35 @@ class XendRoot: 3.114 return sxp.child_value(self.config, name, val=val) 3.115 3.116 def get_xend_port(self): 3.117 - return int(self.get_config_value('xend-port', '8000')) 3.118 + """Get the port xend listens at for its HTTP interface. 3.119 + """ 3.120 + return int(self.get_config_value('xend-port', self.xend_port_default)) 3.121 + 3.122 + def get_xend_event_port(self): 3.123 + """Get the port xend listens at for connection to its event server. 3.124 + """ 3.125 + return int(self.get_config_value('xend-event-port', self.xend_event_port_default)) 3.126 3.127 def get_xend_address(self): 3.128 - return self.get_config_value('xend-address', '') 3.129 + """Get the address xend listens at for its HTTP and event ports. 3.130 + This defaults to the empty string which allows all hosts to connect. 3.131 + If this is set to 'localhost' only the localhost will be able to connect 3.132 + to the HTTP and event ports. 3.133 + """ 3.134 + return self.get_config_value('xend-address', self.xend_address_default) 3.135 + 3.136 + def get_console_address(self): 3.137 + """Get the address xend listens at for its console ports. 3.138 + This defaults to the empty string which allows all hosts to connect. 3.139 + If this is set to 'localhost' only the localhost will be able to connect 3.140 + to the console ports. 3.141 + """ 3.142 + return self.get_config_value('console-address', self.console_address_default) 3.143 + 3.144 + def get_console_port_base(self): 3.145 + """Get the base port number used to generate console ports for domains. 3.146 + """ 3.147 + return int(self.get_config_value('console-port-base', self.console_port_base_default)) 3.148 3.149 def get_block_script(self, type): 3.150 return self.get_config_value('block-%s' % type, '')
4.1 --- a/tools/python/xen/xend/server/SrvBase.py Thu Mar 10 18:09:19 2005 +0000 4.2 +++ b/tools/python/xen/xend/server/SrvBase.py Fri Mar 11 13:09:40 2005 +0000 4.3 @@ -106,7 +106,8 @@ class SrvBase(resource.Resource): 4.4 try: 4.5 val = op_method(op, req) 4.6 except Exception, err: 4.7 - return self._perform_err(err, op, req) 4.8 + self._perform_err(err, op, req) 4.9 + return '' 4.10 4.11 if isinstance(val, defer.Deferred): 4.12 val.addCallback(self._perform_cb, op, req, dfr=1)
5.1 --- a/tools/python/xen/xend/server/SrvDaemon.py Thu Mar 10 18:09:19 2005 +0000 5.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py Fri Mar 11 13:09:40 2005 +0000 5.3 @@ -596,10 +596,10 @@ class Daemon: 5.4 def set_user(self): 5.5 # Set the UID. 5.6 try: 5.7 - os.setuid(pwd.getpwnam(USER)[2]) 5.8 + os.setuid(pwd.getpwnam(XEND_USER)[2]) 5.9 return 0 5.10 except KeyError, error: 5.11 - print "Error: no such user '%s'" % USER 5.12 + print "Error: no such user '%s'" % XEND_USER 5.13 return 1 5.14 5.15 def stop(self): 5.16 @@ -609,7 +609,7 @@ class Daemon: 5.17 xroot = XendRoot.instance() 5.18 log.info("Xend Daemon started") 5.19 self.createFactories() 5.20 - self.listenEvent() 5.21 + self.listenEvent(xroot) 5.22 self.listenNotifier() 5.23 self.listenVirq() 5.24 SrvServer.create(bridge=1) 5.25 @@ -622,9 +622,11 @@ class Daemon: 5.26 self.netifCF = netif.NetifControllerFactory() 5.27 self.consoleCF = console.ConsoleControllerFactory() 5.28 5.29 - def listenEvent(self): 5.30 + def listenEvent(self, xroot): 5.31 protocol = EventFactory(self) 5.32 - return reactor.listenTCP(EVENT_PORT, protocol) 5.33 + port = xroot.get_xend_event_port() 5.34 + interface = xroot.get_xend_address() 5.35 + return reactor.listenTCP(port, protocol, interface=interface) 5.36 5.37 def listenNotifier(self): 5.38 protocol = NotifierProtocol(self.channelF)
6.1 --- a/tools/python/xen/xend/server/SrvDir.py Thu Mar 10 18:09:19 2005 +0000 6.2 +++ b/tools/python/xen/xend/server/SrvDir.py Fri Mar 11 13:09:40 2005 +0000 6.3 @@ -88,7 +88,7 @@ class SrvDir(SrvBase): 6.4 req.write('</body></html>') 6.5 return '' 6.6 except Exception, ex: 6.7 - self._perform_err(ex, req) 6.8 + self._perform_err(ex, "GET", req) 6.9 6.10 def ls(self, req, use_sxp=0): 6.11 url = req.prePathURL()
7.1 --- a/tools/python/xen/xend/server/console.py Thu Mar 10 18:09:19 2005 +0000 7.2 +++ b/tools/python/xen/xend/server/console.py Fri Mar 11 13:09:40 2005 +0000 7.3 @@ -11,6 +11,8 @@ from xen.xend.XendError import XendError 7.4 from xen.xend import EventServer 7.5 eserver = EventServer.instance() 7.6 from xen.xend.XendLogging import log 7.7 +from xen.xend import XendRoot 7.8 +xroot = XendRoot.instance() 7.9 7.10 import controller 7.11 from messages import * 7.12 @@ -191,7 +193,8 @@ class ConsoleController(controller.Contr 7.13 pass 7.14 else: 7.15 f = ConsoleFactory(self, self.idx) 7.16 - self.listener = reactor.listenTCP(self.console_port, f) 7.17 + interface = xroot.get_console_address() 7.18 + self.listener = reactor.listenTCP(self.console_port, f, interface=interface) 7.19 7.20 def connect(self, addr, conn): 7.21 """Connect a TCP connection to the console.
8.1 --- a/tools/python/xen/xend/server/params.py Thu Mar 10 18:09:19 2005 +0000 8.2 +++ b/tools/python/xen/xend/server/params.py Fri Mar 11 13:09:40 2005 +0000 8.3 @@ -3,9 +3,5 @@ XEND_PID_FILE = '/var/run/xend.pid' 8.4 XFRD_PID_FILE = '/var/run/xfrd.pid' 8.5 XEND_TRACE_FILE = '/var/log/xend.trace' 8.6 8.7 -USER = 'root' 8.8 +XEND_USER = 'root' 8.9 8.10 -EVENT_PORT = 8001 8.11 - 8.12 -CONSOLE_PORT_BASE = 9600 8.13 -