コード例 #1
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    if not is_config_initialised():
        config_init(os.environ['IRRD_CONFIG_FILE'])
    engine = create_engine(translate_url(get_setting('database_url')))

    with engine.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata)

        with context.begin_transaction():
            context.run_migrations()
コード例 #2
0
def main():  # pragma: no cover
    description = """Force a full reload for a mirror."""
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument(
        '--config',
        dest='config_file_path',
        type=str,
        help=
        f'use a different IRRd config file (default: {CONFIG_PATH_DEFAULT})')
    parser.add_argument('source',
                        type=str,
                        help='the name of the source to reload')
    args = parser.parse_args()

    config_init(args.config_file_path)

    set_force_reload(args.source)
コード例 #3
0
def main():  # pragma: no cover
    description = """Load an RPSL file into the database."""
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('--config', dest='config_file_path', type=str,
                        help=f'use a different IRRd config file (default: {CONFIG_PATH_DEFAULT})')
    parser.add_argument('--irrd_pidfile', dest='irrd_pidfile', type=str, required=True,
                        help=f'path to the PID file for the running irrd instance')
    parser.add_argument('--serial', dest='serial', type=int,
                        help=f'serial number (optional)')
    parser.add_argument('--source', dest='source', type=str, required=True,
                        help=f'name of the source, e.g. NTTCOM')
    parser.add_argument('input_file', type=str,
                        help='the name of a file to read')
    args = parser.parse_args()

    config_init(args.config_file_path)

    sys.exit(load(args.source, args.input_file, args.serial, args.irrd_pidfile))
コード例 #4
0
def main():  # pragma: no cover
    description = """Downgrade the IRRd SQL database to a particular version by running database migrations. See release notes."""
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument(
        '--config',
        dest='config_file_path',
        type=str,
        help=
        f'use a different IRRd config file (default: {CONFIG_PATH_DEFAULT})')
    parser.add_argument('--version',
                        dest='version',
                        type=str,
                        required=True,
                        help=f'version to downgrade to (see release notes)')
    args = parser.parse_args()

    config_init(args.config_file_path)
    run(args.version)
コード例 #5
0
def main():  # pragma: no cover
    description = """Run RPSL data through the IRRD processor. For each object that resulted in messages emitted by
                     the parser, the object is printed followed by the messages. Optionally, insert objects into
                     the database."""
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('--config', dest='config_file_path', type=str,
                        help=f'use a different IRRd config file (default: {CONFIG_PATH_DEFAULT})')
    parser.add_argument('--hide-info', dest='hide_info', action='store_true',
                        help='hide INFO messages')
    parser.add_argument('--strict', dest='strict_validation', action='store_true',
                        help='use strict validation (errors on e.g. unknown or missing attributes)')
    parser.add_argument('--database-destructive-overwrite', dest='database', action='store_true',
                        help='insert all valid objects into the IRRD database - OVERWRITING ANY EXISTING ENTRIES, if '
                             'they have the same RPSL primary key and source')
    parser.add_argument('input_file', type=str,
                        help='the name of a file to read, or - for stdin')
    args = parser.parse_args()

    config_init(args.config_file_path)
    RPSLParse().main(args.input_file, args.strict_validation, args.database, not args.hide_info)
コード例 #6
0
ファイル: env.py プロジェクト: icing/irrd
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    if not is_config_initialised():
        config_init(os.environ['IRRD_CONFIG_FILE'])
    url = get_setting('database_url')
    context.configure(
        url=url, target_metadata=target_metadata, literal_binds=True)

    with context.begin_transaction():
        context.run_migrations()
コード例 #7
0
    def makeService(self, options):
        config_init(options['config'])

        ms = PythonLoggingMultiService()

        internet.TCPServer(
            get_setting('server.whois.port'),
            WhoisQueryReceiverFactory(),
            interface=get_setting('server.whois.interface')
        ).setServiceParent(ms)

        internet.TCPServer(
            get_setting('server.http.port'),
            http_site,
            interface=get_setting('server.http.interface')
        ).setServiceParent(ms)

        mirror_frequency = int(os.environ.get('IRRD_SCHEDULER_TIMER_OVERRIDE', 15))
        internet.TimerService(mirror_frequency, MirrorScheduler().run).setServiceParent(ms)

        return ms
コード例 #8
0
def main():  # pragma: no cover
    description = """Update a database based on a RPSL file."""
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument(
        '--config',
        dest='config_file_path',
        type=str,
        help=
        f'use a different IRRd config file (default: {CONFIG_PATH_DEFAULT})')
    parser.add_argument('--source',
                        dest='source',
                        type=str,
                        required=True,
                        help=f'name of the source, e.g. NTTCOM')
    parser.add_argument('input_file',
                        type=str,
                        help='the name of a file to read')
    args = parser.parse_args()

    config_init(args.config_file_path)

    sys.exit(update(args.source, args.input_file))
コード例 #9
0
def main():  # pragma: no cover
    description = """Process a raw email message with requested changes. Authentication is checked, message
                     is always read from stdin. A report is sent to the user by email, along with any
                     notifications to mntners and others."""
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument(
        '--config',
        dest='config_file_path',
        type=str,
        help=
        f'use a different IRRd config file (default: {CONFIG_PATH_DEFAULT})')
    parser.add_argument(
        '--irrd_pidfile',
        dest='irrd_pidfile',
        type=str,
        required=True,
        help=f'path to the PID file for the running irrd instance')
    args = parser.parse_args()

    config_init(args.config_file_path)

    run(sys.stdin.read(), args.irrd_pidfile)
コード例 #10
0
Prints a report of the results, which would otherwise
be sent to a user by e-mail.
"""
import argparse
import sys

from pathlib import Path

sys.path.append(str(Path(__file__).resolve().parents[2]))

from irrd.conf import config_init, CONFIG_PATH_DEFAULT
from irrd.updates.handler import ChangeSubmissionHandler


def main(data):
    handler = ChangeSubmissionHandler(data)
    print(handler.submitter_report())


if __name__ == '__main__':  # pragma: no cover
    description = """Process a raw update message, i.e. without email headers. Authentication is still checked, 
                     but PGP is not supported. Message is always read from stdin, and a report is printed to stdout."""
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('--config', dest='config_file_path', type=str,
                        help=f'use a different IRRd config file (default: {CONFIG_PATH_DEFAULT})')
    args = parser.parse_args()

    config_init(args.config_file_path)

    main(sys.stdin.read())
コード例 #11
0
ファイル: main.py プロジェクト: irrdnet/irrd
def main():
    description = """IRRd main process"""
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('--config', dest='config_file_path', type=str,
                        help=f'use a different IRRd config file (default: {CONFIG_PATH_DEFAULT})')
    parser.add_argument('--foreground', dest='foreground', action='store_true',
                        help=f"run IRRd in the foreground, don't detach")
    args = parser.parse_args()

    mirror_frequency = int(os.environ.get('IRRD_SCHEDULER_TIMER_OVERRIDE', 15))

    daemon_kwargs = {
        'umask': 0o022,
    }
    if args.foreground:
        daemon_kwargs['detach_process'] = False
        daemon_kwargs['stdout'] = sys.stdout
        daemon_kwargs['stderr'] = sys.stderr

    # Since Python 3.8, the default method is spawn for MacOS,
    # which creates several issues. For consistency, we force to fork.
    multiprocessing.set_start_method('fork')

    # config_init with commit may only be called within DaemonContext,
    # but this call here causes fast failure for most misconfigurations
    config_init(args.config_file_path, commit=False)

    if not any([
        get_configuration().user_config_staging.get('log.logfile_path'),
        get_configuration().user_config_staging.get('log.logging_config_path'),
        args.foreground,
    ]):
        logging.critical('Unable to start: when not running in the foreground, you must set '
                         'either log.logfile_path or log.logging_config_path in the settings')
        return

    with daemon.DaemonContext(**daemon_kwargs):
        config_init(args.config_file_path)

        uid, gid = get_configured_owner()
        # Running as root is permitted on CI
        if not os.environ.get('CI') and not uid and os.geteuid() == 0:
            logging.critical('Unable to start: user and group must be defined in settings '
                             'when starting IRRd as root')
            return

        piddir = get_setting('piddir')
        logger.info('IRRd attempting to secure PID')
        try:
            with PidFile(pidname='irrd', piddir=piddir):
                logger.info(f'IRRd {__version__} starting, PID {os.getpid()}, PID file in {piddir}')
                run_irrd(mirror_frequency=mirror_frequency,
                         config_file_path=args.config_file_path if args.config_file_path else CONFIG_PATH_DEFAULT,
                         uid=uid,
                         gid=gid,
                         )
        except PidFileError as pfe:
            logger.error(f'Failed to start IRRd, unable to lock PID file irrd.pid in {piddir}: {pfe}')
        except Exception as e:
            logger.error(f'Error occurred in main process, terminating. Error follows:')
            logger.exception(e)
            os.kill(os.getpid(), signal.SIGTERM)