mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Add API wrapper to saltapi
This commit is contained in:
parent
697190e413
commit
3bade9d625
@ -0,0 +1,57 @@
|
||||
'''
|
||||
Make api awesomeness
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
#
|
||||
# Import Salt libs
|
||||
import salt.utils
|
||||
import salt.client
|
||||
import salt.runner
|
||||
|
||||
class API(object):
|
||||
'''
|
||||
'''
|
||||
def __init__(self, opts):
|
||||
self.opts = opts
|
||||
self.local = salt.client.LocalClient(opts['conf_file'])
|
||||
|
||||
def run(self, low):
|
||||
'''
|
||||
'''
|
||||
if not 'client' in low:
|
||||
raise SaltException('No client specified')
|
||||
l_fun = getattr(self, low['client'])
|
||||
fcall = salt.utils.format_call(l_fun, low)
|
||||
if 'kwargs' in fcall:
|
||||
ret = l_fun(*fcall['args'], **fcall['kwargs'])
|
||||
else:
|
||||
ret = l_fun(*f_call['args'])
|
||||
return ret
|
||||
|
||||
def cmd(
|
||||
tgt,
|
||||
fun,
|
||||
arg=(),
|
||||
expr_form='glob',
|
||||
ret='',
|
||||
timeout=None,
|
||||
**kwargs):
|
||||
'''
|
||||
Wrap running a job
|
||||
'''
|
||||
return self.local.run_job(
|
||||
tgt,
|
||||
fun,
|
||||
arg,
|
||||
expr_form,
|
||||
ret,
|
||||
timeout,
|
||||
**kwargs).get('jid')
|
||||
|
||||
def runner(fun, **kwargs):
|
||||
'''
|
||||
'''
|
||||
runner = salt.runner.RunnerClient(opts)
|
||||
return salt.runner.low(fun, kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user