3
from logging import exception
5
from landscape.log import format_object
6
from landscape.plugin import Plugin, BrokerClientPluginRegistry, BrokerPlugin
7
1
from landscape.manager.store import ManagerStore
8
from landscape.lib.dbus_util import method
2
from landscape.broker.client import BrokerClient
10
4
# Protocol messages! Same constants are defined in the server.
14
SERVICE = "com.canonical.landscape.manager"
17
BUS_NAME = "com.canonical.landscape.Manager"
18
OBJECT_PATH = "/com/canonical/landscape/Manager"
22
class ManagerDBusObject(BrokerPlugin):
23
"""A DBUS object which provides an interface to the Landscape Manager."""
26
object_path = OBJECT_PATH
28
ping = method(IFACE_NAME)(BrokerPlugin.ping)
29
exit = method(IFACE_NAME)(BrokerPlugin.exit)
30
message = method(IFACE_NAME)(BrokerPlugin.message)
33
class ManagerPluginRegistry(BrokerClientPluginRegistry):
9
class Manager(BrokerClient):
34
10
"""Central point of integration for the Landscape Manager."""
36
def __init__(self, broker, reactor, config, bus=None, store_filename=None):
37
super(ManagerPluginRegistry, self).__init__(broker)
14
def __init__(self, reactor, config):
15
super(Manager, self).__init__(reactor)
38
16
self.reactor = reactor
39
17
self.config = config
42
self.store = ManagerStore(store_filename)
47
class ManagerPlugin(Plugin):
49
def call_with_operation_result(self, message, callable, *args, **kwargs):
50
"""Send an operation-result message after calling C{callable}.
52
If the function returns normally, an operation-result
53
indicating success will be sent. If the function raises an
54
exception, an operation-result indicating failure will be
57
@param message: The original message.
58
@param callable: The function to call to handle the message.
59
C{args} and C{kwargs} are passed to it.
62
text = callable(*args, **kwargs)
65
cls, obj = sys.exc_info()[:2]
66
text = "%s: %s" % (cls.__name__, obj)
67
exception("Error occured running message handler %s "
69
format_object(callable), args, kwargs)
72
operation_result = {"type": "operation-result", "status": status,
73
"operation-id": message["operation-id"]}
75
operation_result["result-text"] = text
76
return self.registry.broker.send_message(operation_result, urgent=True)
18
self.store = ManagerStore(self.config.store_filename)