-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstacker.py
49 lines (37 loc) · 1.19 KB
/
stacker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
import logging
import json
import salt.utils.http
log = logging.getLogger(__name__)
def ext_pillar(minion_id, pillar, *args, **kwargs):
host = kwargs.get('host', None) or args[0]
namespace = kwargs.get('namespace', None)
log_level = kwargs.get('log_level', None)
if host == None:
log.warning("Cannot contact Stacker with host null")
return {}
host = '%s/%s' % (host, minion_id)
params = {}
if log_level != None:
params['l'] = log_level
if namespace != None:
params['n'] = namespace
data = json.dumps({ 'grains': __grains__.value(), 'pillar': pillar })
result = salt.utils.http.query(
host,
method = 'POST',
params = params,
data = data,
header_dict = { 'Content-Type': 'application/json' }
)
if 'body' in result:
result = result['body']
result = json.loads(result)
if result == {'404': 'Stacker: namespace not found'} or result == {'404': 'Stacker: host not found'}:
log.warning("Error while contacting Stacker for %s : %s" % (minion_id, result))
return {}
else:
return result
else:
log.error("Error while contacting Stacker for %s : %s" % (minion_id, result))
return {}