Skip to content

Instantly share code, notes, and snippets.

@valentinbud
Created October 16, 2013 09:53
Show Gist options
  • Save valentinbud/7005390 to your computer and use it in GitHub Desktop.
Save valentinbud/7005390 to your computer and use it in GitHub Desktop.
diff --git a/salt/modules/lxc.py b/salt/modules/lxc.py
index 26dd259..a6757c3 100644
--- a/salt/modules/lxc.py
+++ b/salt/modules/lxc.py
@@ -68,7 +68,8 @@ def _nic_profile(nic):
def _gen_config(nicp,
cpuset=None,
cpushare=None,
- memory=None):
+ memory=None,
+ mac=None):
'''
Generate the config string for an lxc container
'''
@@ -85,7 +86,10 @@ def _gen_config(nicp,
data.append(('lxc.network.type', args.pop('type', 'veth')))
data.append(('lxc.network.name', dev))
data.append(('lxc.network.flags', args.pop('flags', 'up')))
- data.append(('lxc.network.hwaddr', salt.utils.gen_mac()))
+ if mac:
+ data.append(('lxc.network.hwaddr', mac))
+ else:
+ data.append(('lxc.network.hwaddr', salt.utils.gen_mac()))
for k, v in args.items():
data.append(('lxc.network.{0}'.format(k), v))
@@ -125,6 +129,9 @@ def init(name,
nic
Network interfaces profile (defined in config or pillar).
+ mac
+ Network interface MAC address.
+
profile
A LXC profile (defined in config or pillar).
@@ -147,10 +154,11 @@ def init(name,
install = kwargs.pop('install', True)
seed_cmd = kwargs.pop('seed_cmd', None)
config = kwargs.pop('config', None)
+ mac = kwargs.pop('mac', None)
with tempfile.NamedTemporaryFile() as cfile:
cfile.write(_gen_config(cpuset=cpuset, cpushare=cpushare,
- memory=memory, nicp=nicp))
+ memory=memory, nicp=nicp, mac=mac))
cfile.flush()
ret = create(name, config=cfile.name, profile=profile, **kwargs)
if not ret['created']:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment