Created
October 16, 2013 09:53
-
-
Save valentinbud/7005390 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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