Added new client and fun naming scheme so can have sync or async modes

instead of confusing client runner wheel etc.
To specify wheel or runner client prefix fun name with wheel or runner respectively
This commit is contained in:
Samuel M Smith 2013-08-06 14:14:40 -06:00
parent 82681d496a
commit 545daaed9f

View File

@ -27,10 +27,30 @@ class APIClient(object):
'''
Execute the specified function in the specified client by passing the
lowstate
New backwards compatible client and fun naming scheme.
In new scheme low['client'] is the client mode either 'sync' or 'async'.
Default is 'async'
If 'wheel' or 'runner' prefixes fun then use associated salt client given
by prefix in the specified 'sync' or 'async' mode.
Otherwise use local salt client in the given 'sync' or 'async' mode
'''
if not 'client' in low:
raise SaltException('No client specified')
low['client'] = 'async'
#raise SaltException('No client specified')
# check for wheel or runner prefix to fun name
funparts = low.get('fun', '').split('.')
if len(funparts) > 2 and funparts[0] in ['wheel', 'runner']:
if low['client'] not in ['sync', 'async']: #client should be only 'sync' or 'async'
raise SaltException('With fun of "{1}", client must be "sync" or "async" not "{0}".'\
.format(low['client'], low['fun']))
low['client'] = '{0}_{1}'.format(funparts[0], low['client'])
low['fun'] = '.'.join(funparts[1:]) #strip prefix
if not ('token' in low or 'eauth' in low):
raise EauthAuthenticationError(
'No authentication credentials given')
@ -51,8 +71,10 @@ class APIClient(object):
'''
local = salt.client.LocalClient(self.opts['conf_file'])
return local.run_job(*args, **kwargs)
async = local_async # default async client
def local(self, *args, **kwargs):
def local_sync(self, *args, **kwargs):
'''
Wrap LocalClient for running :ref:`execution modules <all-salt.modules>`
@ -60,18 +82,27 @@ class APIClient(object):
'''
local = salt.client.LocalClient(self.opts['conf_file'])
return local.cmd(*args, **kwargs)
local = local_sync # backwards compatible alias
sync = local_sync # default sync client
def runner(self, fun, **kwargs):
def runner_sync(self, fun, **kwargs):
'''
Wrap RunnerClient for executing :ref:`runner modules <all-salt.runners>`
'''
runner = salt.runner.RunnerClient(self.opts)
return runner.low(fun, kwargs)
runner = runner_sync #backwards compatible alias
runner_async = runner_sync # until we get an runner_async
def wheel(self, fun, **kwargs):
def wheel_sync(self, fun, **kwargs):
'''
Wrap Wheel to enable executing :ref:`wheel modules <all-salt.wheel>`
'''
kwargs['fun'] = fun
wheel = salt.wheel.Wheel(self.opts)
return wheel.master_call(**kwargs)
wheel = wheel_sync # backwards compatible alias
wheel_async = wheel_sync # so it works either mode