Esempio n. 1
0
    def run(self):
        # Start threads
        self.logger.info("MOM starting")
        self.config.set('__int__', 'running', '1')
        host_monitor = HostMonitor(self.config)
        hypervisor_iface = self.get_hypervisor_interface()
        if not hypervisor_iface:
            self.shutdown()
        guest_manager = GuestManager(self.config, hypervisor_iface)
        policy_engine = PolicyEngine(self.config, hypervisor_iface, host_monitor, \
                                     guest_manager)

        threads = { 'host_monitor': host_monitor,
                         'guest_manager': guest_manager,
                         'policy_engine': policy_engine }
        self.momFuncs = MOMFuncs(self.config, threads)
        rpc_server = RPCServer(self.config, self.momFuncs)

        interval = self.config.getint('main', 'main-loop-interval')
        while self.config.getint('__int__', 'running') == 1:
            time.sleep(interval)
            if not self._threads_ok((host_monitor,guest_manager,policy_engine)):
                self.config.set('__int__', 'running', '0')
            # Check the RPC server separately from the other threads since it
            # can be disabled.
            if not rpc_server.thread_ok():
                self.config.set('__int__', 'running', '0')
    
        rpc_server.shutdown()
        self._wait_for_thread(rpc_server, 5)
        self._wait_for_thread(policy_engine, 10)
        self._wait_for_thread(guest_manager, 5)
        self._wait_for_thread(host_monitor, 5)
        self.logger.info("MOM ending")
Esempio n. 2
0
    def run(self):
        # Set up a shared libvirt connection
        uri = self.config.get('main', 'libvirt-hypervisor-uri')
        libvirt_iface = libvirtInterface(uri)
        
        # Start threads
        self.logger.info("MOM starting")
        self.config.set('__int__', 'running', '1')
        host_monitor = HostMonitor(self.config)
        guest_manager = GuestManager(self.config, libvirt_iface)
        policy_engine = PolicyEngine(self.config, libvirt_iface, host_monitor, \
                                     guest_manager)
        rpc_server = RPCServer(self.config, host_monitor, guest_manager, \
                               policy_engine)

        interval = self.config.getint('main', 'main-loop-interval')
        while self.config.getint('__int__', 'running') == 1:
            time.sleep(interval)
            if not self._threads_ok((host_monitor,guest_manager,policy_engine)):
                self.config.set('__int__', 'running', '0')
            # Check the RPC server separately from the other threads since it
            # can be disabled.
            if not rpc_server.thread_ok():
                self.config.set('__int__', 'running', '0')
    
        rpc_server.shutdown()
        self._wait_for_thread(rpc_server, 5)
        self._wait_for_thread(policy_engine, 10)
        self._wait_for_thread(guest_manager, 5)
        self._wait_for_thread(host_monitor, 5)
        self.logger.info("MOM ending")
Esempio n. 3
0
    def run(self):
        if not self._validate_config():
            self.logger.error("Invalid configuration.  Unable to start")
            return

        # Start threads
        self.logger.info("MOM starting")
        self.config.set('__int__', 'running', '1')
        try:
            host_monitor = HostMonitor(self.config)
            hypervisor_iface = self.get_hypervisor_interface()
            if not hypervisor_iface:
                self.shutdown()
            guest_manager = GuestManager(self.config, hypervisor_iface)
            guest_manager.start()
            policy_engine = PolicyEngine(self.config, hypervisor_iface,
                                         host_monitor, guest_manager)

            threads = {
                'host_monitor': host_monitor,
                'guest_manager': guest_manager,
                'policy_engine': policy_engine
            }
            momFuncs = MOMFuncs(self.config, threads)
            self._setupAPI(momFuncs)
            rpc_server = RPCServer(self.config, momFuncs)
        except Exception as e:
            self.logger.exception("Failed to initialize MOM threads")
            return

        interval = self.config.getint('main', 'main-loop-interval')
        while self.config.getint('__int__', 'running') == 1:
            time.sleep(interval)
            if not self._threads_ok(
                (host_monitor, guest_manager, policy_engine)):
                self.config.set('__int__', 'running', '0')
            # Check the RPC server separately from the other threads since it
            # can be disabled.
            if not rpc_server.thread_ok():
                self.config.set('__int__', 'running', '0')

        rpc_server.shutdown()
        self._wait_for_thread(rpc_server, 5)
        self._wait_for_thread(policy_engine, 10)
        self._wait_for_thread(guest_manager, 5)
        self._wait_for_thread(host_monitor, 5)
        self.logger.info("MOM ending")
Esempio n. 4
0
    def run(self):
        if not self._validate_config():
            self.logger.error("Invalid configuration.  Unable to start")
            return

        # Start threads
        self.logger.info("MOM starting")
        self.config.set('__int__', 'running', '1')
        try:
            host_monitor = HostMonitor(self.config)
            hypervisor_iface = self.get_hypervisor_interface()
            if not hypervisor_iface:
                self.shutdown()
            guest_manager = GuestManager(self.config, hypervisor_iface)
            policy_engine = PolicyEngine(self.config, hypervisor_iface,
                                         host_monitor, guest_manager)

            threads = {'host_monitor': host_monitor,
                       'guest_manager': guest_manager,
                       'policy_engine': policy_engine}
            momFuncs = MOMFuncs(self.config, threads)
            self._setupAPI(momFuncs)
            rpc_server = RPCServer(self.config, momFuncs)
        except Exception as e:
            self.log.error("Failed to initialize MOM threads", exc_info=True)
            return

        interval = self.config.getint('main', 'main-loop-interval')
        while self.config.getint('__int__', 'running') == 1:
            time.sleep(interval)
            if not self._threads_ok((host_monitor,guest_manager,policy_engine)):
                self.config.set('__int__', 'running', '0')
            # Check the RPC server separately from the other threads since it
            # can be disabled.
            if not rpc_server.thread_ok():
                self.config.set('__int__', 'running', '0')

        rpc_server.shutdown()
        self._wait_for_thread(rpc_server, 5)
        self._wait_for_thread(policy_engine, 10)
        self._wait_for_thread(guest_manager, 5)
        self._wait_for_thread(host_monitor, 5)
        self.logger.info("MOM ending")