3
from logging import exception
5
from landscape.log import format_object
6
from landscape.broker.client import BrokerClientPlugin
8
# Protocol messages! Same constants are defined in the server.
13
class ManagerPlugin(BrokerClientPlugin):
17
"""An alias for the C{client} attribute}."""
20
def call_with_operation_result(self, message, callable, *args, **kwargs):
21
"""Send an operation-result message after calling C{callable}.
23
If the function returns normally, an operation-result
24
indicating success will be sent. If the function raises an
25
exception, an operation-result indicating failure will be
28
@param message: The original message.
29
@param callable: The function to call to handle the message.
30
C{args} and C{kwargs} are passed to it.
33
text = callable(*args, **kwargs)
36
cls, obj = sys.exc_info()[:2]
37
text = "%s: %s" % (cls.__name__, obj)
38
exception("Error occured running message handler %s "
40
format_object(callable), args, kwargs)
43
operation_result = {"type": "operation-result", "status": status,
44
"operation-id": message["operation-id"]}
46
operation_result["result-text"] = text
47
return self.manager.broker.send_message(operation_result, urgent=True)