1
from twisted.python.reflect import namedClass
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
10
class ManagerService(LandscapeService):
12
The core Twisted Service which creates and runs all necessary managing
13
components when started.
16
service_name = Manager.name
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)
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]
30
def startService(self):
31
"""Start the manager service.
33
This method does 3 things, in this order:
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.
39
super(ManagerService, self).startService()
41
def start_plugins(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)
48
self.connector = RemoteBrokerConnector(self.reactor, self.config)
49
connected = self.connector.connect()
50
return connected.addCallback(start_plugins)
52
def stopService(self):
53
"""Stop the manager and close the connection with the broker."""
54
self.connector.disconnect()
55
super(ManagerService, self).stopService()
59
run_landscape_service(ManagerConfiguration, ManagerService, args)