Hi,
I am finalizing a module which needs, for pretty much every function,
to create a session, and logout that session when the job is done.
To achieve this, I used a simple decorator:
def _session_handle(function):
def _internal(*args, **kwargs):
_session = _get_session()
ret = function(_session.xenapi, *args, **kwargs)
_session.logout()
return ret
return _internal
Which is referred to like this:
@_session_handle
def vm_info(xapi, vm_=None):
While the module behaves correctly when it is called from `salt-call', it
fails with the following error when it's called from plain `salt':
$ sudo salt 'coruscant' virt.vm_info
coruscant:
Missing arguments executing "virt.vm_info": ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None)
First I thought it was related to the fact that the decorator added a session
parameter to the functions, so I made the session variable global, so the
decorator now looks like this:
def _session_handle(function):
def _internal(*args, **kwargs):
global xapi
_session = _get_session()
xapi = _session.xenapi
ret = function(*args, **kwargs)
_session.logout()
return ret
return _internal
Nevertheless, I am still stuck with the same "Missing argument" error.
Is there any known issue when using a decorator within modules? I can't
actually find one that uses it except for @salt.utils.memoize.
Thanks for any pointer.
Cheers,
------------------------------------------------------------------
Emile `iMil' Heitor .ᅵ. <imil@{
home.imil.net,NetBSD.org,
gcu.info}>
_
|
http://imil.net | ASCII ribbon campaign ( )
|
http://www.NetBSD.org | - against HTML email X
|
http://gcu.info | & vCards / \