mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +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
96ab4e1607
commit
ca233e56e5
@ -260,7 +260,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.
|
||||
@ -314,7 +314,7 @@ def load_args_and_kwargs(func, args, data=None):
|
||||
else:
|
||||
_args.append(arg)
|
||||
|
||||
if invalid_kwargs:
|
||||
if invalid_kwargs and not ignore_invalid:
|
||||
raise SaltInvocationError(
|
||||
'The following keyword arguments are not valid: {0}'
|
||||
.format(', '.join(invalid_kwargs))
|
||||
|
@ -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…
Reference in New Issue
Block a user