Re: [lxc-users] Questions on how to "lxd init" again, reinstall, upgrade and downgrade

2017-03-15 Thread Simos Xenitellis
On Tue, Mar 14, 2017 at 2:11 AM, Simos Xenitellis
 wrote:
> Hi All,
>
> I am writing a post on LXD and
> 1. how to run "lxd init" again (keeping the ZFS allocated space)
> 2. how to run "lxd init" again (clearing up the ZFS allocated space,
> allocate fresh space)
> 3. how to upgrade to the latest (currently 2.11) version
> 4. how to downgrade
>
> Here is how I plan to tackle these issues:
> 1. how to run "lxd init" again (keeping the ZFS allocated space)
>>> requires to "sudo systemctl stop lxd.service"
>>> requires to "sudo zpool destroy mylxdpool"
>>> then "nmcli connection delete lxdbr0" (to delete the bridge)
> |--> now "lxd init" and select to reuse the ZFS device
>
> 2. how to run "lxd init" again (clearing up the ZFS allocated space,
> allocate fresh space)
>>> requires to "sudo systemctl stop lxd.service"
>>> requires to "sudo zpool destroy mylxdpool"
>>> then "nmcli connection delete lxdbr0"
>>> remove everything in /var/lib/lxd/
>>> remove everything in /var/log/lxd/
> |--> now "lxd init" and select to reuse the ZFS device
>
> 3. how to upgrade to the latest (currently 2.11) version
>>> Enable the lxd-stable PPA (has 2.11)
> |--> then "sudo apt install lxd", which will bring in "lxd-client".
>
> 4. how to downgrade
> (AFAIK, downgrading is not expected to be tested, so it requires to
> remove everything (case [2]),
> downgrade "lxd" and "lxd-client", then "lxd init".
>
>
> If there is any big no-no in the above, I would love to hear about it!
>

I completed the first installment,
https://blog.simos.info/how-to-initialize-lxd-again/

It talks about what to look for when you need to run "lxd init" again.
I strategically added other interesting info so it should be
educational in general.

I do not talk about removing the lxdbr0 bridge as it still works fine
even if it exists.
The upside is that there are no extra "dnsmasq" processes lying
around, which would have to be taken care of.

I am now again "rm -fr /var/log/lxd/" unless there is a good reason
(currently: only when downgrading LXD).

My next endevour is how to upgrade (to lxd-stable: 2.11) or downgrade
(back to 2.0.9 in 16.04).
As far as I understand, upgrading is being tested, so it just works.
For downgrading, it needs to "rm -fr /var/lib/lxd/".

Simos
___
lxc-users mailing list
lxc-users@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-users

[lxc-users] lxc-attach vs python3 attach_wait

2017-03-15 Thread Alexander Dreweke

Hi

I'm trying to script the creation on various LXC containers. Therefor I 
would like to execute a script that finalizes the container. But the 
script fails when it tries to interact with systemd, the error message 
reads "Failed to connect to bus: No such file or directory"


A minimal example, without a script, results in the same error:

container.attach_wait(
lxc.attach_run_command,
[ "/bin/systemctl", "enable", "systemd-networkd.service" ],
env_policy=lxc.LXC_ATTACH_CLEAR_ENV)

When I execute the same command via lxc-attach it succeeds:

lxc-attach -n test --clear-env -- /usr/bin/strace /bin/systemctl enable 
systemd-networkd.service


Am I missing an option for attach_wait?

I'm using LXC 2.0.7 and the according python3 bindings.

Best regards,
Alexander
___
lxc-users mailing list
lxc-users@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-users

Re: [lxc-users] cloud-init network config error

2017-03-15 Thread Sergiusz Pawlowicz
On Tue, Mar 14, 2017 at 8:49 PM,   wrote:

> #cloud-config.yml
> network:
>   version: 1
>   config:
> - type: physical
>   name: eth0
>   subnets:
> - type: static
>   ipv4: true
>   address: 10.10.10.20
>   netmask: 255.255.255.0
>   gateway: 10.10.10.1
>   control: auto
> - type: nameserver
>   address: 10.10.10.1
>
> I'm launching the container on Ubuntu 16.04 (v2.0.9) with the following:
>
> lxc launch ubuntu: CONTAINER -c user.network-config="$(cat
> cloud-config.yml)"

You put too much into the network-config file, remove "network":

version: 1
config:
   - type .

cheerio,
S.
___
lxc-users mailing list
lxc-users@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-users

Re: [lxc-users] is there a lxc-attach -v switch equivalent in lxc python bindings ?

2017-03-15 Thread Benoit Barthelet
apologies, this was well described here :
https://lists.linuxcontainers.org/pipermail/lxc-devel/2013-August/004898.html

On Wed, Mar 15, 2017 at 9:15 AM, Benoit Barthelet <
benoit.barthe...@gmail.com> wrote:

> it seems like there's a built-in kwarg, extra_env_vars, that does the -v
> switch job of lxc-attach in fact, I wrapped it in a function here but it
> could be written without :
>
> def run_command(container, command, env={}):
> env['LANG'] = "C.UTF-8"
> env['TERM'] = "xterm"
> return container.attach_wait(
> lxc.attach_run_command, command,
> extra_env_vars=env, env_policy=lxc.LXC_ATTACH_CLEAR_ENV)
>
> run_command(container, ["env", ])
>
> returns :
>
> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
> container=lxc
> TERM=xterm
> LANG=C.UTF-8
>
> I managed to find it thanks to its use in http://bazaar.launchpad.net/~
> ubuntu-lxc/lxc/steam-lxc/view/head:/steam-lxc
>
> I couldn't find it documented, have I bad googling skills or is there a
> place where I could have found it ?
> If there isn't I'm ok to try document it, is there a dedicated place, wiki
> for that or it's not worth the effort ?
>
>
>
> On Tue, Mar 14, 2017 at 6:32 PM, Benoit Barthelet <
> benoit.barthe...@gmail.com> wrote:
>
>> thanks, that is exactly what I wanted !
>>
>> On Tue, Mar 14, 2017 at 1:37 PM, Stéphane Graber 
>> 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_CLEA
>>> R_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=0xF150E01A72F6D2EE
>>
>
>
>
> --
> benoit barthelet
> http://pgp.mit.edu/pks/lookup?op=get=0xF150E01A72F6D2EE
>



-- 
benoit barthelet
http://pgp.mit.edu/pks/lookup?op=get=0xF150E01A72F6D2EE
___
lxc-users mailing list
lxc-users@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-users

Re: [lxc-users] is there a lxc-attach -v switch equivalent in lxc python bindings ?

2017-03-15 Thread Benoit Barthelet
it seems like there's a built-in kwarg, extra_env_vars, that does the -v
switch job of lxc-attach in fact, I wrapped it in a function here but it
could be written without :

def run_command(container, command, env={}):
env['LANG'] = "C.UTF-8"
env['TERM'] = "xterm"
return container.attach_wait(
lxc.attach_run_command, command,
extra_env_vars=env, env_policy=lxc.LXC_ATTACH_CLEAR_ENV)

run_command(container, ["env", ])

returns :

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
container=lxc
TERM=xterm
LANG=C.UTF-8

I managed to find it thanks to its use in
http://bazaar.launchpad.net/~ubuntu-lxc/lxc/steam-lxc/view/head:/steam-lxc

I couldn't find it documented, have I bad googling skills or is there a
place where I could have found it ?
If there isn't I'm ok to try document it, is there a dedicated place, wiki
for that or it's not worth the effort ?



On Tue, Mar 14, 2017 at 6:32 PM, Benoit Barthelet <
benoit.barthe...@gmail.com> wrote:

> thanks, that is exactly what I wanted !
>
> On Tue, Mar 14, 2017 at 1:37 PM, Stéphane Graber 
> 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_CLEA
>> R_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=0xF150E01A72F6D2EE
>



-- 
benoit barthelet
http://pgp.mit.edu/pks/lookup?op=get=0xF150E01A72F6D2EE
___
lxc-users mailing list
lxc-users@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-users