Skip to content
Snippets Groups Projects
Commit 1b4a5fdc authored by Nico Vermaas's avatar Nico Vermaas
Browse files

add extra --configuration parameter to the file with tunnel and ldvadmin credentials

parent aa84af30
No related branches found
No related tags found
1 merge request!8Add ldv_migrate script
...@@ -2,8 +2,8 @@ from configparser import ConfigParser ...@@ -2,8 +2,8 @@ from configparser import ConfigParser
import os import os
def read_config(section, filename='database.cfg'): def read_config(configuration_file, section):
full_filename = os.path.join(os.path.dirname(__file__), filename) full_filename = os.path.join(os.path.dirname(__file__), configuration_file)
parser = ConfigParser() parser = ConfigParser()
read_result = parser.read(full_filename) read_result = parser.read(full_filename)
# If file not found then parser returns just an empty list it does not raise an Exception! # If file not found then parser returns just an empty list it does not raise an Exception!
......
...@@ -8,13 +8,13 @@ import os ...@@ -8,13 +8,13 @@ import os
from ldv_migrate.connection.config import read_config from ldv_migrate.connection.config import read_config
def connect_postgresql(section): def connect_postgresql(configuration_file, section):
""" Connect to the PostgreSQL database server """ """ Connect to the PostgreSQL database server """
conn = None conn = None
tunnel = None tunnel = None
try: try:
# read connection parameters # read connection parameters
configuration = read_config(section=section) configuration = read_config(configuration_file=configuration_file, section=section)
logging.info('Connecting PostgreSQL database %s', configuration.get('database', 'no database name given')) logging.info('Connecting PostgreSQL database %s', configuration.get('database', 'no database name given'))
......
...@@ -73,7 +73,9 @@ def main(): ...@@ -73,7 +73,9 @@ def main():
parser.add_argument("-t", "--token", default="ad9b37a24380948601257f9c1f889b07a00ac81e", parser.add_argument("-t", "--token", default="ad9b37a24380948601257f9c1f889b07a00ac81e",
help="Token to access the REST API of ldvspec", action="store") help="Token to access the REST API of ldvspec", action="store")
parser.add_argument("--host", nargs="?", default='dev', parser.add_argument("--host", nargs="?", default='dev',
help="The ldv-spec-db host. Presets are 'dev', 'test', 'prod', otherwise give a full url like https://atdb.astron.nl/atdb") help="The ldv-spec-db host.")
parser.add_argument("--configuration", default='~/shared/ldv_migrate.cfg',
help="Configuration file containing tunnel and ldvadmin database credentials")
parser.add_argument("-s", "--section", default='postgresql-ldv', parser.add_argument("-s", "--section", default='postgresql-ldv',
help="Add the configuration's section from the database.cfg.") help="Add the configuration's section from the database.cfg.")
# Have payload of more millions will most likely not work # Have payload of more millions will most likely not work
...@@ -113,7 +115,7 @@ def main(): ...@@ -113,7 +115,7 @@ def main():
.format(limit_str) .format(limit_str)
# Create connection using ssh tunnel with the ldvadmin database # Create connection using ssh tunnel with the ldvadmin database
conn, tunnel = connector.connect_postgresql(args.section) conn, tunnel = connector.connect_postgresql(args.configuration, args.section)
count_raw_dps = execute_query(conn, query_count_all_raw_dataproducts)[0][0] count_raw_dps = execute_query(conn, query_count_all_raw_dataproducts)[0][0]
count_pl_dps = execute_query(conn, query_count_all_pipeline_dataproducts)[0][0] count_pl_dps = execute_query(conn, query_count_all_pipeline_dataproducts)[0][0]
logging.info(f"There are {count_raw_dps} raw dataproducts and {count_pl_dps} pipeline dataproduct in the ldvadmin.astrowise table!!") logging.info(f"There are {count_raw_dps} raw dataproducts and {count_pl_dps} pipeline dataproduct in the ldvadmin.astrowise table!!")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment