lxc / python3-lxc

Python 3.x binding for liblxc
https://linuxcontainers.org/lxc
GNU Lesser General Public License v2.1
57 stars 38 forks source link

Many keys fail to get from config while they are in the config #6

Closed n3storm closed 6 years ago

n3storm commented 6 years ago

This already has been reported though in wrong place at https://github.com/lxc/lxc/issues/1518

Using latest python3-lxc-3.0.2 release I face the same issue:

 wa01 cat /home/lxc/wa01/config

 lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = down
lxc.network.hwaddr = 00:16:3e:84:67:55
lxc.rootfs = /var/lib/lxc/wa01/rootfs
lxc.rootfs.backend = dir
lxc.include = /usr/share/lxc/config/debian.common.conf
lxc.tty = 4
lxc.utsname = wa01-a
lxc.arch = amd64
lxc.loglevel = 2
lxc.start.auto = 0
lxc.network.ipv4 = 10.0.3.37
lxc.cgroup.cpuset.cpus = 0-1

Some kind of demonstration with config before:

import lxc
c = lxc.Container('wa01')
keys = ['lxc.network.type','lxc.network.link','lxc.network.flags','lxc.network.hwaddr','lxc.rootfs','lxc.rootfs.backend','lxc.include','lxc.tty','lxc.utsname','lxc.arch','lxc.loglevel','lxc.start.auto','lxc.network.ipv4',]

for k in keys:
    try:
        print(c.get_config_item(k))
    except:
        print("Item {} raises invalid key".format(k))

Results

Item lxc.network.type raises invalid key
Item lxc.network.link raises invalid key
Item lxc.network.flags raises invalid key
Item lxc.network.hwaddr raises invalid key
/var/lib/lxc/wa01/rootfs
dir
Item lxc.include raises invalid key
4
wa01-a
x86_64
INFO
0
Item lxc.network.ipv4 raises invalid key
n3storm commented 6 years ago

Okay, my bad, just for the help of somebody else:

for "lxc.network" keys you have to do first set(container.get_config_item('lxc.network')) so you get how many networks your container have.

After that you can index the keys to get their values. If you get one lxc.network key, then you can: container.get_config_item('lxc.network.0.link') and so on.

If you have two, you can access lxc.network.0.link and lxc.network.1.link

Please close this ticket.

brauner commented 6 years ago

Thanks!