mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Revert "port format_all to salt-api pending updates in salt core"
This reverts commit bc3d492791
.
These changes are now in Salt core.
Conflicts:
saltapi/__init__.py
This commit is contained in:
parent
385530b967
commit
4d98d72cd7
@ -35,7 +35,7 @@ class APIClient(object):
|
|||||||
raise SaltException('No client specified')
|
raise SaltException('No client specified')
|
||||||
|
|
||||||
l_fun = getattr(self, low['client'])
|
l_fun = getattr(self, low['client'])
|
||||||
f_call = format_call(l_fun, low)
|
f_call = salt.utils.format_call(l_fun, low)
|
||||||
|
|
||||||
ret = l_fun(*f_call.get('args', ()), **f_call.get('kwargs', {}))
|
ret = l_fun(*f_call.get('args', ()), **f_call.get('kwargs', {}))
|
||||||
return ret
|
return ret
|
||||||
@ -61,64 +61,3 @@ class APIClient(object):
|
|||||||
kwargs['fun'] = fun
|
kwargs['fun'] = fun
|
||||||
wheel = salt.wheel.Wheel(self.opts)
|
wheel = salt.wheel.Wheel(self.opts)
|
||||||
return wheel.master_call(**kwargs)
|
return wheel.master_call(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
### Remove when salt 0.10.5 is released!
|
|
||||||
def _getargs(func):
|
|
||||||
'''
|
|
||||||
A small wrapper around getargspec that also supports callable classes
|
|
||||||
'''
|
|
||||||
if not callable(func):
|
|
||||||
raise TypeError('{0} is not a callable'.format(func))
|
|
||||||
|
|
||||||
if inspect.isfunction(func):
|
|
||||||
aspec = inspect.getargspec(func)
|
|
||||||
elif inspect.ismethod(func):
|
|
||||||
aspec = inspect.getargspec(func)
|
|
||||||
del aspec.args[0] # self
|
|
||||||
elif isinstance(func, object):
|
|
||||||
aspec = inspect.getargspec(func.__call__)
|
|
||||||
del aspec.args[0] # self
|
|
||||||
else:
|
|
||||||
raise TypeError("Cannot inspect argument list for '{0}'".format(func))
|
|
||||||
|
|
||||||
return aspec
|
|
||||||
|
|
||||||
|
|
||||||
def format_call(fun, data):
|
|
||||||
'''
|
|
||||||
Pass in a function and a dict containing arguments to the function.
|
|
||||||
|
|
||||||
A dict with the keys args and kwargs is returned
|
|
||||||
'''
|
|
||||||
ret = {}
|
|
||||||
ret['args'] = []
|
|
||||||
aspec = _getargs(fun)
|
|
||||||
arglen = 0
|
|
||||||
deflen = 0
|
|
||||||
if isinstance(aspec.args, list):
|
|
||||||
arglen = len(aspec.args)
|
|
||||||
if isinstance(aspec.defaults, tuple):
|
|
||||||
deflen = len(aspec.defaults)
|
|
||||||
if aspec.keywords:
|
|
||||||
# This state accepts kwargs
|
|
||||||
ret['kwargs'] = {}
|
|
||||||
for key in data:
|
|
||||||
# Passing kwargs the conflict with args == stack trace
|
|
||||||
if key in aspec.args:
|
|
||||||
continue
|
|
||||||
ret['kwargs'][key] = data[key]
|
|
||||||
kwargs = {}
|
|
||||||
for ind in range(arglen - 1, 0, -1):
|
|
||||||
minus = arglen - ind
|
|
||||||
if deflen - minus > -1:
|
|
||||||
kwargs[aspec.args[ind]] = aspec.defaults[-minus]
|
|
||||||
for arg in kwargs:
|
|
||||||
if arg in data:
|
|
||||||
kwargs[arg] = data[arg]
|
|
||||||
for arg in aspec.args:
|
|
||||||
if arg in kwargs:
|
|
||||||
ret['args'].append(kwargs[arg])
|
|
||||||
else:
|
|
||||||
ret['args'].append(data[arg])
|
|
||||||
return ret
|
|
||||||
|
Loading…
Reference in New Issue
Block a user