Skip to content

Commit

Permalink
simplified update_hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
XaverStiensmeier committed Dec 5, 2023
1 parent 79fe003 commit 469aebd
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions resources/playbook/roles/bibigrid/files/slurm/create_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,12 @@ def update_hosts(name, ip): # pylint: disable=invalid-name
@param ip: ibibigrid-worker0-3k1eeysgetmg4vb-3p address
@return:
"""
hosts = {"host_entries": {}}
if os.path.isfile(HOSTS_FILE_PATH):
with open(HOSTS_FILE_PATH, mode="r", encoding="utf-8") as hosts_file:
hosts = yaml.safe_load(hosts_file)
if hosts is None or "host_entries" not in hosts.keys():
hosts = {"host_entries": {}}

hosts["host_entries"][name] = ip

with open(HOSTS_FILE_PATH, mode="w", encoding="utf-8") as hosts_file:
with open(HOSTS_FILE_PATH, mode="w+", encoding="utf-8") as hosts_file:
hosts = yaml.safe_load(hosts_file)
if not hosts or "host_entries" not in hosts:
hosts = {"host_entries": {}}
hosts["host_entries"][name] = ip
yaml.dump(hosts, hosts_file)


Expand Down

0 comments on commit 469aebd

Please sign in to comment.