-
Notifications
You must be signed in to change notification settings - Fork 33
Fetch RSE info from Rucio and save to a file #892
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
Open
d-ylee
wants to merge
4
commits into
dmwm:master
Choose a base branch
from
d-ylee:fix-770_sync-rse-from-git
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+329
−84
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
92fd9a6
Fetch RSE info from Rucio and save to a file
d-ylee 1c3d5d6
Filter mutable settings, start get info from Gitlab
d-ylee f86e809
Script to commit RSE attributes to SITECONF, parse SITECONF rucio
d-ylee c0c190b
Use ignore list for settings and attributes to ignore
d-ylee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,172 @@ | ||
| #!/bin/env python3 | ||
|
|
||
| import base64 | ||
| from collections import ChainMap, defaultdict | ||
| import json | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import gitlab | ||
| from rucio.client import Client | ||
| from rucio.common.exception import Duplicate | ||
|
|
||
| IGNORED_RSE_INFO = ['id', 'protocols'] | ||
|
|
||
| CMS_TYPES = ['test', 'temp'] | ||
|
|
||
| # from rucio.core.rse | ||
| MUTABLE_RSE_PROPERTIES = { | ||
| 'name', | ||
| 'availability_read', | ||
| 'availability_write', | ||
| 'availability_delete', | ||
| 'latitude', | ||
| 'longitude', | ||
| 'time_zone', | ||
| 'rse_type', | ||
| 'volatile', | ||
| 'deterministic', | ||
| 'region_code', | ||
| 'country_name', | ||
| 'city', | ||
| 'staging_area', | ||
| 'qos_class', | ||
| 'continent', | ||
| 'availability' | ||
| } | ||
|
|
||
| IGNORE = [ | ||
| "cms_type", | ||
| "ddm_quota", | ||
| "dm_weight", | ||
| "freespace", | ||
| "fts", | ||
| "lfn2pfn_algorithm", | ||
| "loadtest", | ||
| "min_free_space_percentage", | ||
| "pnn", | ||
| "quota_approvers", | ||
| "region", | ||
| "rule_approvers", | ||
| "site_admins", | ||
| "tier", | ||
| "availability", | ||
| "availability_delete", | ||
| "availability_read", | ||
| "availability_write", | ||
| "deterministic", | ||
| "rse_type", | ||
| "volatile", | ||
| ] | ||
|
|
||
|
|
||
| try: | ||
| client = Client() | ||
| except: | ||
| pass | ||
|
|
||
|
|
||
| def get_info_from_rucio(rse: str) -> dict: | ||
| ''' | ||
| Gets RSE Settings and Attributes | ||
|
|
||
| Similar output to `rucio rse show` | ||
|
|
||
| returns a dict of settings and attributes | ||
| ''' | ||
| rse_info = client.get_rse(rse=rse) | ||
| attributes = client.list_rse_attributes(rse=rse) | ||
|
|
||
| # Settings | ||
| settings = {key: rse_info[key] for i, key in enumerate(sorted(rse_info)) if key in MUTABLE_RSE_PROPERTIES} | ||
|
|
||
| return dict(ChainMap(settings, attributes)) | ||
|
|
||
|
|
||
| def commit_to_gitlab(site: str, data: dict, dry_run: bool = True) -> bool: | ||
| private_token = os.environ['GITLAB_TOKEN'] | ||
| gl = gitlab.Gitlab('https://gitlab.cern.ch', private_token=private_token) | ||
| group = gl.groups.get('siteconf') | ||
| projects = group.projects.list(all=True, search=site) | ||
| if len(projects) > 1: | ||
| print(f'multiple projects found for site: {site}') | ||
| return False | ||
| full_project = gl.projects.get(projects[0].id) | ||
| if not dry_run: | ||
| try: | ||
| commit = full_project.commits.create(data) | ||
| return True | ||
| except Exception as e: | ||
| print(e) | ||
| return False | ||
| else: | ||
| print(f"DRY RUN: {site}, {data}") | ||
| return False | ||
|
|
||
|
|
||
| def commit_to_personal_gitlab(site: str, data: dict, dry_run: bool = True) -> bool: | ||
| private_token = os.environ['GITLAB_TOKEN'] | ||
| gl = gitlab.Gitlab('https://gitlab.cern.ch', private_token=private_token) | ||
| projects = gl.projects.list(owned=True, search=site) | ||
| if len(projects) > 1: | ||
| print(f'multiple projects found for site: {site}') | ||
| return False | ||
| full_project = gl.projects.get(projects[0].id) | ||
| if not dry_run: | ||
| try: | ||
| commit = full_project.commits.create(data) | ||
| return True | ||
| except Exception as e: | ||
| print(e) | ||
| return False | ||
| else: | ||
| print(f"DRY RUN: {site}, {data}") | ||
| return False | ||
|
|
||
|
|
||
| def extract_siteconf_project_name(rse: str) -> str: | ||
| to_remove = ['_Temp', '_Test', '_Tape', '_Disk'] | ||
| for s in to_remove: | ||
| rse = rse.removesuffix(s) | ||
| return rse | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| rses_by_site = defaultdict(list) | ||
| rses = client.list_rses('update_from_json=True') | ||
| for rse in rses: | ||
| name = rse['rse'] | ||
| rse_info = get_info_from_rucio(name) | ||
| file_dest = Path('rse_configs', f'{name}.json') | ||
|
|
||
| with open(file_dest, 'w') as f: | ||
| json.dump(rse_info, f, indent=4) | ||
|
|
||
| project_name = extract_siteconf_project_name(rse['rse']) | ||
| rses_by_site[project_name].append(rse['rse']) | ||
|
|
||
| #sites_to_commit = [] | ||
| sites_to_ignore = ['T2_US_Nebraska'] | ||
|
|
||
| for site, rses in rses_by_site.items(): | ||
| if site in sites_to_commit: | ||
| print(rses) | ||
| a = { | ||
| 'branch': 'master', | ||
| 'commit_message': 'upload initial rse config', | ||
| 'actions': [] | ||
| } | ||
| for rse in rses: | ||
| file_src = Path('rse_configs', f'{rse}.json') | ||
| action = { | ||
| 'action': 'create', | ||
| 'file_path': f'rucio/{rse}.json', | ||
| 'content': open(file_src, 'r').read(), | ||
| 'author_email': 'dylee@fnal.gov', | ||
| 'author_name': 'Dennis Lee' | ||
| } | ||
| a['actions'].append(action) | ||
|
|
||
| commit = commit_to_gitlab(site, a, dry_run=False) | ||
| #commit = commit_to_personal_gitlab(site, a, dry_run=False) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Settings is still coming?