lxc-containers: generate hwaddrs

This commit is contained in:
Astro 2016-11-26 02:51:59 +01:00
parent 67056cf2fa
commit 89be4dae61
2 changed files with 8 additions and 1 deletions

View File

@ -10,9 +10,11 @@ lxc.rootfs.backend = dir
lxc.autodev = 1
lxc.kmsg = 0
{%- set n = 0 %}
{%- for net, conf in container['interfaces'].items() %}
lxc.network.type={{ conf['type'] }}
lxc.network.flags=up
lxc.network.hwaddr={{ hwaddr_prefix }}:{{ n.__str()__.rjust(2, '0') }}
{%- if conf['type'] == 'veth' %}
lxc.network.veth.pair={{ id }}-{{ net }}
{%- endif %}
@ -34,6 +36,8 @@ lxc.network.ipv4.gateway={{ pillar['hosts-inet'][net][gw] }}
{%- endif %}
#lxc.network.ipv6=
#lxc.network.ipv6.gateway=fe80::1
{%- set n = n + 1 %}
{%- endfor %}

View File

@ -1,7 +1,8 @@
lxc:
pkg.installed: []
{% for id, container in pillar['containers'].items() %}
{%- set n = 0 %}
{%- for id, container in pillar['containers'].items() %}
/var/lib/lxc/{{ id }}:
cmd.run:
@ -17,6 +18,7 @@ lxc:
- context:
id: {{ id }}
container: {{ container }}
hwaddr_prefix: '0A:14:48:01:{{ n.__str__().rjust(2, '0') }}'
- require:
- cmd: /var/lib/lxc/{{ id }}
@ -55,4 +57,5 @@ start-{{ id }}:
require:
- service: autostart-{{ id }}
{%- set n = n + 1 %}
{% endfor %}