Exscript.util.decorator module¶
Decorators for callbacks passed to Queue.run().
-
Exscript.util.decorator.
autoauthenticate
(flush=True, attempts=1)[source]¶ Wraps the given function such that conn.authenticate() is executed before calling it. Example:
@autoauthenticate(attempts = 2) def my_func(job, host, conn): pass # Do something. Exscript.util.start.quickrun('myhost', my_func)
Parameters: - flush (bool) – Whether to flush the last prompt from the buffer.
- attempts (int) – The number of login attempts if login fails.
Return type: function
Returns: The wrapped function.
-
Exscript.util.decorator.
autologin
(flush=True, attempts=1)[source]¶ Wraps the given function such that conn.login() is executed before calling it. Example:
@autologin(attempts = 2) def my_func(job, host, conn): pass # Do something. Exscript.util.start.quickrun('myhost', my_func)
Parameters: - flush (bool) – Whether to flush the last prompt from the buffer.
- attempts (int) – The number of login attempts if login fails.
Return type: function
Returns: The wrapped function.
-
Exscript.util.decorator.
bind
(function, *args, **kwargs)[source]¶ Wraps the given function such that when it is called, the given arguments are passed in addition to the connection argument.
Parameters: - function (function) – The function that’s ought to be wrapped.
- args (list) – Passed on to the called function.
- kwargs (dict) – Passed on to the called function.
Return type: function
Returns: The wrapped function.
-
Exscript.util.decorator.
os_function_mapper
(map)[source]¶ When called with an open connection, this function uses the conn.guess_os() function to guess the operating system of the connected host. It then uses the given map to look up a function name that corresponds to the operating system, and calls it. Example:
def ios_xr(job, host, conn): pass # Do something. def junos(job, host, conn): pass # Do something else. def shell(job, host, conn): pass # Do something else. Exscript.util.start.quickrun('myhost', os_function_mapper(globals()))
An exception is raised if a matching function is not found in the map.
Parameters: - conn (Exscript.protocols.Protocol) – The open connection.
- map (dict) – A dictionary mapping operating system name to a function.
- args (list) – Passed on to the called function.
- kwargs (dict) – Passed on to the called function.
Return type: object
Returns: The return value of the called function.