ia64/xen-unstable

changeset 1570:ee6102a446c2

bitkeeper revision 1.1010.1.2 (40daf234LK7ohaP4f1QHGPJq0t3yZw)

Change configs to live in /etc/xen, other stuff in /var/xen.
Update xendomains to use xm.
author mjw@wray-m-3.hpl.hp.com
date Thu Jun 24 15:24:36 2004 +0000 (2004-06-24)
parents 92c056054f01
children d54973432d60
files tools/examples/Makefile tools/examples/init.d/xendomains tools/xenmgr/lib/XendBridge.py tools/xenmgr/lib/XendRoot.py tools/xenmgr/lib/xm/create.py tools/xenmgr/lib/xm/shutdown.py
line diff
     1.1 --- a/tools/examples/Makefile	Thu Jun 24 11:13:44 2004 +0000
     1.2 +++ b/tools/examples/Makefile	Thu Jun 24 15:24:36 2004 +0000
     1.3 @@ -1,19 +1,20 @@
     1.4  
     1.5  INSTALL  = $(wildcard *.py)
     1.6  ETC	 = defaults democd netbsd xmdefaults
     1.7 +ETCDIR   = /etc/xen
     1.8  INITD    = init.d/xendomains init.d/xend
     1.9  
    1.10  all: 
    1.11  
    1.12  install: all
    1.13  	mkdir -p $(prefix)/usr/bin
    1.14 -	mkdir -p $(prefix)/etc/xc
    1.15 -	mkdir -p $(prefix)/etc/xc/auto
    1.16 +	mkdir -p $(prefix)$(ETCDIR)
    1.17 +	mkdir -p $(prefix)$(ETCDIR)/auto
    1.18  	mkdir -p $(prefix)/etc/init.d
    1.19  	install -m0755 $(INSTALL) $(prefix)/usr/bin
    1.20  	for i in $(ETC); \
    1.21 -	    do [ -a $(prefix)/etc/xc/$$i ] || \
    1.22 -	    install -m0644 $$i $(prefix)/etc/xc; \
    1.23 +	    do [ -a $(prefix)/$(ETCDIR)/$$i ] || \
    1.24 +	    install -m0644 $$i $(prefix)$(ETCDIR); \
    1.25  	done
    1.26  	install -m0755 $(INITD) $(prefix)/etc/init.d
    1.27  
     2.1 --- a/tools/examples/init.d/xendomains	Thu Jun 24 11:13:44 2004 +0000
     2.2 +++ b/tools/examples/init.d/xendomains	Thu Jun 24 15:24:36 2004 +0000
     2.3 @@ -19,6 +19,9 @@ RETVAL=0
     2.4  
     2.5  INITD=/etc/init.d/
     2.6  
     2.7 +AUTODIR=/etc/xen/auto
     2.8 +LOCKFILE=/var/lock/subsys/xendomains
     2.9 +
    2.10  if [ -e /lib/lsb ]; then
    2.11      # assume an LSB-compliant distro (Debian with LSB package,
    2.12      # recent-enough SuSE, others...)
    2.13 @@ -52,24 +55,23 @@ fi
    2.14  
    2.15  
    2.16  start() {
    2.17 -    if [ -f /var/lock/subsys/xendomains ]; then return; fi
    2.18 +    if [ -f $LOCKFILE ]; then return; fi
    2.19  
    2.20      echo -n $"Starting auto Xen domains:"
    2.21  
    2.22 -    # we expect config scripts for auto starting domains to be in
    2.23 -    # /etc/xc/auto/ - they could just be symlinks to files elsewhere
    2.24 -    if [ -d /etc/xc/auto ] &&
    2.25 -	    [ $(ls /etc/xc/auto/ | wc -l) -gt 0 ]; then
    2.26 +    # We expect config scripts for auto starting domains to be in
    2.27 +    # AUTODIR - they could just be symlinks to files elsewhere
    2.28 +    if [ -d $AUTODIR ] && [ $(ls $AUTODIR | wc -l) -gt 0 ]; then
    2.29 +	touch $LOCKFILE
    2.30  	
    2.31 -       # create all domains with config files in /etc/xc/auto
    2.32 -	for dom in /etc/xc/auto/*; do
    2.33 -	    xc_dom_create.py -q -f $dom
    2.34 +       # Create all domains with config files in AUTODIR.
    2.35 +	for dom in  $AUTODIR/*; do
    2.36 +	    xm create --quiet --defaults $dom
    2.37  	    if [ $? -ne 0 ]; then
    2.38  		RETVAL=$?
    2.39  	    fi
    2.40  	done
    2.41  
    2.42 -	touch /var/lock/subsys/xendomains
    2.43      fi
    2.44  
    2.45      on_fn_exit
    2.46 @@ -78,40 +80,24 @@ start() {
    2.47  stop()
    2.48  {
    2.49      # NB. this shuts down ALL Xen domains (politely), not just the ones in
    2.50 -    # /etc/xc/auto/*
    2.51 +    # AUTODIR/*
    2.52      # This is because it's easier to do ;-) but arguably if this script is run
    2.53      # on system shutdown then it's also the right thing to do.
    2.54      
    2.55      echo -n $"Shutting down all Xen domains:"
    2.56  
    2.57 -    if [ -d /var/run/xendomains ] &&
    2.58 -	    [ $(ls /var/run/xendomains/ | wc -l) -gt 0 ]; then
    2.59 -	
    2.60 -	cd /var/run/xendomains/
    2.61 -
    2.62 -	for pid in *; do
    2.63 -	   
    2.64 -	    kill -s SIGTERM $(cat $pid)
    2.65 +    xm shutdown --all --wait --norestart
    2.66  
    2.67 -	done
    2.68 -
    2.69 -    fi
    2.70 -
    2.71 -    sleep 3 # avoid races
    2.72 -
    2.73 -    xc_dom_control.py shutdown all -w # shut down all domains, politely and wait
    2.74 -                                      # for all to exit
    2.75 -    
    2.76      RETVAL=$?
    2.77  
    2.78 -    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/xendomains
    2.79 +    [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
    2.80  
    2.81      on_fn_exit
    2.82  }
    2.83  
    2.84  # This does NOT necessarily restart all running domains: instead it
    2.85  # stops all running domains and then boots all the domains specified in
    2.86 -# /etc/xc/auto.  If other domains have been started manually then they will
    2.87 +# AUTODIR.  If other domains have been started manually then they will
    2.88  # not get restarted.
    2.89  # Commented out to avoid confusion!
    2.90  #
    2.91 @@ -149,7 +135,7 @@ case "$1" in
    2.92  #	;;
    2.93  
    2.94      status)
    2.95 -	xc_dom_control.py list
    2.96 +	xm list
    2.97  	;;
    2.98  
    2.99      *)
     3.1 --- a/tools/xenmgr/lib/XendBridge.py	Thu Jun 24 11:13:44 2004 +0000
     3.2 +++ b/tools/xenmgr/lib/XendBridge.py	Thu Jun 24 15:24:36 2004 +0000
     3.3 @@ -12,6 +12,7 @@ os.defpath = os.defpath + ':/sbin:/usr/s
     3.4  CMD_IFCONFIG = 'ifconfig'
     3.5  CMD_ROUTE    = 'route'
     3.6  CMD_BRCTL    = 'brctl'
     3.7 +CMD_IPTABLES = "iptables"
     3.8  
     3.9  DEFAULT_BRIDGE = 'nbe-br'
    3.10  DEFAULT_INTERFACE = 'eth0'
    3.11 @@ -61,6 +62,16 @@ def vif_bridge_rem(dom, vif, bridge=None
    3.12      d = { 'bridge': bridge, 'vif': vif_dev(dom, vif) }
    3.13      cmd(CMD_BRCTL, 'delif %(bridge)s %(vif)s' % d)
    3.14  
    3.15 +def vif_restrict_addr(dom, vif, addr, delete=0):
    3.16 +    d = { 'vif': vif_dev(dom, vif), 'addr': addr}
    3.17 +    if delete:
    3.18 +        d['flag'] = '-D'
    3.19 +    else:
    3.20 +        d['flag' = '-A'
    3.21 +    cmd(CMD_IPTABLES, '-P FORWARD DROP')
    3.22 +    cmd(CMD_IPTABLES, '%(flag)s FORWARD -m physdev --physdev-in %(vif)s -s %(addr)s -j ACCEPT' % d)
    3.23 +    cmd(CMD_IPTABLES, '%(flag)s FORWARD -m physdev --physdev-out %(vif)s -d %(addr)s -j ACCEPT' % d)
    3.24 +
    3.25  def bridge_create(bridge=None, **kwd):
    3.26      """Create a bridge.
    3.27      Defaults hello time to 0, forward delay to 0 and stp off.
     4.1 --- a/tools/xenmgr/lib/XendRoot.py	Thu Jun 24 11:13:44 2004 +0000
     4.2 +++ b/tools/xenmgr/lib/XendRoot.py	Thu Jun 24 15:24:36 2004 +0000
     4.3 @@ -30,13 +30,13 @@ def last_reboot():
     4.4  class XendRoot:
     4.5      """Root of the management classes."""
     4.6  
     4.7 -    lastboot_default = "/etc/xen/xend/lastboot"
     4.8 +    lastboot_default = "/var/xen/lastboot"
     4.9  
    4.10      """Default path to the root of the database."""
    4.11 -    dbroot_default = "/etc/xen/xend/xenmgr-db"
    4.12 +    dbroot_default = "/var/xen/xend-db"
    4.13  
    4.14      """Default path to the config file."""
    4.15 -    config_default = "/etc/xen/xenmgr-config.sxp"
    4.16 +    config_default = "/etc/xen/xend-config.sxp"
    4.17  
    4.18      """Environment variable used to override config_default."""
    4.19      config_var     = "XEND_CONFIG"
     5.1 --- a/tools/xenmgr/lib/xm/create.py	Thu Jun 24 11:13:44 2004 +0000
     5.2 +++ b/tools/xenmgr/lib/xm/create.py	Thu Jun 24 15:24:36 2004 +0000
     5.3 @@ -24,11 +24,11 @@ gopts.opt('quiet', short='q',
     5.4           use="Quiet.")
     5.5  
     5.6  gopts.opt('path', val='PATH',
     5.7 -         fn=set_value, default='.:/etc/xc',
     5.8 +         fn=set_value, default='.:/etc/xen',
     5.9           use="Search path for default scripts.")
    5.10  
    5.11  gopts.opt('defaults', short='f', val='FILE',
    5.12 -         fn=set_value, default='xmdefaults',
    5.13 +         fn=set_value, default='defaults',
    5.14           use="Use the given default script.")
    5.15  
    5.16  gopts.opt('config', short='F', val='FILE',
    5.17 @@ -220,12 +220,13 @@ def configure_vifs(config_devs, opts):
    5.18              config_vif.append(['bridge', bridge])
    5.19          config_devs.append(['device', config_vif])
    5.20  
    5.21 -##     if vfr_ipaddr:
    5.22 -##         config_vfr = ['vfr']
    5.23 -##         idx = 0 # No way of saying which IP is for which vif?
    5.24 -##         for ip in vfr_ipaddr:
    5.25 -##             config_vfr.append(['vif', ['id', idx], ['ip', ip]])
    5.26 -##         config.append(config_vfr)
    5.27 +def configure_vfr(config, opts):
    5.28 +     if not opts.ipaddr: return
    5.29 +     config_vfr = ['vfr']
    5.30 +     idx = 0 # No way of saying which IP is for which vif?
    5.31 +     for ip in opts.ipaddr:
    5.32 +         config_vfr.append(['vif', ['id', idx], ['ip', ip]])
    5.33 +     config.append(config_vfr)
    5.34  
    5.35  
    5.36  def make_config(opts):
     6.1 --- a/tools/xenmgr/lib/xm/shutdown.py	Thu Jun 24 11:13:44 2004 +0000
     6.2 +++ b/tools/xenmgr/lib/xm/shutdown.py	Thu Jun 24 15:24:36 2004 +0000
     6.3 @@ -24,6 +24,10 @@ gopts.opt('wait', short='w',
     6.4           fn=set_true, default=0,
     6.5           use='Wait for shutdown to complete.')
     6.6  
     6.7 +gopts.opt('norestart', short='n',
     6.8 +          fn=set_true, default=0,
     6.9 +          use='Prevent domain restart.')
    6.10 +
    6.11  def shutdown(opts, doms, wait):
    6.12      def domains():
    6.13          return [ int(a) for a in server.xend_domains() ]