| Server IP : 61.19.30.66 / Your IP : 216.73.216.15 Web Server : Apache/2.2.22 (Ubuntu) System : Linux klw 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 User : www-data ( 33) PHP Version : 5.3.10-1ubuntu3.48 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /usr/share/pyshared/landscape/manager/ |
Upload File : |
from twisted.internet.defer import maybeDeferred
from landscape.lib.log import log_failure
from landscape.log import format_object
from landscape.broker.client import BrokerClientPlugin
# Protocol messages! Same constants are defined in the server.
FAILED = 5
SUCCEEDED = 6
class ManagerPlugin(BrokerClientPlugin):
@property
def manager(self):
"""An alias for the C{client} attribute}."""
return self.client
def call_with_operation_result(self, message, callable, *args, **kwargs):
"""Send an operation-result message after calling C{callable}.
If the function returns normally, an operation-result
indicating success will be sent. If the function raises an
exception, an operation-result indicating failure will be
sent.
The function can also return a C{Deferred}, and the behavior above
still applies.
@param message: The original message.
@param callable: The function to call to handle the message.
C{args} and C{kwargs} are passed to it.
"""
deferred = maybeDeferred(callable, *args, **kwargs)
def success(text):
return SUCCEEDED, text
def failure(failure):
text = "%s: %s" % (failure.type.__name__, failure.value)
msg = ("Error occured running message handler %s with "
"args %r %r.", format_object(callable), args, kwargs)
log_failure(failure, msg=msg)
return FAILED, text
def send((status, text)):
result = {"type": "operation-result",
"status": status,
"operation-id": message["operation-id"]}
if text:
result["result-text"] = text
return self.manager.broker.send_message(result, urgent=True)
deferred.addCallback(success)
deferred.addErrback(failure)
deferred.addCallback(send)
return deferred