Use explicit declaration for mac_utils functions

This commit is contained in:
twangboy 2016-03-04 16:57:33 -07:00
parent 75546eadaf
commit b19927d4b3

View File

@ -11,8 +11,7 @@ from datetime import datetime
# Import salt libs
import salt.utils
from salt.utils.mac_utils import execute_return_result, \
execute_return_success, parse_return, validate_enabled
import salt.utils.mac_utils as mac_utils
from salt.exceptions import CommandExecutionError
__virtualname__ = 'timezone'
@ -69,8 +68,8 @@ def get_date():
salt '*' timezone.get_date
'''
ret = execute_return_result('systemsetup -getdate')
return parse_return(ret)
ret = mac_utils.execute_return_result('systemsetup -getdate')
return mac_utils.parse_return(ret)
def set_date(date):
@ -96,7 +95,7 @@ def set_date(date):
dt_obj = datetime.strptime(date, date_format)
cmd = 'systemsetup -setdate {0}'.format(dt_obj.strftime('%m:%d:%Y'))
execute_return_success(cmd)
mac_utils.execute_return_success(cmd)
new_date = get_date()
date_format = _get_date_time_format(new_date)
@ -118,8 +117,8 @@ def get_time():
salt '*' timezone.get_time
'''
ret = execute_return_result('systemsetup -gettime')
return parse_return(ret)
ret = mac_utils.execute_return_result('systemsetup -gettime')
return mac_utils.parse_return(ret)
def set_time(time):
@ -143,7 +142,7 @@ def set_time(time):
dt_obj = datetime.strptime(time, time_format)
cmd = 'systemsetup -settime {0}'.format(dt_obj.strftime('%H:%M:%S'))
execute_return_success(cmd)
mac_utils.execute_return_success(cmd)
new_time = get_time()
time_format = _get_date_time_format(new_time)
@ -165,8 +164,8 @@ def get_zone():
salt '*' timezone.get_zone
'''
ret = execute_return_result('systemsetup -gettimezone')
return parse_return(ret)
ret = mac_utils.execute_return_result('systemsetup -gettimezone')
return mac_utils.parse_return(ret)
def get_zonecode():
@ -182,7 +181,7 @@ def get_zonecode():
salt '*' timezone.get_zonecode
'''
return execute_return_result('date +%Z')
return mac_utils.execute_return_result('date +%Z')
def get_offset():
@ -198,7 +197,7 @@ def get_offset():
salt '*' timezone.get_offset
'''
return execute_return_result('date +%z')
return mac_utils.execute_return_result('date +%z')
def list_zones():
@ -215,8 +214,8 @@ def list_zones():
salt '*' timezone.list_zones
'''
ret = execute_return_result('systemsetup -listtimezones')
return parse_return(ret)
ret = mac_utils.execute_return_result('systemsetup -listtimezones')
return mac_utils.parse_return(ret)
def set_zone(time_zone):
@ -239,7 +238,7 @@ def set_zone(time_zone):
return (False, 'Not a valid timezone. '
'Use list_time_zones to find a valid time zone.')
execute_return_success('systemsetup -settimezone {0}'.format(time_zone))
mac_utils.execute_return_success('systemsetup -settimezone {0}'.format(time_zone))
return time_zone in get_zone()
@ -278,12 +277,8 @@ def get_using_network_time():
salt '*' timezone.get_using_network_time
'''
ret = execute_return_result('systemsetup -getusingnetworktime')
if parse_return(ret) == 'On':
return True
else:
return False
ret = mac_utils.execute_return_result('systemsetup -getusingnetworktime')
return mac_utils.validate_enabled(mac_utils.parse_return(ret)) == 'on'
def set_using_network_time(enable):
@ -305,9 +300,9 @@ def set_using_network_time(enable):
state = validate_enabled(enable)
cmd = 'systemsetup -setusingnetworktime {0}'.format(state)
execute_return_success(cmd)
mac_utils.execute_return_success(cmd)
return state == validate_enabled(get_using_network_time())
return state == mac_utils.validate_enabled(get_using_network_time())
def get_time_server():
@ -323,8 +318,8 @@ def get_time_server():
salt '*' timezone.get_time_server
'''
ret = execute_return_result('systemsetup -getnetworktimeserver')
return parse_return(ret)
ret = mac_utils.execute_return_result('systemsetup -getnetworktimeserver')
return mac_utils.parse_return(ret)
def set_time_server(time_server='time.apple.com'):
@ -346,6 +341,6 @@ def set_time_server(time_server='time.apple.com'):
salt '*' timezone.set_time_server time.acme.com
'''
cmd = 'systemsetup -setnetworktimeserver {0}'.format(time_server)
execute_return_success(cmd)
mac_utils.execute_return_success(cmd)
return time_server in get_time_server()