mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
bitkeeper revision 1.1426.1.1 (4289cc8cPUM98bLJs4TV93NHY9LOKg)
Many files:
Make interface to network/block scripts consistent:
- output on stdout is returned to the script caller
- output on stderr is logged at the error level, messages with a '-' prefix
are logged at the debug level and messages with a '*' prefix are logged
at the info level.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
This commit is contained in:
1 parent
ca5d3268f9
commit
b93e7f7e8b
10 files changed
+40
-32
No files matched your search
@@ -4,10 +4,11 @@
|
||||
|
||||
import popen2
|
||||
import select
|
||||
import string
|
||||
|
||||
from xen.xend.XendLogging import log
|
||||
|
||||
def system(cmd):
|
||||
def runscript(cmd):
|
||||
# split after first space, then grab last component of path
|
||||
cmdname = "[%s] " % cmd.split()[0].split('/')[-1]
|
||||
# run command and grab stdin, stdout and stderr
|
||||
@@ -18,14 +19,19 @@ def system(cmd):
|
||||
p = select.poll()
|
||||
p.register(cout)
|
||||
p.register(cerr)
|
||||
stdout = ""
|
||||
while True:
|
||||
r = p.poll()
|
||||
for (fd, event) in r:
|
||||
if event == select.POLLHUP:
|
||||
return
|
||||
return stdout
|
||||
if fd == cout.fileno():
|
||||
l = cout.readline()
|
||||
log.info(cmdname + l.rstrip())
|
||||
stdout = stdout + cout.readline()
|
||||
if fd == cerr.fileno():
|
||||
l = cerr.readline()
|
||||
log.error(cmdname + l.rstrip())
|
||||
if l[0] == '-':
|
||||
log.debug(cmdname + l[1:].rstrip())
|
||||
elif l[0] == '*':
|
||||
log.info(cmdname + l[1:].rstrip())
|
||||
else:
|
||||
log.error(cmdname + l.rstrip())
|
||||
@@ -4,6 +4,7 @@ import os
|
||||
import os.path
|
||||
import sys
|
||||
import string
|
||||
import xen.util.process
|
||||
|
||||
from xen.xend import XendRoot
|
||||
|
||||
@@ -38,8 +39,6 @@ def block(op, type, dets, script=None):
|
||||
script = os.path.join(SCRIPT_DIR, script)
|
||||
args = [op] + string.split(dets, ':')
|
||||
args = ' '.join(args)
|
||||
out = os.popen(script + ' ' + args)
|
||||
|
||||
output = _readline(out)
|
||||
out.close()
|
||||
return string.rstrip(output)
|
||||
ret = xen.util.process.runscript(script + ' ' + args)
|
||||
if len(ret):
|
||||
return ret.splitlines()[0]
|
||||
@@ -36,7 +36,9 @@ def network(op, script=None, bridge=None, antispoof=None):
|
||||
else:
|
||||
args.append("antispoof=no")
|
||||
args = ' '.join(args)
|
||||
xen.util.process.system(script + ' ' + args)
|
||||
ret = xen.util.process.runscript(script + ' ' + args)
|
||||
if len(ret):
|
||||
return ret.splitlines()[0]
|
||||
|
||||
def set_vif_name(vif_old, vif_new):
|
||||
if vif_old == vif_new:
|
||||
@@ -81,5 +83,6 @@ def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr
|
||||
ips = ' '.join(ipaddr)
|
||||
args.append("ip='%s'" % ips)
|
||||
args = ' '.join(args)
|
||||
os.system(script + ' ' + args)
|
||||
|
||||
ret = xen.util.process.runscript(script + ' ' + args)
|
||||
if len(ret):
|
||||
return ret.splitlines()[0]
|
||||