-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #774 from dynamic-entropy/master
Add fetching locality instructions to helper scripts
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import requests | ||
import json | ||
from urllib.parse import urlparse | ||
import os | ||
|
||
|
||
def parse_apihost_path_map(urls): | ||
parsed_urls = [urlparse(url) for url in urls] | ||
|
||
host_files_map = {} | ||
for url in parsed_urls: | ||
hostname = 'https://' + url.netloc | ||
if hostname not in host_files_map: | ||
host_files_map[hostname] = [] | ||
host_files_map[hostname].append(url.path) | ||
|
||
api_host_files_map = {} | ||
for hostname, files in host_files_map.items(): | ||
response = requests.get(hostname + '/.well-known/wlcg-tape-rest-api', | ||
verify='/etc/grid-security/certificates', | ||
cert=(os.environ['X509_USER_PROXY'], | ||
os.environ['X509_USER_PROXY']), | ||
timeout=180 | ||
) | ||
tape_host = response.json()["endpoints"][0]["uri"] | ||
api_host_files_map[tape_host] = files | ||
return api_host_files_map | ||
|
||
|
||
def get_locality(urls): | ||
host_files_map = parse_apihost_path_map(urls) | ||
|
||
for hostname, files in host_files_map.items(): | ||
response = requests.post(hostname + '/archiveinfo', | ||
data=json.dumps({"paths": files}), | ||
verify='/etc/grid-security/certificates', | ||
cert=(os.environ['X509_USER_PROXY'], | ||
os.environ['X509_USER_PROXY']), | ||
headers={'Content-Type': 'application/json'}, | ||
timeout=180 | ||
) | ||
print(response.text) | ||
|
||
|
||
if __name__ == "__main__": | ||
urls = ["davs://<hostname>:<port><path>"] | ||
get_locality(urls) |