mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #20666 from cachedout/returner_context
Returner context
This commit is contained in:
commit
290b9216d9
@ -153,15 +153,18 @@ def proxy(opts, functions, whitelist=None):
|
||||
pack={'__proxy__': functions})
|
||||
|
||||
|
||||
def returners(opts, functions, whitelist=None):
|
||||
def returners(opts, functions, whitelist=None, context=None):
|
||||
'''
|
||||
Returns the returner modules
|
||||
'''
|
||||
if context is None:
|
||||
context = {}
|
||||
return LazyLoader(_module_dirs(opts, 'returners', 'returner'),
|
||||
opts,
|
||||
tag='returner',
|
||||
whitelist=whitelist,
|
||||
pack={'__salt__': functions})
|
||||
pack={'__salt__': functions,
|
||||
'__context__': context})
|
||||
|
||||
|
||||
def utils(opts, whitelist=None):
|
||||
|
@ -156,12 +156,23 @@ def _get_serv(ret=None, commit=False):
|
||||
Return a mysql cursor
|
||||
'''
|
||||
_options = _get_options(ret)
|
||||
|
||||
if __context__ and 'mysql_returner_conn' in __context__:
|
||||
log.debug('Reusing MySQL connection pool')
|
||||
conn = __context__['mysql_returner_conn']
|
||||
else:
|
||||
log.debug('Generating new MySQL connection pool')
|
||||
try:
|
||||
conn = MySQLdb.connect(host=_options.get('host'),
|
||||
user=_options.get('user'),
|
||||
passwd=_options.get('pass'),
|
||||
db=_options.get('db'),
|
||||
port=_options.get('port'))
|
||||
|
||||
try:
|
||||
__context__['mysql_returner_conn'] = conn
|
||||
except TypeError:
|
||||
pass
|
||||
except MySQLdb.connections.OperationalError as exc:
|
||||
raise salt.exceptions.SaltMasterError('MySQL returner could not connect to database: {exc}'.format(exc=exc))
|
||||
cursor = conn.cursor()
|
||||
@ -177,8 +188,6 @@ def _get_serv(ret=None, commit=False):
|
||||
cursor.execute("COMMIT")
|
||||
else:
|
||||
cursor.execute("ROLLBACK")
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def returner(ret):
|
||||
|
Loading…
Reference in New Issue
Block a user