~free.ekanayaka/landscape-client/lucid-1.5.4-0ubuntu0.10.04.0

« back to all changes in this revision

Viewing changes to landscape/manager/manager.py

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2010-06-28 18:07:18 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100628180718-vytyqgbtkiirv5sb
Tags: 1.5.2.1-0ubuntu0.10.04.0
Filter duplicate network interfaces in get_active_interfaces (LP: #597000)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import sys
2
 
 
3
 
from logging import exception
4
 
 
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
9
3
 
10
4
# Protocol messages! Same constants are defined in the server.
11
5
FAILED = 5
12
6
SUCCEEDED = 6
13
7
 
14
 
SERVICE = "com.canonical.landscape.manager"
15
 
 
16
 
 
17
 
BUS_NAME = "com.canonical.landscape.Manager"
18
 
OBJECT_PATH = "/com/canonical/landscape/Manager"
19
 
IFACE_NAME = BUS_NAME
20
 
 
21
 
 
22
 
class ManagerDBusObject(BrokerPlugin):
23
 
    """A DBUS object which provides an interface to the Landscape Manager."""
24
 
 
25
 
    bus_name = BUS_NAME
26
 
    object_path = OBJECT_PATH
27
 
 
28
 
    ping = method(IFACE_NAME)(BrokerPlugin.ping)
29
 
    exit = method(IFACE_NAME)(BrokerPlugin.exit)
30
 
    message = method(IFACE_NAME)(BrokerPlugin.message)
31
 
 
32
 
 
33
 
class ManagerPluginRegistry(BrokerClientPluginRegistry):
 
8
 
 
9
class Manager(BrokerClient):
34
10
    """Central point of integration for the Landscape Manager."""
35
11
 
36
 
    def __init__(self, broker, reactor, config, bus=None, store_filename=None):
37
 
        super(ManagerPluginRegistry, self).__init__(broker)
 
12
    name = "manager"
 
13
 
 
14
    def __init__(self, reactor, config):
 
15
        super(Manager, self).__init__(reactor)
38
16
        self.reactor = reactor
39
17
        self.config = config
40
 
        self.bus = bus
41
 
        if store_filename:
42
 
            self.store = ManagerStore(store_filename)
43
 
        else:
44
 
            self.store = None
45
 
 
46
 
 
47
 
class ManagerPlugin(Plugin):
48
 
 
49
 
    def call_with_operation_result(self, message, callable, *args, **kwargs):
50
 
        """Send an operation-result message after calling C{callable}.
51
 
 
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
55
 
        sent.
56
 
 
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.
60
 
        """
61
 
        try:
62
 
            text = callable(*args, **kwargs)
63
 
        except:
64
 
            status = FAILED
65
 
            cls, obj = sys.exc_info()[:2]
66
 
            text = "%s: %s" % (cls.__name__, obj)
67
 
            exception("Error occured running message handler %s "
68
 
                      "with args %r %r.",
69
 
                      format_object(callable), args, kwargs)
70
 
        else:
71
 
            status = SUCCEEDED
72
 
        operation_result = {"type": "operation-result", "status": status,
73
 
                            "operation-id": message["operation-id"]}
74
 
        if text:
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)