~free.ekanayaka/landscape-client/jaunty-1.5.2.1-0ubuntu0.9.04.0

« back to all changes in this revision

Viewing changes to landscape/manager/plugin.py

  • Committer: Free Ekanayaka
  • Date: 2010-06-16 10:01:20 UTC
  • Revision ID: free.ekanayaka@canonical.com-20100616100120-k185twz19yf1qqmh
* New upstream version (LP: #594594):
  - A new includes information about active network devices and their
    IP address in sysinfo output (LP: #272344).
  - A new plugin collects information about network traffic (#LP :284662).
  - Report information about which packages requested a reboot (LP: #538253).
  - Fix breakage on Lucid AMIs having no ramdisk (LP: #574810).
  - Migrate the inter-process communication system from DBus to Twisted AMP.

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.broker.client import BrokerClientPlugin
 
7
 
 
8
# Protocol messages! Same constants are defined in the server.
 
9
FAILED = 5
 
10
SUCCEEDED = 6
 
11
 
 
12
 
 
13
class ManagerPlugin(BrokerClientPlugin):
 
14
 
 
15
    @property
 
16
    def manager(self):
 
17
        """An alias for the C{client} attribute}."""
 
18
        return self.client
 
19
 
 
20
    def call_with_operation_result(self, message, callable, *args, **kwargs):
 
21
        """Send an operation-result message after calling C{callable}.
 
22
 
 
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
 
26
        sent.
 
27
 
 
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.
 
31
        """
 
32
        try:
 
33
            text = callable(*args, **kwargs)
 
34
        except:
 
35
            status = FAILED
 
36
            cls, obj = sys.exc_info()[:2]
 
37
            text = "%s: %s" % (cls.__name__, obj)
 
38
            exception("Error occured running message handler %s "
 
39
                      "with args %r %r.",
 
40
                      format_object(callable), args, kwargs)
 
41
        else:
 
42
            status = SUCCEEDED
 
43
        operation_result = {"type": "operation-result", "status": status,
 
44
                            "operation-id": message["operation-id"]}
 
45
        if text:
 
46
            operation_result["result-text"] = text
 
47
        return self.manager.broker.send_message(operation_result, urgent=True)