-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #172 - Add irrd_load_database command for manual loading of sources.
- Loading branch information
Showing
9 changed files
with
301 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python | ||
# flake8: noqa: E402 | ||
import argparse | ||
import logging | ||
import sys | ||
|
||
from pathlib import Path | ||
|
||
""" | ||
Load an RPSL file into the database. | ||
""" | ||
|
||
logger = logging.getLogger(__name__) | ||
sys.path.append(str(Path(__file__).resolve().parents[2])) | ||
|
||
from irrd.conf import config_init, CONFIG_PATH_DEFAULT | ||
from irrd.mirroring.parsers import MirrorFileImportParser | ||
from irrd.storage.database_handler import DatabaseHandler | ||
|
||
|
||
def load(source, filename, serial) -> int: | ||
dh = DatabaseHandler() | ||
dh.delete_all_rpsl_objects_with_journal(source) | ||
dh.disable_journaling() | ||
parser = MirrorFileImportParser(source, filename, serial=serial, database_handler=dh, direct_error_return=True) | ||
error = parser.run_import() | ||
if error: | ||
dh.rollback() | ||
else: | ||
dh.commit() | ||
dh.close() | ||
if error: | ||
print(f'Error occurred while processing object:\n{error}') | ||
return 1 | ||
return 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('--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)) | ||
|
||
|
||
if __name__ == '__main__': # pragma: no cover | ||
main() |
Oops, something went wrong.