<div dir="ltr"><div><div><div>I managed to do it, but I find the whole process ugly, so I wondered if there might be something I'm missing or if I'm trying to reinvent the wheel...<br><br>I see lxd has some built-in file transfer, unfortunately lxd still isn't available on debian :)<br><br>So I managed the file transfer this way:<br><br>cat settings.patch | lxc-attach - n lxcws -- sudo -u guest sh -c 'exec cat > /home/guest/settings.patch'<br><br></div><div>which translates in python to:<br></div><div><br>def run_command(container, command, env={}, uid=None, gid=None, **kwargs):<br> env['LANG'] = "C.UTF-8"<br> env['TERM'] = "xterm"<br> env = ["%s=%s" % (key, value) for key, value in env.items()]<br> if uid is not None and gid is not None:<br> return container.attach_wait(<br> lxc.attach_run_command, command,<br> extra_env_vars=env, env_policy=lxc.LXC_ATTACH_CLEAR_ENV, uid=uid, gid=gid, **kwargs)<br> else:<br> return container.attach_wait(<br> lxc.attach_run_command, command,<br> extra_env_vars=env, env_policy=lxc.LXC_ATTACH_CLEAR_ENV, **kwargs)<br><br>def transfer_file(container, hostfile, destfile, uid=None, gid=None, **kwargs):<br> catfile = subprocess.Popen(['cat', hostfile], stdout=subprocess.PIPE)<br> exec_command = 'exec cat > ' + destfile<br> return run_command(container, ['sh', '-c', exec_command], uid=uid, gid=gid, stdin=catfile.stdout, **kwargs)<br><br>patchfile = '/home/host/PycharmProjects/lxcws/settings.patch'<br>transfer_file(container, patchfile, '/home/guest/settings.patch', uid=1000, gid=1000)<br></div><br></div>The patching now: <br><br>lxc-attach -n lxcws -- sudo -u guest sh -c 'patch -p1 -b < /home/toto/settings.patch'<br><br>the below "python translation" works, but I wondered if there was a nicest way to implement it, using stdout in the attach_wait kwargs, but I couldn't wrap my head around it.<br><br>patch_command = 'patch -p1 -b < /home/guest/settings.patch'<br>run_command(container, ['sh', '-c', patch_command], uid=1000, gid=1000, initial_cwd='/home/guest')<br><br></div>In fact the whole use of "sh -c" in both commands is bizarre to me, would there be something more elegant ?<br><div><br><br><br>--<br><div><div><div><div class="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></div></div></div></div>