mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
RunnerClient support old style commands with kwargs on top level.
1. Use low['args'] low['kwargs'] if specified and not empty in the low data. 2. Lookup root level and set kwargs in low data if missing.
This commit is contained in:
parent
10b522b86c
commit
53e7a6b7c5
3 changed files with 19 additions and 11 deletions
|
@ -262,7 +262,7 @@ def parse_args_and_kwargs(func, args, data=None):
|
|||
return load_args_and_kwargs(func, args, data=data)
|
||||
|
||||
|
||||
def load_args_and_kwargs(func, args, data=None):
|
||||
def load_args_and_kwargs(func, args, data=None, ignore_invalid=False):
|
||||
'''
|
||||
Detect the args and kwargs that need to be passed to a function call, and
|
||||
check them against what was passed.
|
||||
|
@ -316,7 +316,7 @@ def load_args_and_kwargs(func, args, data=None):
|
|||
else:
|
||||
_args.append(arg)
|
||||
|
||||
if invalid_kwargs:
|
||||
if invalid_kwargs and not ignore_invalid:
|
||||
salt.utils.invalid_kwargs(invalid_kwargs)
|
||||
|
||||
if argspec.keywords and isinstance(data, dict):
|
||||
|
|
|
@ -141,10 +141,6 @@ class NetapiClient(object):
|
|||
:return: Returns the result from the runner module
|
||||
'''
|
||||
kwargs['fun'] = fun
|
||||
if 'kwargs' not in kwargs:
|
||||
kwargs['kwargs'] = {}
|
||||
if 'args' not in kwargs:
|
||||
kwargs['args'] = []
|
||||
runner = salt.runner.RunnerClient(self.opts)
|
||||
return runner.cmd_sync(kwargs, timeout=timeout)
|
||||
|
||||
|
@ -160,10 +156,6 @@ class NetapiClient(object):
|
|||
:return: event data and a job ID for the executed function.
|
||||
'''
|
||||
kwargs['fun'] = fun
|
||||
if 'kwargs' not in kwargs:
|
||||
kwargs['kwargs'] = {}
|
||||
if 'args' not in kwargs:
|
||||
kwargs['args'] = []
|
||||
runner = salt.runner.RunnerClient(self.opts)
|
||||
return runner.cmd_async(kwargs)
|
||||
|
||||
|
|
|
@ -59,8 +59,24 @@ class RunnerClient(mixins.SyncClientMixin, mixins.AsyncClientMixin, object):
|
|||
auth_creds = dict([(i, low.pop(i)) for i in [
|
||||
'username', 'password', 'eauth', 'token', 'client',
|
||||
] if i in low])
|
||||
reformatted_low = {'fun': low.pop('fun')}
|
||||
fun = low.pop('fun')
|
||||
reformatted_low = {'fun': fun}
|
||||
reformatted_low.update(auth_creds)
|
||||
# Support old style calls where arguments could be specified in 'low' top level
|
||||
if not low.get('args') and not low.get('kwargs'): # not specified or empty
|
||||
verify_fun(self.functions, fun)
|
||||
args, kwargs = salt.minion.load_args_and_kwargs(
|
||||
self.functions[fun],
|
||||
salt.utils.args.condition_input([], low),
|
||||
self.opts,
|
||||
ignore_invalid=True
|
||||
)
|
||||
low['args'] = args
|
||||
low['kwargs'] = kwargs
|
||||
if 'kwargs' not in low:
|
||||
low['kwargs'] = {}
|
||||
if 'args' not in low:
|
||||
low['args'] = []
|
||||
reformatted_low['kwarg'] = low
|
||||
return reformatted_low
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue