mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix crash if the controller is down
This commit is contained in:
parent
a7d5aafbe3
commit
a2b1a71e01
1 changed files with 10 additions and 2 deletions
|
@ -119,7 +119,12 @@ def _set(lamp_id, state, method="state"):
|
|||
:return:
|
||||
'''
|
||||
url = "{0}/lights/{1}".format(CONFIG['url'], lamp_id) + (method and "/{0}".format(method) or '')
|
||||
res = json.loads(requests.put(url, json=state).content)
|
||||
res = None
|
||||
try:
|
||||
res = json.loads(requests.put(url, json=state).content)
|
||||
except Exception, err:
|
||||
raise CommandExecutionError(err)
|
||||
|
||||
res = len(res) > 1 and res[-1] or res[0]
|
||||
if res.get('success'):
|
||||
res = {'result': True}
|
||||
|
@ -151,7 +156,10 @@ def _get_lights():
|
|||
|
||||
:return:
|
||||
'''
|
||||
return json.loads(requests.get(CONFIG['url'] + "/lights").content)
|
||||
try:
|
||||
return json.loads(requests.get(CONFIG['url'] + "/lights").content)
|
||||
except Exception, exc:
|
||||
raise CommandExecutionError(exc)
|
||||
|
||||
|
||||
# Callers
|
||||
|
|
Loading…
Add table
Reference in a new issue