From 058a3b9b752125e8966b025a347395712511ca5c Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Thu, 7 Aug 2014 00:02:30 -0400 Subject: [PATCH 1/4] Added jail.conf support --- salt/modules/freebsdjail.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/salt/modules/freebsdjail.py b/salt/modules/freebsdjail.py index 9ffd70c88a..7736521c08 100644 --- a/salt/modules/freebsdjail.py +++ b/salt/modules/freebsdjail.py @@ -122,6 +122,21 @@ def show_config(jail): continue key, value = line.split('=') ret[key.split('_', 2)[2]] = value.split('"')[1] + for jconf in ('/etc/jail.conf', '/usr/local/etc/jail.conf'): + if os.access(jconf, os.R_OK): + with salt.utils.fopen(jconf, 'r') as _fp: + for line in _fp: + if line.split()[0:2] == [jail, '{']: + break + for line in _fp: + if line.split()[-1] == '}': + break + if '=' not in line: + ret[line.strip().rstrip(";")] = 'true' + else: + key = line.split('=')[0].strip() + value = line.split('=')[-1].strip().strip(";'\"") + ret[key] = value return ret @@ -140,7 +155,12 @@ def fstab(jail): config = show_config(jail) if 'fstab' in config: c_fstab = config['fstab'] + elif 'mount.fstab' in config: + c_fstab = config['mount.fstab'] + if 'fstab' in config or 'mount.fstab' in config: + print config['mount.fstab'] if os.access(c_fstab, os.R_OK): + print '158' with salt.utils.fopen(c_fstab, 'r') as _fp: for line in _fp: line = line.strip() @@ -196,3 +216,5 @@ def sysctl(): key, value = line.split(':', 1) ret[key.strip()] = value.strip() return ret + + From 6ebcff9422ce5059b57444c71e495cb1242407f7 Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Thu, 7 Aug 2014 00:10:25 -0400 Subject: [PATCH 2/4] Removed debug print lines --- salt/modules/freebsdjail.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/salt/modules/freebsdjail.py b/salt/modules/freebsdjail.py index 7736521c08..5b5c179422 100644 --- a/salt/modules/freebsdjail.py +++ b/salt/modules/freebsdjail.py @@ -158,9 +158,7 @@ def fstab(jail): elif 'mount.fstab' in config: c_fstab = config['mount.fstab'] if 'fstab' in config or 'mount.fstab' in config: - print config['mount.fstab'] if os.access(c_fstab, os.R_OK): - print '158' with salt.utils.fopen(c_fstab, 'r') as _fp: for line in _fp: line = line.strip() From 4744469993fcd454a405c6ea9223768f88182f7b Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Thu, 7 Aug 2014 11:19:29 -0400 Subject: [PATCH 3/4] added jail info from jls command --- salt/modules/freebsdjail.py | 69 +++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/salt/modules/freebsdjail.py b/salt/modules/freebsdjail.py index 5b5c179422..9080697221 100644 --- a/salt/modules/freebsdjail.py +++ b/salt/modules/freebsdjail.py @@ -5,6 +5,8 @@ The jail module for FreeBSD # Import python libs import os +import subprocess +import shlex # Import salt libs import salt.utils @@ -112,31 +114,48 @@ def show_config(jail): salt '*' jail.show_config ''' ret = {} - for rconf in ('/etc/rc.conf', '/etc/rc.conf.local'): - if os.access(rconf, os.R_OK): - with salt.utils.fopen(rconf, 'r') as _fp: - for line in _fp: - if not line.strip(): - continue - if not line.startswith('jail_{0}_'.format(jail)): - continue - key, value = line.split('=') - ret[key.split('_', 2)[2]] = value.split('"')[1] - for jconf in ('/etc/jail.conf', '/usr/local/etc/jail.conf'): - if os.access(jconf, os.R_OK): - with salt.utils.fopen(jconf, 'r') as _fp: - for line in _fp: - if line.split()[0:2] == [jail, '{']: - break - for line in _fp: - if line.split()[-1] == '}': - break - if '=' not in line: - ret[line.strip().rstrip(";")] = 'true' - else: - key = line.split('=')[0].strip() - value = line.split('=')[-1].strip().strip(";'\"") - ret[key] = value + if subprocess.call(["jls", "-nq", "-j", jail]) == 0: + jls = subprocess.check_output(["jls", "-nq", "-j", jail]) + jailopts = shlex.split(jls) + for jailopt in jailopts: + if '=' not in jailopt: + ret[jailopt.strip().rstrip(";")] = '1' + else: + key = jailopt.split('=')[0].strip() + value = jailopt.split('=')[-1].strip().strip("\"") + ret[key] = value + else: + for rconf in ('/etc/rc.conf', '/etc/rc.conf.local'): + if os.access(rconf, os.R_OK): + with salt.utils.fopen(rconf, 'r') as _fp: + for line in _fp: + if not line.strip(): + continue + if not line.startswith('jail_{0}_'.format(jail)): + continue + key, value = line.split('=') + ret[key.split('_', 2)[2]] = value.split('"')[1] + for jconf in ('/etc/jail.conf', '/usr/local/etc/jail.conf'): + if os.access(jconf, os.R_OK): + with salt.utils.fopen(jconf, 'r') as _fp: + for line in _fp: + line = line.partition('#')[0].strip() + if line: + if line.split()[-1] == '{': + if line.split()[0] != jail and line.split()[0] != '*': + while line.split()[-1] != '}': + line = _fp.next() + line = line.partition('#')[0].strip() + else: + continue + if line.split()[-1] == '}': + continue + if '=' not in line: + ret[line.strip().rstrip(";")] = '1' + else: + key = line.split('=')[0].strip() + value = line.split('=')[-1].strip().strip(";'\"") + ret[key] = value return ret From 376cab00de69b15c966f53e04e43d7344c67cfc1 Mon Sep 17 00:00:00 2001 From: Thomas S Hatch Date: Fri, 8 Aug 2014 16:03:13 -0600 Subject: [PATCH 4/4] Lint fixes --- salt/modules/freebsdjail.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/salt/modules/freebsdjail.py b/salt/modules/freebsdjail.py index 9080697221..581e93ac5a 100644 --- a/salt/modules/freebsdjail.py +++ b/salt/modules/freebsdjail.py @@ -233,5 +233,3 @@ def sysctl(): key, value = line.split(':', 1) ret[key.strip()] = value.strip() return ret - -