Esempio n. 1
0
def start():
    """ Start the global manager web service.
    """
    config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
                                      REQUIRED_FIELDS)

    common.init_logging(
        config['log_directory'],
        'global-manager.log',
        int(config['log_level']))

    state = init_state(config)
    switch_hosts_on(state['db'],
                    config['ether_wake_interface'],
                    state['host_macs'],
                    state['compute_hosts'])

    bottle.debug(True)
    bottle.app().state = {
        'config': config,
        'state': state}

    host = config['global_manager_host']
    port = config['global_manager_port']
    log.info('Starting the global manager listening to %s:%s', host, port)
    bottle.run(host=host, port=port)
Esempio n. 2
0
def start():
    """ Start the global manager web service.
    """
    config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
                                      REQUIRED_FIELDS)

    common.init_logging(
        config['log_directory'],
        'global-manager.log',
        int(config['log_level']))

    state = init_state(config)
    switch_hosts_on(state['db'],
                    config['ether_wake_interface'],
                    state['host_macs'],
                    state['compute_hosts'])

    bottle.debug(True)
    bottle.app().state = {
        'config': config,
        'state': state}

    host = config['global_manager_host']
    port = config['global_manager_port']
    log.info('Starting the global manager listening to %s:%s', host, port)
    bottle.run(host=host, port=port)
Esempio n. 3
0
def start():
    """ Start the data collector loop.

    :return: The final state.
     :rtype: dict(str: *)
    """
    config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
                                      REQUIRED_FIELDS)

    common.init_logging(
        config['log_directory'],
        'data-collector.log',
        int(config['log_level']))

    vm_path = common.build_local_vm_path(config['local_data_directory'])
    if not os.access(vm_path, os.F_OK):
        os.makedirs(vm_path)
        log.info('Created a local VM data directory: %s', vm_path)
    else:
        cleanup_all_local_data(config['local_data_directory'])
        log.info('Creaned up the local data directory: %s',
                 config['local_data_directory'])

    interval = config['data_collector_interval']
    log.info('Starting the data collector, ' +
             'iterations every %s seconds', interval)
    return common.start(
        init_state,
        execute,
        config,
        int(interval))
Esempio n. 4
0
def start():
    """ Start the data collector loop.

    :return: The final state.
     :rtype: dict(str: *)
    """
    config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
                                      REQUIRED_FIELDS)

    common.init_logging(
        config['log_directory'],
        'data-collector.log',
        int(config['log_level']))

    vm_path = common.build_local_vm_path(config['local_data_directory'])
    if not os.access(vm_path, os.F_OK):
        os.makedirs(vm_path)
        log.info('Created a local VM data directory: %s', vm_path)
    else:
        cleanup_all_local_data(config['local_data_directory'])
        log.info('Creaned up the local data directory: %s',
                 config['local_data_directory'])

    interval = config['data_collector_interval']
    log.info('Starting the data collector, ' +
             'iterations every %s seconds', interval)
    return common.start(
        init_state,
        execute,
        config,
        int(interval))
    def test_init_logging(self):
        log_dir = os.path.join(
            os.path.dirname(__file__), 'resources', 'log')
        log_file = 'test.log'
        log_path = os.path.join(log_dir, log_file)

        with MockTransaction:
            logging.root = mock('root')
            expect(logging).disable(logging.CRITICAL).once()
            expect(logging.root).setLevel.never()
            expect(logging.root).addHandler.never()
            assert common.init_logging(log_dir, log_file, 0)

        with MockTransaction:
            shutil.rmtree(log_dir, True)
            logging.root = mock('root')
            expect(logging).disable.never()
            expect(logging.root).setLevel(logging.WARNING).once()
            handler = mock('handler')
            expect(logging).FileHandler(log_path).and_return(handler).once()
            expect(handler).setFormatter.and_return(True).once()
            expect(logging).Formatter(
                '%(asctime)s %(levelname)-8s %(name)s %(message)s').once()
            expect(logging.root).addHandler.once()
            assert common.init_logging(log_dir, log_file, 1)
            assert os.access(log_dir, os.W_OK)

        with MockTransaction:
            logging.root = mock('root')
            expect(logging).disable.never()
            expect(logging.root).setLevel(logging.INFO).once()
            handler = mock('handler')
            expect(logging).FileHandler(log_path).and_return(handler).once()
            expect(handler).setFormatter.and_return(True).once()
            expect(logging).Formatter(
                '%(asctime)s %(levelname)-8s %(name)s %(message)s').once()
            expect(logging.root).addHandler.once()
            assert common.init_logging(log_dir, log_file, 2)
            assert os.access(log_dir, os.W_OK)

        with MockTransaction:
            logging.root = mock('root')
            expect(logging).disable.never()
            expect(logging.root).setLevel(logging.DEBUG).once()
            handler = mock('handler')
            expect(logging).FileHandler(log_path).and_return(handler).once()
            expect(handler).setFormatter.and_return(True).once()
            expect(logging).Formatter(
                '%(asctime)s %(levelname)-8s %(name)s %(message)s').once()
            expect(logging.root).addHandler.once()
            assert common.init_logging(log_dir, log_file, 3)
            assert os.access(log_dir, os.W_OK)

        shutil.rmtree(log_dir, True)
Esempio n. 6
0
    def test_init_logging(self):
        log_dir = os.path.join(os.path.dirname(__file__), 'resources', 'log')
        log_file = 'test.log'
        log_path = os.path.join(log_dir, log_file)

        with MockTransaction:
            logging.root = mock('root')
            expect(logging).disable(logging.CRITICAL).once()
            expect(logging.root).setLevel.never()
            expect(logging.root).addHandler.never()
            assert common.init_logging(log_dir, log_file, 0)

        with MockTransaction:
            shutil.rmtree(log_dir, True)
            logging.root = mock('root')
            expect(logging).disable.never()
            expect(logging.root).setLevel(logging.WARNING).once()
            handler = mock('handler')
            expect(logging).FileHandler(log_path).and_return(handler).once()
            expect(handler).setFormatter.and_return(True).once()
            expect(logging).Formatter(
                '%(asctime)s %(levelname)-8s %(name)s %(message)s').once()
            expect(logging.root).addHandler.once()
            assert common.init_logging(log_dir, log_file, 1)
            assert os.access(log_dir, os.W_OK)

        with MockTransaction:
            logging.root = mock('root')
            expect(logging).disable.never()
            expect(logging.root).setLevel(logging.INFO).once()
            handler = mock('handler')
            expect(logging).FileHandler(log_path).and_return(handler).once()
            expect(handler).setFormatter.and_return(True).once()
            expect(logging).Formatter(
                '%(asctime)s %(levelname)-8s %(name)s %(message)s').once()
            expect(logging.root).addHandler.once()
            assert common.init_logging(log_dir, log_file, 2)
            assert os.access(log_dir, os.W_OK)

        with MockTransaction:
            logging.root = mock('root')
            expect(logging).disable.never()
            expect(logging.root).setLevel(logging.DEBUG).once()
            handler = mock('handler')
            expect(logging).FileHandler(log_path).and_return(handler).once()
            expect(handler).setFormatter.and_return(True).once()
            expect(logging).Formatter(
                '%(asctime)s %(levelname)-8s %(name)s %(message)s').once()
            expect(logging.root).addHandler.once()
            assert common.init_logging(log_dir, log_file, 3)
            assert os.access(log_dir, os.W_OK)

        shutil.rmtree(log_dir, True)
Esempio n. 7
0
def start():
    """ Start the database cleaner loop.

    :return: The final state.
     :rtype: dict(str: *)
    """
    config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
                                      REQUIRED_FIELDS)

    common.init_logging(config['log_directory'], 'db-cleaner.log',
                        int(config['log_level']))

    interval = config['db_cleaner_interval']
    if log.isEnabledFor(logging.INFO):
        log.info(
            'Starting the database cleaner, ' + 'iterations every %s seconds',
            interval)
    return common.start(init_state, execute, config, int(interval))
Esempio n. 8
0
def start():
    """ Start the local manager loop.

    :return: The final state.
     :rtype: dict(str: *)
    """
    config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
                                      REQUIRED_FIELDS)

    common.init_logging(
        config['log_directory'],
        'local-manager.log',
        int(config['log_level']))

    interval = config['local_manager_interval']
    if log.isEnabledFor(logging.INFO):
        log.info('Starting the local manager, ' +
                 'iterations every %s seconds', interval)
    return common.start(
        init_state,
        execute,
        config,
        int(interval))