~wgrant/ubuntu/natty/landscape-client/natty-updates-broken

« back to all changes in this revision

Viewing changes to landscape/monitor/service.py

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2010-04-21 19:58:10 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: james.westby@ubuntu.com-20100421195810-s30uv3s6i27lue38
Tags: 1.5.2-0ubuntu0.10.10.0
* 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
"""Deployment code for the monitor."""
 
2
 
 
3
import os
 
4
 
 
5
from twisted.python.reflect import namedClass
 
6
 
 
7
from landscape.service import LandscapeService, run_landscape_service
 
8
from landscape.monitor.config import MonitorConfiguration
 
9
from landscape.monitor.monitor import Monitor
 
10
from landscape.broker.amp import (
 
11
    BrokerClientProtocolFactory, RemoteBrokerConnector)
 
12
 
 
13
 
 
14
class MonitorService(LandscapeService):
 
15
    """
 
16
    The core Twisted Service which creates and runs all necessary monitoring
 
17
    components when started.
 
18
    """
 
19
 
 
20
    service_name = Monitor.name
 
21
 
 
22
    def __init__(self, config):
 
23
        self.persist_filename = os.path.join(
 
24
            config.data_path, "%s.bpickle" % self.service_name)
 
25
        super(MonitorService, self).__init__(config)
 
26
        self.plugins = self.get_plugins()
 
27
        self.monitor = Monitor(self.reactor, self.config, self.persist,
 
28
                               persist_filename=self.persist_filename)
 
29
        self.factory = BrokerClientProtocolFactory(object=self.monitor)
 
30
 
 
31
    def get_plugins(self):
 
32
        return [namedClass("landscape.monitor.%s.%s"
 
33
                           % (plugin_name.lower(), plugin_name))()
 
34
                for plugin_name in self.config.plugin_factories]
 
35
 
 
36
    def startService(self):
 
37
        """Start the monitor."""
 
38
        super(MonitorService, self).startService()
 
39
 
 
40
        def start_plugins(broker):
 
41
            self.broker = broker
 
42
            self.monitor.broker = broker
 
43
            for plugin in self.plugins:
 
44
                self.monitor.add(plugin)
 
45
            return self.broker.register_client(self.service_name)
 
46
 
 
47
        self.connector = RemoteBrokerConnector(self.reactor, self.config)
 
48
        connected = self.connector.connect()
 
49
        return connected.addCallback(start_plugins)
 
50
 
 
51
    def stopService(self):
 
52
        """Stop the monitor.
 
53
 
 
54
        The monitor is flushed to ensure that things like persist databases
 
55
        get saved to disk.
 
56
        """
 
57
        self.monitor.flush()
 
58
        self.connector.disconnect()
 
59
        super(MonitorService, self).stopService()
 
60
 
 
61
 
 
62
def run(args):
 
63
    run_landscape_service(MonitorConfiguration, MonitorService, args)