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