chiark / gitweb /
can set env vars
authorIan Jackson <ian@anarres>
Thu, 22 Feb 2007 20:07:23 +0000 (20:07 +0000)
committerIan Jackson <ian@anarres>
Thu, 22 Feb 2007 20:07:23 +0000 (20:07 +0000)
doc/README.virtualisation-server
virt-subproc/VirtSubproc.py

index 3c3835d5f7b81118ac25705f1068b1f0e19b9eee..ab7243cf66de12564bb13795cc097c74e8ffd155 100644 (file)
@@ -103,18 +103,22 @@ Protocol
 
   Currently defined keyword arguments:
 
+       env=<var>=<value>
+
+               Sets the environment variable <var> to <value>.
+
        debug=<tfd>-<hfd>
 
                Arranges to pass fd <tfd> the testbed command, and
                send all output to it to the fd <hfd> as passed
                by the virt server's caller.
 
-               If this feature is available, execute-debug will
-               be advertised.  Only one such plumbing is available.
-
                <tfd> may be 1 or 2, in which case no output will
                be written to the <stdout> or <stderr> files.
 
+               If this feature is available, execute-debug will
+               be advertised.  Only one such plumbing is available.
+
 * Commands
        copydown <host-tree> <testbed-path>
        copyup <testbed-tree> <host-path>
index 8720716985ebe6dd0ebfa927b045534392f28b18..32af6d5aeb3e0685aecd995b1f44201831b01235 100644 (file)
@@ -148,12 +148,17 @@ def cmd_execute(c, ce):
        cmdnumargs(c, ce, 5, None)
        debug_re = regexp.compile('debug=(\d+)\-(\d+)$')
        debug_g = None
+       envs = []
        for kw in ce[6:]:
                if kw.startswith('debug='):
                        if debug_g: bomb("multiple debug= in execute")
                        m = debug_re.match(kw)
                        if not m: bomb("invalid execute debug arg `%s'" % kw)
                        debug_g = m.groups()
+               elif kw.startswith('env='):
+                       es = kw[4:]; eq = es.find('=')
+                       if eq <= 0: bomb("invalid env arg `%s'" % kw)
+                       envs.append((es[:eq], es[eq+1:]))
                else: bomb("invalid execute kw arg `%s'" % kw)
                
        gobody = "      import sys\n"
@@ -169,6 +174,10 @@ def cmd_execute(c, ce):
                if ioe == tfd: ioe_tfd = -1
                gobody += "     setfd(%d,'%s',%d)\n" % (
                        ioe_tfd, ce[ioe+2], ioe>0 )
+       for e in envs:
+               gobody += ("    os.environ[urllib.unquote('%s')]"
+                          " = urllib.unquote('%s')\n"
+                               % tuple(map(urllib.quote, e)))
        gobody += "     os.chdir(urllib.unquote('" + ce[5] +"'))\n"
        gobody += "     cmd = '%s'\n" % ce[1]
        gobody += ("    cmd = cmd.split(',')\n"