Fixed _valideate_enabled function

This commit is contained in:
twangboy 2016-01-26 14:14:34 -07:00
parent 67b20728d2
commit a1bfcafba6

View File

@ -122,30 +122,20 @@ def _validate_enabled(enabled):
''' '''
Helper function to validate the enabled parameter. Boolean values are Helper function to validate the enabled parameter. Boolean values are
converted to "on" and "off". String values are checked to make sure they are converted to "on" and "off". String values are checked to make sure they are
either "on" or "off". All other values return an error. either "on" or "off". Int 1+ and 0 are converted to "on" and "off"
Returns: "on" or "off" or errors Returns: "on" or "off" or errors
''' '''
if isinstance(enabled, bool): if isinstance(enabled, str):
if enabled: if enabled.lower() in ['on', 'off']:
return 'on' return enabled.lower
else: else:
return 'off' msg = '\nMac Power: Invalid String Value for Enabled.\n' \
elif isinstance(enabled, int): 'String values must be \'on\' or \'off\'.\n' \
if enabled in [1, 0]:
if enabled == 1:
return 'on'
else:
return 'off'
else:
msg = '\nMac Power: Invalid Integer Value for Enabled.\n' \
'Integer values must be 1 or 0.\n' \
'Passed: {0}'.format(enabled) 'Passed: {0}'.format(enabled)
raise SaltInvocationError(msg) raise SaltInvocationError(msg)
else: else:
msg = '\nMac Power: Unknown Variable Type Passed for Enabled.\n' \ return 'on' if bool(enabled) else 'off'
'Passed: {0}'.format(enabled)
raise SaltInvocationError(msg)
def get_sleep(): def get_sleep():