ia64/xen-unstable

changeset 2854:1cacaf908d8b

bitkeeper revision 1.1159.1.354 (41891272X8MfKdN725aWtH970ayx1Q)

Merge ssh://srg//auto/groups/xeno/BK/xeno.bk
into equilibrium.research:/export/scratch/xeno-docs.bk
author mwilli2@equilibrium.research
date Wed Nov 03 17:16:34 2004 +0000 (2004-11-03)
parents 123bec0b692a 119930e9e60c
children ab134f4d418d
files .rootkeys tools/python/xen/sv/Daemon.py tools/python/xen/util/Brctl.py tools/python/xen/util/ip.py tools/python/xen/xend/Blkctl.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/util.py
line diff
     1.1 --- a/.rootkeys	Wed Nov 03 16:13:25 2004 +0000
     1.2 +++ b/.rootkeys	Wed Nov 03 17:16:34 2004 +0000
     1.3 @@ -491,6 +491,7 @@ 40c9c469yrm31i60pGKslTi2Zgpotg tools/pyt
     1.4  40c9c46925x-Rjb0Cv2f1-l2jZrPYg tools/python/xen/xend/server/netif.py
     1.5  40c9c469ZqILEQ8x6yWy0_51jopiCg tools/python/xen/xend/server/params.py
     1.6  40c9c469LNxLVizOUpOjEaTKKCm8Aw tools/python/xen/xend/sxp.py
     1.7 +4189125cL90jKSOcBJ3Vx4nWGiXXvA tools/python/xen/xend/util.py
     1.8  40d05079aFRp6NQdo5wIh5Ly31c0cg tools/python/xen/xm/__init__.py
     1.9  40cf2937gKQcATgXKGtNeWb1PDH5nA tools/python/xen/xm/create.py
    1.10  40f552eariuUSB9TWqCPnDLz5zvxMw tools/python/xen/xm/destroy.py
     2.1 --- a/tools/python/xen/sv/Daemon.py	Wed Nov 03 16:13:25 2004 +0000
     2.2 +++ b/tools/python/xen/sv/Daemon.py	Wed Nov 03 17:16:34 2004 +0000
     2.3 @@ -11,6 +11,7 @@ import sys
     2.4  import re
     2.5  
     2.6  from xen.sv.params import *
     2.7 +from xen.xend import util
     2.8  
     2.9  from twisted.internet import reactor
    2.10  from twisted.web import static, server, script
    2.11 @@ -29,7 +30,7 @@ class Daemon:
    2.12          cmdex = '(?P<cmd>.*)'
    2.13          procre = re.compile('^\s*' + pidex + '\s*' + pythonex + '\s*' + cmdex + '$')
    2.14          xendre = re.compile('^/usr/sbin/xend\s*(start|restart)\s*.*$')
    2.15 -        procs = os.popen('ps -e -o pid,args 2>/dev/null')
    2.16 +        procs = util.popen('ps -e -o pid,args 2>/dev/null')
    2.17          for proc in procs:
    2.18              pm = procre.match(proc)
    2.19              if not pm: continue
    2.20 @@ -57,7 +58,7 @@ class Daemon:
    2.21              return 0
    2.22          # Read the pid of the previous invocation and search active process list.
    2.23          pid = open(PID_FILE, 'r').read()
    2.24 -        lines = os.popen('ps ' + pid + ' 2>/dev/null').readlines()
    2.25 +        lines = util.popen('ps ' + pid + ' 2>/dev/null').readlines()
    2.26          for line in lines:
    2.27              if re.search('^ *' + pid + '.+xensv', line):
    2.28                  if not kill:
     3.1 --- a/tools/python/xen/util/Brctl.py	Wed Nov 03 16:13:25 2004 +0000
     3.2 +++ b/tools/python/xen/util/Brctl.py	Wed Nov 03 17:16:34 2004 +0000
     3.3 @@ -5,6 +5,8 @@ import os.path
     3.4  import re
     3.5  import sys
     3.6  
     3.7 +from xen.xend import util
     3.8 +
     3.9  os.defpath = os.defpath + ':/sbin:/usr/sbin:/usr/local/sbin'
    3.10  CMD_IFCONFIG = 'ifconfig'
    3.11  CMD_ROUTE    = 'route'
    3.12 @@ -81,7 +83,7 @@ def bridge_del(bridge):
    3.13  def routes():
    3.14      """Return a list of the routes.
    3.15      """
    3.16 -    fin = os.popen(CMD_ROUTE + ' -n', 'r')
    3.17 +    fin = util.popen(CMD_ROUTE + ' -n', 'r')
    3.18      routes = []
    3.19      for x in fin:
    3.20          if x.startswith('Kernel'): continue
    3.21 @@ -102,7 +104,7 @@ def routes():
    3.22  def ifconfig(interface):
    3.23      """Return the ip config for an interface,
    3.24      """
    3.25 -    fin = os.popen(CMD_IFCONFIG + ' %s' % interface, 'r')
    3.26 +    fin = util.popen(CMD_IFCONFIG + ' %s' % interface, 'r')
    3.27      inetre = re.compile('\s*inet\s*addr:(?P<address>\S*)\s*Bcast:(?P<broadcast>\S*)\s*Mask:(?P<mask>\S*)')
    3.28      info = None
    3.29      for x in fin:
     4.1 --- a/tools/python/xen/util/ip.py	Wed Nov 03 16:13:25 2004 +0000
     4.2 +++ b/tools/python/xen/util/ip.py	Wed Nov 03 17:16:34 2004 +0000
     4.3 @@ -4,6 +4,8 @@ import socket
     4.4  import struct
     4.5  import errno
     4.6  
     4.7 +from xen.xend import util
     4.8 +
     4.9  def _readlines(fd):
    4.10      """Version of readlines safe against EINTR.
    4.11      """
    4.12 @@ -49,7 +51,7 @@ def get_current_ipaddr(dev='eth0'):
    4.13  
    4.14      returns interface address as a string
    4.15      """
    4.16 -    fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
    4.17 +    fd = util.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
    4.18      lines = _readlines(fd)
    4.19      for line in lines:
    4.20          m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
    4.21 @@ -67,7 +69,7 @@ def get_current_ipmask(dev='eth0'):
    4.22  
    4.23      returns interface netmask as a string
    4.24      """
    4.25 -    fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
    4.26 +    fd = util.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
    4.27      lines = _readlines(fd)
    4.28      for line in lines:
    4.29          m = re.search( '^.+Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
    4.30 @@ -85,7 +87,7 @@ def get_current_ipgw(dev='eth0'):
    4.31  
    4.32      returns gateway address as a string
    4.33      """
    4.34 -    fd = os.popen( '/sbin/route -n' )
    4.35 +    fd = util.popen( '/sbin/route -n' )
    4.36      lines = _readlines(fd)
    4.37      for line in lines:
    4.38          m = re.search( '^\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' +
     5.1 --- a/tools/python/xen/xend/Blkctl.py	Wed Nov 03 16:13:25 2004 +0000
     5.2 +++ b/tools/python/xen/xend/Blkctl.py	Wed Nov 03 17:16:34 2004 +0000
     5.3 @@ -5,6 +5,7 @@ import os.path
     5.4  import sys
     5.5  import string
     5.6  
     5.7 +from xen.xend import util
     5.8  from xen.xend import XendRoot
     5.9  xroot = XendRoot.instance()
    5.10  
    5.11 @@ -35,7 +36,7 @@ def block(op, type, dets, script=None):
    5.12      script = os.path.join(SCRIPT_DIR, script)
    5.13      args = [op] + string.split(dets, ':')
    5.14      args = ' '.join(args)
    5.15 -    out = os.popen(script + ' ' + args)
    5.16 +    out = util.popen(script + ' ' + args)
    5.17  
    5.18      output = out.readline()
    5.19      out.close()
     6.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Wed Nov 03 16:13:25 2004 +0000
     6.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Wed Nov 03 17:16:34 2004 +0000
     6.3 @@ -34,6 +34,7 @@ from xen.xend.XendError import XendError
     6.4  from xen.xend.server import SrvServer
     6.5  from xen.xend import XendRoot
     6.6  from xen.xend.XendLogging import log
     6.7 +from xen.xend import util
     6.8  
     6.9  import channel
    6.10  import blkif
    6.11 @@ -336,7 +337,7 @@ class Daemon:
    6.12          cmdex = '(?P<cmd>.*)'
    6.13          procre = re.compile('^\s*' + pidex + '\s*' + pythonex + '\s*' + cmdex + '$')
    6.14          xendre = re.compile('^/usr/sbin/xend\s*(start|restart)\s*.*$')
    6.15 -        procs = os.popen('ps -e -o pid,args 2>/dev/null')
    6.16 +        procs = util.popen('ps -e -o pid,args 2>/dev/null')
    6.17          for proc in procs:
    6.18              pm = procre.match(proc)
    6.19              if not pm: continue
    6.20 @@ -382,7 +383,7 @@ class Daemon:
    6.21          """
    6.22          running = 0
    6.23          if pid:
    6.24 -            lines = os.popen('ps %d 2>/dev/null' % pid).readlines()
    6.25 +            lines = util.popen('ps %d 2>/dev/null' % pid).readlines()
    6.26              exp = '^ *%d.+%s' % (pid, name)
    6.27              for line in lines:
    6.28                  if re.search(exp, line):
     7.1 --- a/tools/python/xen/xend/server/blkif.py	Wed Nov 03 16:13:25 2004 +0000
     7.2 +++ b/tools/python/xen/xend/server/blkif.py	Wed Nov 03 17:16:34 2004 +0000
     7.3 @@ -8,6 +8,7 @@ from xen.xend import sxp
     7.4  from xen.xend import Blkctl
     7.5  from xen.xend.XendLogging import log
     7.6  from xen.xend.XendError import XendError, VmError
     7.7 +from xen.xend import util
     7.8  
     7.9  import os
    7.10  import re
    7.11 @@ -25,7 +26,7 @@ def expand_dev_name(name):
    7.12  def check_mounted(self, name):
    7.13      mode = None
    7.14      name = expand_dev_name(name)
    7.15 -    lines = os.popen('mount 2>/dev/null').readlines()
    7.16 +    lines = util.popen('mount 2>/dev/null').readlines()
    7.17      exp = re.compile('^' + name + ' .*[\(,]r(?P<mode>[ow])[,\)]')
    7.18      for line in lines:
    7.19          pm = exp.match(line)
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/python/xen/xend/util.py	Wed Nov 03 17:16:34 2004 +0000
     8.3 @@ -0,0 +1,36 @@
     8.4 +# Misc utility functions for Xend
     8.5 +# (c) 2004 Mark A. Williamson <mark.williamson@cl.cam.ac.uk>
     8.6 +
     8.7 +from twisted.internet import utils
     8.8 +from twisted.internet import reactor
     8.9 +from XendLogging import log
    8.10 +from StringIO import StringIO
    8.11 +
    8.12 +# This is rather distasteful.  Twisted doesn't play nicely with Python's
    8.13 +# standard os.popen, so here's an implementation of a synchronous popen that
    8.14 +# should work reliably. - MAW
    8.15 +def popen(cmd):
    8.16 +    global done_flag, result
    8.17 +
    8.18 +    done_flag = False
    8.19 +    result = ''
    8.20 +    
    8.21 +    def done(output):
    8.22 +        global done_flag, result
    8.23 +        done_flag = True
    8.24 +        result = output
    8.25 +
    8.26 +    def err(output):
    8.27 +        global done_flag
    8.28 +# For normal use, suppress debug output here.  It grumbles about stderr if the
    8.29 +# program exits with $? != 0, even if stderr is redirected.  Grrr!
    8.30 +#        log.debug("util.popen(\'%s\'): %s" % (cmd, output))
    8.31 +        done_flag = True
    8.32 +
    8.33 +    d = utils.getProcessOutput(cmd)
    8.34 +    d.addCallbacks(done, err)
    8.35 +
    8.36 +    while not done_flag:
    8.37 +        reactor.iterate()
    8.38 +
    8.39 +    return StringIO(result)