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

« back to all changes in this revision

Viewing changes to landscape/manager/service.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
from twisted.python.reflect import namedClass
 
2
 
 
3
from landscape.service import LandscapeService, run_landscape_service
 
4
from landscape.manager.config import ManagerConfiguration
 
5
from landscape.broker.amp import (
 
6
    BrokerClientProtocolFactory, RemoteBrokerConnector)
 
7
from landscape.manager.manager import Manager
 
8
 
 
9
 
 
10
class ManagerService(LandscapeService):
 
11
    """
 
12
    The core Twisted Service which creates and runs all necessary managing
 
13
    components when started.
 
14
    """
 
15
 
 
16
    service_name = Manager.name
 
17
 
 
18
    def __init__(self, config):
 
19
        super(ManagerService, self).__init__(config)
 
20
        self.plugins = self.get_plugins()
 
21
        self.manager = Manager(self.reactor, self.config)
 
22
        self.factory = BrokerClientProtocolFactory(object=self.manager)
 
23
 
 
24
    def get_plugins(self):
 
25
        """Return instances of all the plugins enabled in the configuration."""
 
26
        return [namedClass("landscape.manager.%s.%s"
 
27
                           % (plugin_name.lower(), plugin_name))()
 
28
                for plugin_name in self.config.plugin_factories]
 
29
 
 
30
    def startService(self):
 
31
        """Start the manager service.
 
32
 
 
33
        This method does 3 things, in this order:
 
34
 
 
35
          - Start listening for connections on the manager socket.
 
36
          - Connect to the broker.
 
37
          - Add all configured plugins, that will in turn register themselves.
 
38
        """
 
39
        super(ManagerService, self).startService()
 
40
 
 
41
        def start_plugins(broker):
 
42
            self.broker = broker
 
43
            self.manager.broker = broker
 
44
            for plugin in self.plugins:
 
45
                self.manager.add(plugin)
 
46
            return self.broker.register_client(self.service_name)
 
47
 
 
48
        self.connector = RemoteBrokerConnector(self.reactor, self.config)
 
49
        connected = self.connector.connect()
 
50
        return connected.addCallback(start_plugins)
 
51
 
 
52
    def stopService(self):
 
53
        """Stop the manager and close the connection with the broker."""
 
54
        self.connector.disconnect()
 
55
        super(ManagerService, self).stopService()
 
56
 
 
57
 
 
58
def run(args):
 
59
    run_landscape_service(ManagerConfiguration, ManagerService, args)