mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #14867 from thatch45/clinta-FreeBSD-jail-jls
Merge #14821 with fixes
This commit is contained in:
commit
deb1e2ce12
@ -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,16 +114,48 @@ def show_config(jail):
|
||||
salt '*' jail.show_config <jail name>
|
||||
'''
|
||||
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]
|
||||
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
|
||||
|
||||
|
||||
@ -140,6 +174,9 @@ 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:
|
||||
if os.access(c_fstab, os.R_OK):
|
||||
with salt.utils.fopen(c_fstab, 'r') as _fp:
|
||||
for line in _fp:
|
||||
|
Loading…
Reference in New Issue
Block a user