move to systemd utils file code

This commit is contained in:
Thomas S Hatch 2015-02-25 13:12:32 -07:00
parent 8fd39ef646
commit 15b4ed1ca6

View File

@ -6,36 +6,21 @@ import os
import shutil
# Import Salt libs
import salt.defaults.exitcodes
import salt.utils.systemd
__virtualname__ = 'nspawn'
WANT = '/etc/systemd/system/multi-user.target.wants/systemd-nspawn@{0}.service'
def __virtual__():
'''
Only work on systems that have been booted with systemd
'''
if __grains__['kernel'] == 'Linux' and _sd_booted(__context__):
if __grains__['kernel'] == 'Linux' and salt.utils.systemd.booted(__context__):
return __virtualname__
return False
def _sd_booted(context):
'''
Return True if the system was booted with systemd, False otherwise.
'''
# We can cache this for as long as the minion runs.
if "systemd.sd_booted" not in context:
try:
# This check does the same as sd_booted() from libsystemd-daemon:
# http://www.freedesktop.org/software/systemd/man/sd_booted.html
if os.stat('/run/systemd/system'):
context['systemd.sd_booted'] = True
except OSError:
context['systemd.sd_booted'] = False
return context['systemd.sd_booted']
def _arch_bootstrap(name, **kwargs):
'''
Bootstrap an Arch Linux container