-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create last_update_export.py #23
base: main
Are you sure you want to change the base?
Conversation
This script is designed for use in a "disconnect" environment. The host server is to do daily exports based on last build of a channel. This script looks at the list of channels, gets the ChannelLastBuildByID and checks if the date is the current date or prior and then exports that channel. Logging is provided as well to show which channels were updated in that export. The target server can then rsync the `/mnt/export` directory and run another script to execute the inter-server-sync import of the exported data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution!
I've added few comments that I hope it helps to get the script in shape to get merged.
Updates from the source since uploading to uyuni-tools, multiple iterations to streamline have occured. Updates include fixes from comments and further use, which include... 1) script header 2) better path management and configurable parameters 3) use of shutil.rmtree avoiding extra calls to subprocess 4) configurable days for export 5) configurable user/group 6) added the use of mgr-sycn credentials file instead of using username/password in the script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes! This is looking better now! Still I added some comments after your latest changes, maybe you can have a look.
uyuni-tools/last_update_export.py
Outdated
# Configuration Variables | ||
base_dir = "/mnt" # Define base directory where the exports will be. | ||
output_dir = os.path.join(base_dir, "export/updates") | ||
log_dir = os.path.join(base_dir, "logs") | ||
today = datetime.date.today() | ||
target_date = today - datetime.timedelta(days=1) # Define the number of days back for export, 1 day by default | ||
rsync_user = "rsyncuser" # Define rsync user | ||
rsync_group = "users" # Define rsync group |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OTOH these ones I would move them to the top of the file (below imports statements and before functions definition), as user is expected to modify them.
I'd also suggest to use uppercase notation (constants) for those.
uyuni-tools/last_update_export.py
Outdated
MANAGER_LOGIN = config.get('DEFAULT', 'mgrsync.user') | ||
MANAGER_PASSWORD = config.get('DEFAULT', 'mgrsync.password') | ||
SUMA_FQDN = socket.getfqdn() | ||
MANAGER_URL = f"https://{SUMA_FQDN}/rpc/api" | ||
context = ssl.create_default_context() | ||
client = ServerProxy(MANAGER_URL, context=context) | ||
return client, client.auth.login(MANAGER_LOGIN, MANAGER_PASSWORD) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to not use the uppercase notation here, as these values are not hardcoded anymore, and contants are usually defined at the top level of the file.
Maybe just go with something like:
MANAGER_LOGIN = config.get('DEFAULT', 'mgrsync.user') | |
MANAGER_PASSWORD = config.get('DEFAULT', 'mgrsync.password') | |
SUMA_FQDN = socket.getfqdn() | |
MANAGER_URL = f"https://{SUMA_FQDN}/rpc/api" | |
context = ssl.create_default_context() | |
client = ServerProxy(MANAGER_URL, context=context) | |
return client, client.auth.login(MANAGER_LOGIN, MANAGER_PASSWORD) | |
manager_login = config.get('DEFAULT', 'mgrsync.user') | |
manager_password = config.get('DEFAULT', 'mgrsync.password') | |
suma_fqdn = socket.getfqdn() | |
manager_url = f"https://{suma_fqdn}/rpc/api" | |
context = ssl.create_default_context() | |
client = ServerProxy(manager_url, context=context) | |
return client, client.auth.login(manager_login, manager_password) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified.
updated the constants and variables, and changed the order they appear in the script
caught the datetime.date.today()
Co-authored-by: Pablo Suárez Hernández <[email protected]>
removed the shell=True from the subprocess.run command, missed that from the last commit after updating the command
Fixed the shebang line
fixed the command execution
updated script header to be better formatted and easier to read.
This file is part of the last_update_export.py script put forward. This file is for the initial export using the ISSv2 used in a disconnected or air-gapped environment, to do a full export instead of an incremental export as the last_update_export.py, it can also be used to add a new product channel to an air-gapped system.
This script is designed for use in a "disconnect" environment. The host server is to do daily exports based on last build of a channel. This script looks at the list of channels, gets the ChannelLastBuildByID and checks if the date is the current date or prior and then exports that channel.
Logging is provided as well to show which channels were updated in that export.
The target server can then rsync the
/mnt/export
directory and run another script to execute the inter-server-sync import of the exported data.