mirror of
https://github.com/clearml/clearml-server
synced 2025-02-24 21:24:25 +00:00
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
![]() |
#!/usr/bin/env python3
|
||
|
"""
|
||
|
Apply elasticsearch mappings to given hosts.
|
||
|
"""
|
||
|
import argparse
|
||
|
import json
|
||
|
import requests
|
||
|
from pathlib import Path
|
||
|
|
||
|
HERE = Path(__file__).parent
|
||
|
|
||
|
|
||
|
def apply_mappings_to_host(host: str):
|
||
|
def _send_mapping(f):
|
||
|
with f.open() as json_data:
|
||
|
data = json.load(json_data)
|
||
|
es_server = host
|
||
|
url = f"{es_server}/_template/{f.stem}"
|
||
|
requests.delete(url)
|
||
|
r = requests.post(
|
||
|
url, headers={"Content-Type": "application/json"}, data=json.dumps(data)
|
||
|
)
|
||
|
return {"mapping": f.stem, "result": r.text}
|
||
|
|
||
|
p = HERE / "mappings"
|
||
|
return [
|
||
|
_send_mapping(f) for f in p.iterdir() if f.is_file() and f.suffix == ".json"
|
||
|
]
|
||
|
|
||
|
|
||
|
def parse_args():
|
||
|
parser = argparse.ArgumentParser(
|
||
|
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
|
||
|
)
|
||
|
parser.add_argument("hosts", nargs="+")
|
||
|
return parser.parse_args()
|
||
|
|
||
|
|
||
|
def main():
|
||
|
for host in parse_args().hosts:
|
||
|
print(">>>>> Applying mapping to " + host)
|
||
|
res = apply_mappings_to_host(host)
|
||
|
print(res)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|