mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
commit
14fe423e0c
@ -236,28 +236,6 @@ logger = logging.getLogger()
|
||||
# - "wheel" (need async api...)
|
||||
|
||||
|
||||
class SaltClientsMixIn(object):
|
||||
'''
|
||||
MixIn class to container all of the salt clients that the API needs
|
||||
'''
|
||||
# TODO: load this proactively, instead of waiting for a request
|
||||
__saltclients = None
|
||||
|
||||
@property
|
||||
def saltclients(self):
|
||||
if SaltClientsMixIn.__saltclients is None:
|
||||
local_client = salt.client.get_local_client(mopts=self.application.opts)
|
||||
# TODO: refreshing clients using cachedict
|
||||
SaltClientsMixIn.__saltclients = {
|
||||
'local': local_client.run_job_async,
|
||||
# not the actual client we'll use.. but its what we'll use to get args
|
||||
'local_async': local_client.run_job_async,
|
||||
'runner': salt.runner.RunnerClient(opts=self.application.opts).cmd_async,
|
||||
'runner_async': None, # empty, since we use the same client as `runner`
|
||||
}
|
||||
return SaltClientsMixIn.__saltclients
|
||||
|
||||
|
||||
AUTH_TOKEN_HEADER = 'X-Auth-Token'
|
||||
AUTH_COOKIE_NAME = 'session_id'
|
||||
|
||||
@ -388,7 +366,7 @@ class EventListener(object):
|
||||
del self.timeout_map[future]
|
||||
|
||||
|
||||
class BaseSaltAPIHandler(tornado.web.RequestHandler, SaltClientsMixIn): # pylint: disable=W0223
|
||||
class BaseSaltAPIHandler(tornado.web.RequestHandler): # pylint: disable=W0223
|
||||
ct_out_map = (
|
||||
('application/json', json.dumps),
|
||||
('application/x-yaml', yaml.safe_dump),
|
||||
@ -416,6 +394,16 @@ class BaseSaltAPIHandler(tornado.web.RequestHandler, SaltClientsMixIn): # pylin
|
||||
self.application.opts,
|
||||
)
|
||||
|
||||
if not hasattr(self, 'saltclients'):
|
||||
local_client = salt.client.get_local_client(mopts=self.application.opts)
|
||||
self.saltclients = {
|
||||
'local': local_client.run_job_async,
|
||||
# not the actual client we'll use.. but its what we'll use to get args
|
||||
'local_async': local_client.run_job_async,
|
||||
'runner': salt.runner.RunnerClient(opts=self.application.opts).cmd_async,
|
||||
'runner_async': None, # empty, since we use the same client as `runner`
|
||||
}
|
||||
|
||||
@property
|
||||
def token(self):
|
||||
'''
|
||||
@ -745,7 +733,7 @@ class SaltAuthHandler(BaseSaltAPIHandler): # pylint: disable=W0223
|
||||
self.write(self.serialize(ret))
|
||||
|
||||
|
||||
class SaltAPIHandler(BaseSaltAPIHandler, SaltClientsMixIn): # pylint: disable=W0223
|
||||
class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
|
||||
'''
|
||||
Main API handler for base "/"
|
||||
'''
|
||||
|
@ -559,6 +559,11 @@ class IPCMessagePublisher(object):
|
||||
io_loop=self.io_loop
|
||||
)
|
||||
self.streams.add(stream)
|
||||
|
||||
def discard_after_closed():
|
||||
self.streams.discard(stream)
|
||||
|
||||
stream.set_close_callback(discard_after_closed)
|
||||
except Exception as exc:
|
||||
log.error('IPC streaming error: {0}'.format(exc))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user