3
from logging import exception
5
from landscape.log import format_object
6
from landscape.plugin import Plugin, PluginRegistry, BrokerPlugin
7
from landscape.lib.dbus_util import method
9
# Protocol messages! Same constants are defined in the server.
13
SERVICE = "com.canonical.landscape.manager"
16
BUS_NAME = "com.canonical.landscape.Manager"
17
OBJECT_PATH = "/com/canonical/landscape/Manager"
21
class ManagerDBusObject(BrokerPlugin):
22
"""A DBUS object which provides an interface to the Landscape Manager."""
25
object_path = OBJECT_PATH
27
ping = method(IFACE_NAME)(BrokerPlugin.ping)
28
exit = method(IFACE_NAME)(BrokerPlugin.exit)
29
message = method(IFACE_NAME)(BrokerPlugin.message)
32
class ManagerPluginRegistry(PluginRegistry):
33
"""Central point of integration for the Landscape Manager."""
35
def __init__(self, reactor, broker, config, bus=None):
36
super(ManagerPluginRegistry, self).__init__()
37
self.reactor = reactor
43
class ManagerPlugin(Plugin):
45
def call_with_operation_result(self, message, callable, *args, **kwargs):
46
"""Send an operation-result message after calling C{callable}.
48
If the function returns normally, an operation-result
49
indicating success will be sent. If the function raises an
50
exception, an operation-result indicating failure will be
53
@param message: The original message.
54
@param callable: The function to call to handle the message.
55
C{args} and C{kwargs} are passed to it.
58
text = callable(*args, **kwargs)
61
cls, obj = sys.exc_info()[:2]
62
text = "%s: %s" % (cls.__name__, obj)
63
exception("Error occured running message handler %s "
65
format_object(callable), args, kwargs)
68
operation_result = {"type": "operation-result", "status": status,
69
"operation-id": message["operation-id"]}
71
operation_result["result-text"] = text
72
return self.registry.broker.send_message(operation_result, urgent=True)