Am I doing something wrong, or is the user section of config template variables a real pain to use due to the use of dots in keys?
In theory, you can do just about anything you want by adding custom config keys under the user prefix, then using those values in templates. The trouble comes when trying to use them. Dot is supposed to be a break point in the pongo template language representing another nested key/value hash. It's not supposed to be a valid char on the key side and there seems to be no way to escape the dot and forcing pongo2 to treat the dot as a part of a key in the template language. So when lxd provides "user.foo"="bar" to the template expansion, you can't just use them as {{user.foo}} and have them expanded as expected, because because {{use.foo}} references the non-existent {user: { foo: bar } } not { user.foo: bar }. For example set config: user.foo: bar in a template or via lxc luanch -c user.foo=bar and the only way I found to use it was this really obtuse looking for loop. {% for k,v in config %}{%if k in "user.foo" %}{{v}}{% endif %}{% endfor %} And it's not just user space keys that use dot as part of a key provided to the template. If you want the automagic-mac, I can only get it with {% for k,v in config %}{%if k in "volatile.eth0.hwaddr" %}{{v}}{% endif %}{% endfor %} not {{volatile.eth0.hwaddr}} as the examples suggest. but if you want the container name, you follow the straight forward syntax works: {{container.name}} is correct. This all seems way to strange to be the right way to do this, but alternate constructions that should make it a map to satisfy pongo2 are rejected as invalid config by lxc/lxd. So the big question is, am I missing a way easier construct, and is this intentional or something that should be changed? config: user: foo: bar or config: { foo: bar } Example: ==== metadata.yaml: ... "templates": { ... "/etc/sysconfig/network-scripts/ifcfg-eth0": { "template": "ifcfg-eth0.tpl", "when": [ "start" ] }, ... ==== templates/ifcfg-eth0.tpl: DEVICE=eth0 BOOTPROTO=static DHCPCLASS= HWADDR={% for k,v in config %}{%if k in "volatile.eth0.hwaddr" %}{{v}}{% endif %}{% endfor %} IPADDR={% for k,v in config %}{%if k in "user.ip" %}{{v}}{% endif %}{% endfor %} NETMASK={% for k,v in config %}{%if k in "user.netmask" %}{{v}}{% endif %}{% endfor %} GATEWAY={% for k,v in config %}{%if k in "user.gateway" %}{{v}}{% endif %}{% endfor %} ONBOOT=yes ==== lxc profile show local name: local config: user.gateway: 10.0.2.1 user.netmask: 255.255.255.128 user.ns: 10.0.2.1 description: Adds local network options that don't change from host to host. devices: eth0: name: eth0 nictype: bridged parent: lxdbr0 type: nic
_______________________________________________ lxc-users mailing list lxc-users@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-users