Esempio n. 1
0
def main():
    cti_config.init_cli_config(sys.argv[1:])
    cti_config.init_config_file()
    cti_config.init_auth_config()
    xivo_dao.init_db_from_config(config)
    cti_config.update_db_config()

    user = config.get('user')
    if user:
        change_user(user)

    setup_logging(config['logfile'], config['foreground'], config['debug'])
    silence_loggers(
        ['amqp', 'urllib3', 'Flask-Cors', 'kombu', 'stevedore.extension'],
        logging.WARNING)

    xivo_uuid = get_xivo_uuid(logger)

    register_class.setup(xivo_uuid)

    ctid = context.get('cti_server')
    ctid.setup()

    with ServiceCatalogRegistration('xivo-ctid', xivo_uuid, config['consul'],
                                    config['service_discovery'], config['bus'],
                                    partial(self_check, config)):
        ctid.run()
Esempio n. 2
0
def main():
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    service_key = _load_key_file(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    config = ChainMap(cli_config, service_key, file_config, _DEFAULT_CONFIG)

    user = config.get('user')
    if user:
        change_user(user)

    xivo_dao.init_db_from_config(config)

    setup_logging(config['logfile'], config['foreground'], config['debug'])
    silence_loggers(['Flask-Cors'], logging.WARNING)
    set_xivo_uuid(config, logger)

    with pidfile_context(config['pidfile'], config['foreground']):
        logger.info('Starting xivo-agentd')
        try:
            _run(config)
        except Exception:
            logger.exception('Unexpected error:')
        except KeyboardInterrupt:
            pass
        finally:
            logger.info('Stopping xivo-agentd')
Esempio n. 3
0
def main():
    _print_deprecation_notice()
    setup_logging('/dev/null', foreground=True, debug=False)
    silence_loggers(['urllib3.connectionpool'], level=logging.WARNING)
    init_db_from_config(default_config())
    with pidfile_context(PIDFILENAME, foreground=True):
        _generate_call_logs()
Esempio n. 4
0
    def run(self):
        logger.info('wazo-confd running...')
        xivo_dao.init_db_from_config(self.config)
        signal.signal(signal.SIGTERM, partial(_sigterm_handler, self))

        with self.token_renewer:
            with ServiceCatalogRegistration(*self._service_discovery_args):
                self.http_server.run()
Esempio n. 5
0
 def load(self, core):
     xivo_dao.init_db_from_config(core.config)
     Meetme.register(meetme, route_base='/', route_prefix='/x/meetme')
     MeetmeAdd.register(meetme, route_base='/add', route_prefix='/x/meetme')
     MeetmeDelete.register(meetme,
                           route_base='/delete',
                           route_prefix='/x/meetme')
     core.register_blueprint(meetme)
Esempio n. 6
0
def _generate_call_logs():
    parser = argparse.ArgumentParser(description='Call logs generator')
    options = parse_args(parser)

    file_config = {
        key: value
        for key, value in read_config_file_hierarchy(DEFAULT_CONFIG).items()
        if key in ('confd', 'bus', 'auth', 'db_uri', 'cel_db_uri')
    }
    key_config = {}
    auth_username = file_config['auth'].get('username')
    auth_password = file_config['auth'].get('password')
    if not (auth_username and auth_password):
        key_config = load_key_file(ChainMap(file_config, DEFAULT_CONFIG))
    config = ChainMap(key_config, file_config, DEFAULT_CONFIG)
    set_xivo_uuid(config, logger)
    init_db_from_config({'db_uri': config['cel_db_uri']})
    DBSession = new_db_session(config['db_uri'])
    CELDBSession = new_db_session(config['cel_db_uri'])
    dao = DAO(DBSession, CELDBSession)

    auth_client = AuthClient(**config['auth'])
    confd_client = ConfdClient(**config['confd'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(confd_client.set_token)

    generator = CallLogsGenerator(
        confd_client,
        [
            LocalOriginateCELInterpretor(),
            DispatchCELInterpretor(CallerCELInterpretor(),
                                   CalleeCELInterpretor()),
        ],
    )
    token_renewer.subscribe_to_next_token_details_change(
        generator.set_default_tenant_uuid)
    writer = CallLogsWriter(dao)
    publisher = BusPublisher(service_uuid=config['uuid'], **config['bus'])
    manager = CallLogsManager(dao, generator, writer, publisher)

    options = vars(options)
    with token_renewer:
        if options.get('action') == 'delete':
            if options.get('all'):
                manager.delete_all()
            elif options.get('days'):
                manager.delete_from_days(options['days'])
        else:
            if options.get('days'):
                manager.generate_from_days(days=options['days'])
            else:
                manager.generate_from_count(cel_count=options['cel_count'])
Esempio n. 7
0
def main():
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(ChainMap(cli_config, _DEFAULT_CONFIG))
    config = ChainMap(cli_config, file_config, _DEFAULT_CONFIG)

    setup_logging(config['logfile'], config['foreground'], config['debug'])
    silence_loggers(['urllib3'], logging.WARNING)

    xivo_dao.init_db_from_config(config)

    with pidfile_context(config['pidfile'], config['foreground']):
        agid.init(config)
        agid.run()
Esempio n. 8
0
    def run(self):
        logger.debug('xivo-confd running...')

        xivo_dao.init_db_from_config(self.config)

        app = setup_app(self.config)

        with ServiceCatalogRegistration('xivo-confd', self.config['uuid'],
                                        self.config['consul'],
                                        self.config['service_discovery'],
                                        self.config['bus'],
                                        partial(self_check, self.config)):
            run_server(app)
Esempio n. 9
0
def main():
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(ChainMap(cli_config, _DEFAULT_CONFIG))
    config = ChainMap(cli_config, file_config, _DEFAULT_CONFIG)

    setup_logging(config['log_file'], debug=config['debug'])

    xivo_dao.init_db_from_config(config)

    with pidfile_context(config['pid_file']):
        if 'archives' in config.get('enabled_plugins', {}):
            _load_plugins(config)
        _purge_tables(config)
Esempio n. 10
0
def main():
    cli_args = parse_cli_args()
    config = load_config()

    xivo_logging.setup_logging('/dev/null', log_level=cli_args['log_level'])
    xivo_logging.silence_loggers(['stevedore.extension'], logging.WARNING)

    token = AuthClient(**config['auth']).token.new(expiration=300)['token']

    del config['auth']['username']
    del config['auth']['password']
    tenants = AuthClient(token=token, **config['auth']).tenants.list()['items']
    auth_tenants = set(tenant['uuid'] for tenant in tenants)
    auth_tenant_slugs = {tenant['uuid']: tenant['slug'] for tenant in tenants}
    logger.debug('wazo-auth tenants: %s', auth_tenants)

    init_db_from_config(config)
    default_sip_template_service = DefaultSIPTemplateService(
        sip_dao,
        transport_dao,
    )

    with session_scope() as session:
        confd_tenants = set()
        confd_tenant_without_slugs = set()
        for tenant in session.query(Tenant).all():
            confd_tenants.add(tenant.uuid)
            if not tenant.slug:
                confd_tenant_without_slugs.add(tenant.uuid)
        logger.debug('wazo-confd tenants: %s', confd_tenants)

        removed_tenants = confd_tenants - auth_tenants
        for tenant_uuid in removed_tenants:
            logger.info('Removing tenant: %s... (SKIP)', tenant_uuid)
            remove_tenant(tenant_uuid)

    with session_scope() as session:
        for tenant_uuid in auth_tenants:
            tenant = tenant_dao.find_or_create_tenant(tenant_uuid)
            default_sip_template_service.generate_sip_templates(tenant)

        for tenant_uuid in confd_tenant_without_slugs:
            slug = auth_tenant_slugs.get(tenant_uuid)
            if not slug:
                continue
            tenant = tenant_dao.find_or_create_tenant(tenant_uuid)
            tenant.slug = slug
            session.flush()
Esempio n. 11
0
def _generate_call_logs():
    parser = argparse.ArgumentParser(description='Call logs generator')
    options = parse_args(parser)

    file_config = {
        key: value
        for key, value in read_config_file_hierarchy(DEFAULT_CONFIG).items()
        if key in ('confd', 'bus', 'auth', 'db_uri')
    }
    key_config = load_key_file(ChainMap(file_config, DEFAULT_CONFIG))
    config = ChainMap(key_config, file_config, DEFAULT_CONFIG)
    init_db_from_config(config)

    auth_client = AuthClient(**config['auth'])
    confd_client = ConfdClient(**config['confd'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(confd_client.set_token)

    cel_fetcher = CELFetcher()
    generator = CallLogsGenerator(
        confd_client,
        [
            LocalOriginateCELInterpretor(confd_client),
            DispatchCELInterpretor(
                CallerCELInterpretor(confd_client), CalleeCELInterpretor(confd_client)
            ),
        ],
    )
    token_renewer.subscribe_to_next_token_details_change(
        generator.set_default_tenant_uuid
    )
    writer = CallLogsWriter()
    publisher = BusPublisher(config)
    manager = CallLogsManager(cel_fetcher, generator, writer, publisher)

    options = vars(options)
    with token_renewer:
        if options.get('action') == 'delete':
            if options.get('all'):
                manager.delete_all()
            elif options.get('days'):
                manager.delete_from_days(options['days'])
        else:
            if options.get('days'):
                manager.generate_from_days(days=options['days'])
            else:
                manager.generate_from_count(cel_count=options['cel_count'])
Esempio n. 12
0
def main():
    cli_args = parse_cli_args()
    config = load_config()
    xivo_logging.setup_logging('/dev/null', log_level=cli_args['log_level'])
    xivo_logging.silence_loggers(['stevedore.extension'], logging.WARNING)

    tenant_uuid = get_master_tenant_uuid(config['auth'])
    init_db_from_config(config)

    wazo_uuid = info_dao.get().uuid
    bus = BusPublisher.from_config(
        config['bus'],
        wazo_uuid,
    )
    sysconfd = SysconfdPublisher.from_config(config)

    if not cli_args['authorizations_only']:
        ingress_http_service = build_ingress_http_service()
        extension_features_service = build_extension_features_service()
        meeting_service = CRUDService(
            meeting_dao,
            build_meeting_validator(),
            MeetingNotifier(
                bus,
                sysconfd,
                ingress_http_service,
                extension_features_service,
                tenant_uuid,
            ),
        )

        meeting_date_limit = datetime.now(timezone.utc) - timedelta(hours=24)
        remove_meetings_older_than(meeting_date_limit, meeting_service)

    authorization_notifier = MeetingAuthorizationNotifier(bus)
    meeting_authorization_service = build_authorization_service(
        authorization_notifier)

    meeting_authorization_date_limit = datetime.now(
        timezone.utc) - timedelta(hours=24)
    remove_meeting_authorizations_older_than(meeting_authorization_date_limit,
                                             meeting_authorization_service)

    sysconfd.flush()
    bus.flush()
Esempio n. 13
0
def main(argv):
    config = load_config(argv)

    user = config.get('user')
    if user:
        change_user(user)

    setup_logging(config['logfile'], config['foreground'], config['debug'],
                  config['log_level'])
    xivo_dao.init_db_from_config(config)

    set_xivo_uuid(config, logger)

    controller = Controller(config)
    signal.signal(signal.SIGTERM, partial(sigterm, controller))

    with pidfile_context(config['pidfile'], config['foreground']):
        controller.run()
Esempio n. 14
0
def main(argv):
    config = load_config(argv)

    xivo_logging.setup_logging(config['log_filename'], config['foreground'],
                               config['debug'], config['log_level'])
    xivo_logging.silence_loggers(['Flask-Cors'], logging.WARNING)

    if config['user']:
        change_user(config['user'])

    xivo_dao.init_db_from_config(config)
    init_bus_from_config(ChainMap(config, {'uuid': info_dao.get().uuid}))
    setup_sysconfd(config['sysconfd']['host'], config['sysconfd']['port'])

    controller = Controller(config)

    with pidfile_context(config['pid_filename'], config['foreground']):
        controller.run()
Esempio n. 15
0
def main():
    argv = sys.argv[1:]
    config = load_config(argv)

    if config['user']:
        change_user(config['user'])

    setup_logging(
        config['logfile'], debug=config['debug'], log_level=config['log_level']
    )
    silence_loggers(['amqp'], level=logging.WARNING)

    if config["db_upgrade_on_startup"]:
        database.upgrade(config["db_uri"])

    xivo_dao.init_db_from_config({'db_uri': config['cel_db_uri']})
    set_xivo_uuid(config, logger)

    controller = Controller(config)
    controller.run()
Esempio n. 16
0
def main(argv=None):
    argv = argv or sys.argv[1:]
    config = load_config(logger, argv)

    user = config.get('user')
    if user:
        change_user(user)

    xivo_dao.init_db_from_config(config)

    setup_logging(config['logfile'], debug=config['debug'])
    silence_loggers(['Flask-Cors', 'amqp'], logging.WARNING)
    set_xivo_uuid(config, logger)

    logger.info('Starting wazo-agentd')
    try:
        _run(config)
    except Exception:
        logger.exception('Unexpected error:')
    except KeyboardInterrupt:
        pass
    finally:
        logger.info('Stopping wazo-agentd')
Esempio n. 17
0
def main():
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    key_config = _load_key_file(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    config = ChainMap(cli_config, key_config, file_config, _DEFAULT_CONFIG)

    setup_logging(config['logfile'], debug=config['debug'])
    silence_loggers(['urllib3'], logging.WARNING)

    user = config.get('user')
    if user:
        change_user(user)

    xivo_dao.init_db_from_config(config)

    token_renewer = TokenRenewer(AuthClient(**config['auth']))
    config['agentd']['client'] = AgentdClient(**config['agentd'])
    config['calld']['client'] = CalldClient(**config['calld'])
    config['confd']['client'] = ConfdClient(**config['confd'])
    config['dird']['client'] = DirdClient(**config['dird'])
    config['auth']['client'] = AuthClient(**config['auth'])

    def on_token_change(token_id):
        config['agentd']['client'].set_token(token_id)
        config['calld']['client'].set_token(token_id)
        config['confd']['client'].set_token(token_id)
        config['dird']['client'].set_token(token_id)
        config['auth']['client'].set_token(token_id)

    token_renewer.subscribe_to_token_change(on_token_change)

    agid.init(config)
    with token_renewer:
        agid.run()
Esempio n. 18
0
def main():
    log_format = '%(asctime)s: %(message)s'
    main_config = config.get_config()
    init_db_from_config(main_config)
    setup_logging(main_config['log_filename'],
                  debug=main_config['debug'],
                  log_format=log_format)

    with pidfile_context(PIDFILENAME):
        parser = argparse.ArgumentParser(
            description='Wazo statistics generator')
        options = parse_args(parser)
        subcommand = getattr(options, 'subcommand', None)

        if subcommand == 'fill_db':
            core.update_db(
                config=main_config,
                start_date=options.start,
                end_date=options.end,
            )
        elif subcommand == 'clean_db':
            core.clean_db()
        else:
            parser.print_help()
Esempio n. 19
0
 def load(self, core):
     xivo_dao.init_db_from_config(core.config)
     GeneralSIP.register(q_generalsip, route_base='/x/generalsip', route_prefix='')
     register_flaskview(q_generalsip, GeneralSIP)
     core.register_blueprint(q_generalsip)
Esempio n. 20
0
 def load(self, core):
     xivo_dao.init_db_from_config(core.config)
     Meetme.register(meetme, route_base='/', route_prefix='/x/meetme')
     MeetmeAdd.register(meetme, route_base='/add', route_prefix='/x/meetme')
     MeetmeDelete.register(meetme, route_base='/delete', route_prefix='/x/meetme')
     core.register_blueprint(meetme)
Esempio n. 21
0
 def __init__(self, dependencies):
     init_db_from_config(dependencies['config'])