mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Merge pull request #50421 from weswhet/fix-mac_system-loader
fixing an issue on mac_system where the virtual function wouldnt load
This commit is contained in:
commit
fccf875077
@ -8,7 +8,6 @@ System module for sleeping, restarting, and shutting down the system on Mac OS X
|
||||
Using this module will enable ``atrun`` on the system if it is disabled.
|
||||
'''
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
import os
|
||||
|
||||
# Import python libs
|
||||
try: # python 3
|
||||
@ -19,8 +18,6 @@ except ImportError: # python 2
|
||||
import getpass
|
||||
|
||||
# Import salt libs
|
||||
from salt.ext import six
|
||||
import salt.utils.mac_utils
|
||||
import salt.utils.platform
|
||||
from salt.exceptions import SaltInvocationError, CommandExecutionError
|
||||
|
||||
@ -47,35 +44,10 @@ def __virtual__():
|
||||
|
||||
def _atrun_enabled():
|
||||
'''
|
||||
Check to see if atrun is enabled on the system
|
||||
Check to see if atrun is running and enabled on the system
|
||||
'''
|
||||
name = 'com.apple.atrun'
|
||||
services = __utils__['mac_utils.available_services']()
|
||||
label = None
|
||||
|
||||
if name in services:
|
||||
label = services[name]['plist']['Label']
|
||||
else:
|
||||
for service in six.itervalues(services):
|
||||
if service['file_path'].lower() == name:
|
||||
# Match on full path
|
||||
label = service['plist']['Label']
|
||||
break
|
||||
basename, ext = os.path.splitext(service['file_name'])
|
||||
if basename.lower() == name:
|
||||
# Match on basename
|
||||
label = service['plist']['Label']
|
||||
break
|
||||
|
||||
if not label:
|
||||
return False
|
||||
|
||||
try:
|
||||
# Collect information on service: will raise an error if it fails
|
||||
salt.utils.mac_utils.launchctl('list',
|
||||
label,
|
||||
return_stdout=True)
|
||||
return True
|
||||
return __salt__['service.list']('com.apple.atrun')
|
||||
except CommandExecutionError:
|
||||
return False
|
||||
|
||||
@ -85,33 +57,11 @@ def _enable_atrun():
|
||||
Enable and start the atrun daemon
|
||||
'''
|
||||
name = 'com.apple.atrun'
|
||||
services = __utils__['mac_utils.available_services']()
|
||||
label = None
|
||||
path = None
|
||||
|
||||
if name in services:
|
||||
label = services[name]['plist']['Label']
|
||||
path = services[name]['file_path']
|
||||
else:
|
||||
for service in six.itervalues(services):
|
||||
if service['file_path'].lower() == name:
|
||||
# Match on full path
|
||||
label = service['plist']['Label']
|
||||
path = service['file_path']
|
||||
break
|
||||
basename, ext = os.path.splitext(service['file_name'])
|
||||
if basename.lower() == name:
|
||||
# Match on basename
|
||||
label = service['plist']['Label']
|
||||
path = service['file_path']
|
||||
break
|
||||
|
||||
if not label:
|
||||
try:
|
||||
__salt__['service.enable'](name)
|
||||
__salt__['service.start'](name)
|
||||
except CommandExecutionError:
|
||||
return False
|
||||
|
||||
salt.utils.mac_utils.launchctl('enable',
|
||||
'system/{0}'.format(label))
|
||||
salt.utils.mac_utils.launchctl('load', path)
|
||||
return _atrun_enabled()
|
||||
|
||||
|
||||
@ -259,11 +209,11 @@ def get_remote_login():
|
||||
|
||||
salt '*' system.get_remote_login
|
||||
'''
|
||||
ret = salt.utils.mac_utils.execute_return_result(
|
||||
ret = __utils__['mac_utils.execute_return_result'](
|
||||
'systemsetup -getremotelogin')
|
||||
|
||||
enabled = salt.utils.mac_utils.validate_enabled(
|
||||
salt.utils.mac_utils.parse_return(ret))
|
||||
enabled = __utils__['mac_utils.validate_enabled'](
|
||||
__utils__['mac_utils.parse_return'](ret))
|
||||
|
||||
return enabled == 'on'
|
||||
|
||||
@ -285,16 +235,14 @@ def set_remote_login(enable):
|
||||
|
||||
salt '*' system.set_remote_login True
|
||||
'''
|
||||
state = salt.utils.mac_utils.validate_enabled(enable)
|
||||
state = __utils__['mac_utils.validate_enabled'](enable)
|
||||
|
||||
cmd = 'systemsetup -f -setremotelogin {0}'.format(state)
|
||||
salt.utils.mac_utils.execute_return_success(cmd)
|
||||
__utils__['mac_utils.execute_return_success'](cmd)
|
||||
|
||||
return salt.utils.mac_utils.confirm_updated(
|
||||
state,
|
||||
get_remote_login,
|
||||
normalize_ret=True,
|
||||
)
|
||||
return __utils__['mac_utils.confirm_updated'](state,
|
||||
get_remote_login,
|
||||
normalize_ret=True)
|
||||
|
||||
|
||||
def get_remote_events():
|
||||
@ -310,11 +258,11 @@ def get_remote_events():
|
||||
|
||||
salt '*' system.get_remote_events
|
||||
'''
|
||||
ret = salt.utils.mac_utils.execute_return_result(
|
||||
ret = __utils__['mac_utils.execute_return_result'](
|
||||
'systemsetup -getremoteappleevents')
|
||||
|
||||
enabled = salt.utils.mac_utils.validate_enabled(
|
||||
salt.utils.mac_utils.parse_return(ret))
|
||||
enabled = __utils__['mac_utils.validate_enabled'](
|
||||
__utils__['mac_utils.parse_return'](ret))
|
||||
|
||||
return enabled == 'on'
|
||||
|
||||
@ -337,12 +285,12 @@ def set_remote_events(enable):
|
||||
|
||||
salt '*' system.set_remote_events On
|
||||
'''
|
||||
state = salt.utils.mac_utils.validate_enabled(enable)
|
||||
state = __utils__['mac_utils.validate_enabled'](enable)
|
||||
|
||||
cmd = 'systemsetup -setremoteappleevents {0}'.format(state)
|
||||
salt.utils.mac_utils.execute_return_success(cmd)
|
||||
__utils__['mac_utils.execute_return_success'](cmd)
|
||||
|
||||
return salt.utils.mac_utils.confirm_updated(
|
||||
return __utils__['mac_utils.confirm_updated'](
|
||||
state,
|
||||
get_remote_events,
|
||||
normalize_ret=True,
|
||||
@ -362,10 +310,10 @@ def get_computer_name():
|
||||
|
||||
salt '*' system.get_computer_name
|
||||
'''
|
||||
ret = salt.utils.mac_utils.execute_return_result(
|
||||
ret = __utils__['mac_utils.execute_return_result'](
|
||||
'systemsetup -getcomputername')
|
||||
|
||||
return salt.utils.mac_utils.parse_return(ret)
|
||||
return __utils__['mac_utils.parse_return'](ret)
|
||||
|
||||
|
||||
def set_computer_name(name):
|
||||
@ -384,9 +332,9 @@ def set_computer_name(name):
|
||||
salt '*' system.set_computer_name "Mike's Mac"
|
||||
'''
|
||||
cmd = 'systemsetup -setcomputername "{0}"'.format(name)
|
||||
salt.utils.mac_utils.execute_return_success(cmd)
|
||||
__utils__['mac_utils.execute_return_success'](cmd)
|
||||
|
||||
return salt.utils.mac_utils.confirm_updated(
|
||||
return __utils__['mac_utils.confirm_updated'](
|
||||
name,
|
||||
get_computer_name,
|
||||
)
|
||||
@ -405,10 +353,10 @@ def get_subnet_name():
|
||||
|
||||
salt '*' system.get_subnet_name
|
||||
'''
|
||||
ret = salt.utils.mac_utils.execute_return_result(
|
||||
ret = __utils__['mac_utils.execute_return_result'](
|
||||
'systemsetup -getlocalsubnetname')
|
||||
|
||||
return salt.utils.mac_utils.parse_return(ret)
|
||||
return __utils__['mac_utils.parse_return'](ret)
|
||||
|
||||
|
||||
def set_subnet_name(name):
|
||||
@ -431,9 +379,9 @@ def set_subnet_name(name):
|
||||
salt '*' system.set_subnet_name "Mike's Mac"
|
||||
'''
|
||||
cmd = 'systemsetup -setlocalsubnetname "{0}"'.format(name)
|
||||
salt.utils.mac_utils.execute_return_success(cmd)
|
||||
__utils__['mac_utils.execute_return_success'](cmd)
|
||||
|
||||
return salt.utils.mac_utils.confirm_updated(
|
||||
return __utils__['mac_utils.confirm_updated'](
|
||||
name,
|
||||
get_subnet_name,
|
||||
)
|
||||
@ -452,10 +400,10 @@ def get_startup_disk():
|
||||
|
||||
salt '*' system.get_startup_disk
|
||||
'''
|
||||
ret = salt.utils.mac_utils.execute_return_result(
|
||||
ret = __utils__['mac_utils.execute_return_result'](
|
||||
'systemsetup -getstartupdisk')
|
||||
|
||||
return salt.utils.mac_utils.parse_return(ret)
|
||||
return __utils__['mac_utils.parse_return'](ret)
|
||||
|
||||
|
||||
def list_startup_disks():
|
||||
@ -471,7 +419,7 @@ def list_startup_disks():
|
||||
|
||||
salt '*' system.list_startup_disks
|
||||
'''
|
||||
ret = salt.utils.mac_utils.execute_return_result(
|
||||
ret = __utils__['mac_utils.execute_return_result'](
|
||||
'systemsetup -liststartupdisks')
|
||||
|
||||
return ret.splitlines()
|
||||
@ -501,9 +449,9 @@ def set_startup_disk(path):
|
||||
raise SaltInvocationError(msg)
|
||||
|
||||
cmd = 'systemsetup -setstartupdisk {0}'.format(path)
|
||||
salt.utils.mac_utils.execute_return_result(cmd)
|
||||
__utils__['mac_utils.execute_return_result'](cmd)
|
||||
|
||||
return salt.utils.mac_utils.confirm_updated(
|
||||
return __utils__['mac_utils.confirm_updated'](
|
||||
path,
|
||||
get_startup_disk,
|
||||
)
|
||||
@ -524,10 +472,10 @@ def get_restart_delay():
|
||||
|
||||
salt '*' system.get_restart_delay
|
||||
'''
|
||||
ret = salt.utils.mac_utils.execute_return_result(
|
||||
ret = __utils__['mac_utils.execute_return_result'](
|
||||
'systemsetup -getwaitforstartupafterpowerfailure')
|
||||
|
||||
return salt.utils.mac_utils.parse_return(ret)
|
||||
return __utils__['mac_utils.parse_return'](ret)
|
||||
|
||||
|
||||
def set_restart_delay(seconds):
|
||||
@ -565,9 +513,9 @@ def set_restart_delay(seconds):
|
||||
raise SaltInvocationError(msg)
|
||||
|
||||
cmd = 'systemsetup -setwaitforstartupafterpowerfailure {0}'.format(seconds)
|
||||
salt.utils.mac_utils.execute_return_success(cmd)
|
||||
__utils__['mac_utils.execute_return_success'](cmd)
|
||||
|
||||
return salt.utils.mac_utils.confirm_updated(
|
||||
return __utils__['mac_utils.confirm_updated'](
|
||||
seconds,
|
||||
get_restart_delay,
|
||||
)
|
||||
@ -587,11 +535,11 @@ def get_disable_keyboard_on_lock():
|
||||
|
||||
salt '*' system.get_disable_keyboard_on_lock
|
||||
'''
|
||||
ret = salt.utils.mac_utils.execute_return_result(
|
||||
ret = __utils__['mac_utils.execute_return_result'](
|
||||
'systemsetup -getdisablekeyboardwhenenclosurelockisengaged')
|
||||
|
||||
enabled = salt.utils.mac_utils.validate_enabled(
|
||||
salt.utils.mac_utils.parse_return(ret))
|
||||
enabled = __utils__['mac_utils.validate_enabled'](
|
||||
__utils__['mac_utils.parse_return'](ret))
|
||||
|
||||
return enabled == 'on'
|
||||
|
||||
@ -614,13 +562,13 @@ def set_disable_keyboard_on_lock(enable):
|
||||
|
||||
salt '*' system.set_disable_keyboard_on_lock False
|
||||
'''
|
||||
state = salt.utils.mac_utils.validate_enabled(enable)
|
||||
state = __utils__['mac_utils.validate_enabled'](enable)
|
||||
|
||||
cmd = 'systemsetup -setdisablekeyboardwhenenclosurelockisengaged ' \
|
||||
'{0}'.format(state)
|
||||
salt.utils.mac_utils.execute_return_success(cmd)
|
||||
__utils__['mac_utils.execute_return_success'](cmd)
|
||||
|
||||
return salt.utils.mac_utils.confirm_updated(
|
||||
return __utils__['mac_utils.confirm_updated'](
|
||||
state,
|
||||
get_disable_keyboard_on_lock,
|
||||
normalize_ret=True,
|
||||
@ -640,10 +588,10 @@ def get_boot_arch():
|
||||
|
||||
salt '*' system.get_boot_arch
|
||||
'''
|
||||
ret = salt.utils.mac_utils.execute_return_result(
|
||||
ret = __utils__['mac_utils.execute_return_result'](
|
||||
'systemsetup -getkernelbootarchitecturesetting')
|
||||
|
||||
arch = salt.utils.mac_utils.parse_return(ret)
|
||||
arch = __utils__['mac_utils.parse_return'](ret)
|
||||
|
||||
if 'default' in arch:
|
||||
return 'default'
|
||||
@ -688,9 +636,9 @@ def set_boot_arch(arch='default'):
|
||||
raise SaltInvocationError(msg)
|
||||
|
||||
cmd = 'systemsetup -setkernelbootarchitecture {0}'.format(arch)
|
||||
salt.utils.mac_utils.execute_return_success(cmd)
|
||||
__utils__['mac_utils.execute_return_success'](cmd)
|
||||
|
||||
return salt.utils.mac_utils.confirm_updated(
|
||||
return __utils__['mac_utils.confirm_updated'](
|
||||
arch,
|
||||
get_boot_arch,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user