ia64/xen-unstable

changeset 4095:2f9077bf40da

bitkeeper revision 1.1159.265.2 (42319500DXIXjiTkjszNpliySomMvA)

Add support for setting the listen address for consoles
and the event port.

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Fri Mar 11 12:54:24 2005 +0000 (2005-03-11)
parents 8a0070a6f1b6
children 6cf7424f52f1
files tools/examples/xend-config.sxp tools/python/xen/xend/XendRoot.py tools/python/xen/xend/server/SrvDaemon.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 14:53:08 2005 +0000
     1.2 +++ b/tools/examples/xend-config.sxp	Fri Mar 11 12:54:24 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/XendRoot.py	Thu Mar 10 14:53:08 2005 +0000
     2.2 +++ b/tools/python/xen/xend/XendRoot.py	Fri Mar 11 12:54:24 2005 +0000
     2.3 @@ -2,6 +2,11 @@
     2.4  
     2.5  """Xend root class.
     2.6  Creates the event server and handles configuration.
     2.7 +
     2.8 +Other classes get config variables by importing this module,
     2.9 +using instance() to get a XendRoot instance, and then
    2.10 +the config functions (e.g. get_xend_port()) to get
    2.11 +configured values.
    2.12  """
    2.13  
    2.14  import os
    2.15 @@ -34,17 +39,33 @@ class XendRoot:
    2.16      """Where block control scripts live."""
    2.17      block_script_dir = "/etc/xen/scripts"
    2.18  
    2.19 +    """Default path to the log file. """
    2.20      logfile_default = "/var/log/xend.log"
    2.21  
    2.22      loglevel_default = 'DEBUG'
    2.23  
    2.24 +    """Default interface address xend listens at. """
    2.25 +    xend_address_default      = ''
    2.26 +
    2.27 +    """Default port xend serves HTTP at. """
    2.28 +    xend_port_default         = '8000'
    2.29 +
    2.30 +    """Default port xend serves events at. """
    2.31 +    xend_event_port_default   = '8001'
    2.32 +
    2.33 +    """Default inteface address xend listens at for consoles."""
    2.34 +    console_address_default   = ''
    2.35 +
    2.36 +    """Default port xend serves consoles at. """
    2.37 +    console_port_base_default = '9600'
    2.38 +
    2.39      components = {}
    2.40  
    2.41      def __init__(self):
    2.42          self.dbroot = None
    2.43          self.config_path = None
    2.44          self.config = None
    2.45 -        self.logger = None
    2.46 +        self.logging = None
    2.47          self.configure()
    2.48          eserver.subscribe('xend.*', self.event_handler)
    2.49          #eserver.subscribe('xend.domain.created', self.event_handler)
    2.50 @@ -73,9 +94,9 @@ class XendRoot:
    2.51  
    2.52      def _format(self, msg, args):
    2.53          if args:
    2.54 -            return str(msg)
    2.55 +            return str(msg) % args
    2.56          else:
    2.57 -            return str(msg) % args
    2.58 +            return str(msg)
    2.59  
    2.60      def _log(self, mode, fmt, args):
    2.61          """Logging function that uses the logger if it exists, otherwise
    2.62 @@ -90,7 +111,7 @@ class XendRoot:
    2.63          if log:
    2.64              getattr(log, mode)(fmt, *args)
    2.65          else:
    2.66 -            print >>stderr, "xend", "[%s]" % level, self._format(msg, args)
    2.67 +            print >>sys.stderr, "xend", "[%s]" % level, self._format(fmt, args)
    2.68  
    2.69      def logDebug(self, fmt, *args):
    2.70          """Log a debug message.
    2.71 @@ -132,7 +153,6 @@ class XendRoot:
    2.72          self.configure_logger()
    2.73          self.dbroot = self.get_config_value("dbroot", self.dbroot_default)
    2.74  
    2.75 -
    2.76      def configure_logger(self):
    2.77          logfile = self.get_config_value("logfile", self.logfile_default)
    2.78          loglevel = self.get_config_value("loglevel", self.loglevel_default)
    2.79 @@ -146,7 +166,7 @@ class XendRoot:
    2.80      def get_logger(self):
    2.81          """Get the logger.
    2.82          """
    2.83 -        return self.logging.getLogger()
    2.84 +        return self.logging and self.logging.getLogger()
    2.85  
    2.86      def get_dbroot(self):
    2.87          """Get the path to the database root.
    2.88 @@ -160,14 +180,20 @@ class XendRoot:
    2.89          """
    2.90          self.config_path = os.getenv(self.config_var, self.config_default)
    2.91          if os.path.exists(self.config_path):
    2.92 -            fin = file(self.config_path, 'rb')
    2.93 +            #self.logInfo('Reading config file %s', self.config_path)
    2.94              try:
    2.95 -                config = sxp.parse(fin)
    2.96 +                fin = file(self.config_path, 'rb')
    2.97 +                try:
    2.98 +                    config = sxp.parse(fin)
    2.99 +                finally:
   2.100 +                    fin.close()
   2.101                  config.insert(0, 'xend-config')
   2.102                  self.config = config
   2.103 -            finally:
   2.104 -                fin.close()
   2.105 +            except Exception, ex:
   2.106 +                self.logError('Reading config file %s: %s', self.config_path, str(ex))
   2.107 +                raise
   2.108          else:
   2.109 +            self.logError('Config file does not exist: %s', self.config_path)
   2.110              self.config = ['xend-config']
   2.111  
   2.112      def get_config(self, name=None):
   2.113 @@ -193,10 +219,35 @@ class XendRoot:
   2.114          return sxp.child_value(self.config, name, val=val)
   2.115  
   2.116      def get_xend_port(self):
   2.117 -        return int(self.get_config_value('xend-port', '8000'))
   2.118 +        """Get the port xend listens at for its HTTP interface.
   2.119 +        """
   2.120 +        return int(self.get_config_value('xend-port', self.xend_port_default))
   2.121 +
   2.122 +    def get_xend_event_port(self):
   2.123 +        """Get the port xend listens at for connection to its event server.
   2.124 +        """
   2.125 +        return int(self.get_config_value('xend-event-port', self.xend_event_port_default))
   2.126  
   2.127      def get_xend_address(self):
   2.128 -        return self.get_config_value('xend-address', '')
   2.129 +        """Get the address xend listens at for its HTTP and event ports.
   2.130 +        This defaults to the empty string which allows all hosts to connect.
   2.131 +        If this is set to 'localhost' only the localhost will be able to connect
   2.132 +        to the HTTP and event ports.
   2.133 +        """
   2.134 +        return self.get_config_value('xend-address', self.xend_address_default)
   2.135 +
   2.136 +    def get_console_address(self):
   2.137 +        """Get the address xend listens at for its console ports.
   2.138 +        This defaults to the empty string which allows all hosts to connect.
   2.139 +        If this is set to 'localhost' only the localhost will be able to connect
   2.140 +        to the console ports.
   2.141 +        """
   2.142 +        return self.get_config_value('console-address', self.console_address_default)
   2.143 +
   2.144 +    def get_console_port_base(self):
   2.145 +        """Get the base port number used to generate console ports for domains.
   2.146 +        """
   2.147 +        return int(self.get_config_value('console-port-base', self.console_port_base_default))
   2.148  
   2.149      def get_block_script(self, type):
   2.150          return self.get_config_value('block-%s' % type, '')
     3.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Thu Mar 10 14:53:08 2005 +0000
     3.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Fri Mar 11 12:54:24 2005 +0000
     3.3 @@ -596,10 +596,10 @@ class Daemon:
     3.4      def set_user(self):
     3.5          # Set the UID.
     3.6          try:
     3.7 -            os.setuid(pwd.getpwnam(USER)[2])
     3.8 +            os.setuid(pwd.getpwnam(XEND_USER)[2])
     3.9              return 0
    3.10          except KeyError, error:
    3.11 -            print "Error: no such user '%s'" % USER
    3.12 +            print "Error: no such user '%s'" % XEND_USER
    3.13              return 1
    3.14  
    3.15      def stop(self):
    3.16 @@ -609,7 +609,7 @@ class Daemon:
    3.17          xroot = XendRoot.instance()
    3.18          log.info("Xend Daemon started")
    3.19          self.createFactories()
    3.20 -        self.listenEvent()
    3.21 +        self.listenEvent(xroot)
    3.22          self.listenNotifier()
    3.23          self.listenVirq()
    3.24          SrvServer.create(bridge=1)
    3.25 @@ -622,9 +622,11 @@ class Daemon:
    3.26          self.netifCF = netif.NetifControllerFactory()
    3.27          self.consoleCF = console.ConsoleControllerFactory()
    3.28  
    3.29 -    def listenEvent(self):
    3.30 +    def listenEvent(self, xroot):
    3.31          protocol = EventFactory(self)
    3.32 -        return reactor.listenTCP(EVENT_PORT, protocol)
    3.33 +        port = xroot.get_xend_event_port()
    3.34 +        interface = xroot.get_xend_address()
    3.35 +        return reactor.listenTCP(port, protocol, interface=interface)
    3.36  
    3.37      def listenNotifier(self):
    3.38          protocol = NotifierProtocol(self.channelF)
     4.1 --- a/tools/python/xen/xend/server/console.py	Thu Mar 10 14:53:08 2005 +0000
     4.2 +++ b/tools/python/xen/xend/server/console.py	Fri Mar 11 12:54:24 2005 +0000
     4.3 @@ -11,6 +11,8 @@ from xen.xend.XendError import XendError
     4.4  from xen.xend import EventServer
     4.5  eserver = EventServer.instance()
     4.6  from xen.xend.XendLogging import log
     4.7 +from xen.xend import XendRoot
     4.8 +xroot = XendRoot.instance()
     4.9  
    4.10  import controller
    4.11  from messages import *
    4.12 @@ -191,7 +193,8 @@ class ConsoleController(controller.Contr
    4.13              pass
    4.14          else:
    4.15              f = ConsoleFactory(self, self.idx)
    4.16 -            self.listener = reactor.listenTCP(self.console_port, f)
    4.17 +            interface = xroot.get_console_address()
    4.18 +            self.listener = reactor.listenTCP(self.console_port, f, interface=interface)
    4.19  
    4.20      def connect(self, addr, conn):
    4.21          """Connect a TCP connection to the console.
     5.1 --- a/tools/python/xen/xend/server/params.py	Thu Mar 10 14:53:08 2005 +0000
     5.2 +++ b/tools/python/xen/xend/server/params.py	Fri Mar 11 12:54:24 2005 +0000
     5.3 @@ -3,9 +3,5 @@ XEND_PID_FILE = '/var/run/xend.pid'
     5.4  XFRD_PID_FILE = '/var/run/xfrd.pid'
     5.5  XEND_TRACE_FILE = '/var/log/xend.trace'
     5.6  
     5.7 -USER = 'root'
     5.8 +XEND_USER = 'root'
     5.9  
    5.10 -EVENT_PORT = 8001
    5.11 -
    5.12 -CONSOLE_PORT_BASE = 9600
    5.13 -