/usr/share/pyshared/landscape/manager/plugin.py is in landscape-common 12.04.3-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import sys
from logging import exception
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.
@param message: The original message.
@param callable: The function to call to handle the message.
C{args} and C{kwargs} are passed to it.
"""
try:
text = callable(*args, **kwargs)
except:
status = FAILED
cls, obj = sys.exc_info()[:2]
text = "%s: %s" % (cls.__name__, obj)
exception("Error occured running message handler %s "
"with args %r %r.",
format_object(callable), args, kwargs)
else:
status = SUCCEEDED
operation_result = {"type": "operation-result", "status": status,
"operation-id": message["operation-id"]}
if text:
operation_result["result-text"] = text
return self.manager.broker.send_message(operation_result, urgent=True)
|