<div dir="ltr">thanks, that is exactly what I wanted !<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 14, 2017 at 1:37 PM, Stéphane Graber <span dir="ltr"><<a href="mailto:stgraber@ubuntu.com" target="_blank">stgraber@ubuntu.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, Mar 14, 2017 at 11:22:26AM +0100, Benoit Barthelet wrote:<br>
> ultimately I'd like to do this in python:<br>
><br>
> lxc-attach --clear-env -n lxcws -v TERM=xterm<br>
><br>
> So far I managed to clear the env variables doing the following, but I<br>
> didn't find a way to pass the TERM env variable.<br>
><br>
> container.attach_wait(lxc.<wbr>attach_run_command,<br>
>                       ["apt-get", "dist-upgrade", "-y"],<br>
>                       env_policy=lxc.LXC_ATTACH_<wbr>CLEAR_ENV)<br>
<br>
</span>Easiest I think is to use your own attach function instead of the<br>
generic lxc.attach_run_command. In that function you can then set<br>
os.environ as you want and call subprocess to run the command you want.<br>
<br>
In the lxc-ci code we have something like this:<br>
<br>
    def execute(self, cmd, cwd="/"):<br>
        def run_command(args):<br>
            cmd, cwd = args<br>
<br>
            os.environ['PATH'] = '/usr/sbin:/usr/bin:/sbin:/<wbr>bin'<br>
            os.environ['HOME'] = '/root'<br>
            if "env" in config and "proxy" in config['env']:<br>
                os.environ["DEBIAN_FRONTEND"] = "noninteractive"<br>
                os.environ['http_proxy'] = config['env']['proxy']<br>
                os.environ['https_proxy'] = config['env']['proxy']<br>
<br>
            return subprocess.call(cmd, cwd=cwd)<br>
<br>
        if isinstance(cmd, str):<br>
            pid = self.container.init_pid<br>
            cmdpath = "/proc/%d/root/tmp/exec_<wbr>script" % pid<br>
            with open(cmdpath, "w+") as fd:<br>
                fd.write(cmd)<br>
            os.chmod(cmdpath, 0o755)<br>
            cmd = ["/tmp/exec_script"]<br>
<br>
        print(" ==> Executing: \"%s\" in %s" % (" ".join(cmd), cwd))<br>
        return self.container.attach_wait(<wbr>run_command,<br>
                                          (cmd, cwd),<br>
                                          env_policy=lxc.LXC_ATTACH_<wbr>CLEAR_ENV)<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Stéphane Graber<br>
Ubuntu developer<br>
<a href="http://www.ubuntu.com" rel="noreferrer" target="_blank">http://www.ubuntu.com</a><br>
</font></span><br>______________________________<wbr>_________________<br>
lxc-users mailing list<br>
<a href="mailto:lxc-users@lists.linuxcontainers.org">lxc-users@lists.<wbr>linuxcontainers.org</a><br>
<a href="http://lists.linuxcontainers.org/listinfo/lxc-users" rel="noreferrer" target="_blank">http://lists.linuxcontainers.<wbr>org/listinfo/lxc-users</a><br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr">benoit barthelet<br><a href="http://pgp.mit.edu/pks/lookup?op=get&search=0xF150E01A72F6D2EE" target="_blank">http://pgp.mit.edu/pks/lookup?op=get&search=0xF150E01A72F6D2EE</a><br></div></div></div></div>
</div>