Created
October 16, 2013 11:18
-
-
Save valentinbud/7006196 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..9e36ae0 100644 | |
--- a/salt/modules/lxc.py | |
+++ b/salt/modules/lxc.py | |
@@ -9,6 +9,7 @@ Work with linux containers | |
import logging | |
import tempfile | |
import os | |
+import ast | |
#import salt libs | |
import salt.utils | |
@@ -68,7 +69,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 +87,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[dev])) | |
+ 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 +130,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 +155,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']: |
/home/bud/.virtualenvs/salt/bin/salt 'nox' lxc.init lxc109 nic=default profile=local-debian-wheezy-lvm config='{master: 192.168.122.1}' seed=True mac="{'eth0': 'AC:DE:48:60:2A:28'}"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeError encountered executing lxc.init: eval() arg 1 must be a string or code object. See debug log for more info. Possibly a missing arguments issue: ArgSpec(args=['name', 'cpuset', 'cpushare', 'memory', 'nic', 'profile'], varargs=None, keywords='kwargs', defaults=(None, None, None, 'default', None))