Skip to content

Commit

Permalink
Merge pull request #135 from xylar/detect-compute-nodes
Browse files Browse the repository at this point in the history
Switch to regular expression for discovery by host
  • Loading branch information
xylar authored Sep 21, 2023
2 parents 45ad55c + 600c7fe commit dd2661e
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions mache/discover.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import socket


Expand All @@ -18,29 +19,30 @@ def discover_machine(quiet=False):
"""
hostname = socket.gethostname()
machine = None
machines_by_hostname = {
'acme1': 'acme1',
'andes': 'andes',
'blueslogin': 'anvil',
'ch-fe': 'chicoma-cpu',
'chrlogin': 'chrysalis',
'compy': 'compy',
'cooley': 'cooley'
machines_by_host_re = {
r'^acme1': 'acme1',
r'^andes': 'andes',
r'^blueslogin': 'anvil',
r'^b\d{3}': 'anvil',
r'^ch-fe': 'chicoma-cpu',
r'^chrlogin': 'chrysalis',
r'^chr-\d{4}': 'chrysalis',
r'^compy': 'compy',
r'^n\d{4}': 'anvil',
r'^cooley': 'cooley'
}
found = False
for host, mach in machines_by_hostname.items():
if hostname.startswith(host):
for host_re, mach in machines_by_host_re.items():
p = re.compile(host_re)
if p.match(hostname):
machine = mach
found = True
break
if not found and 'LMOD_SYSTEM_NAME' in os.environ:
if machine is None and 'LMOD_SYSTEM_NAME' in os.environ:
hostname = os.environ['LMOD_SYSTEM_NAME']
if hostname == 'frontier':
# frontier's hostname is too generic to detect, so relying on
# LMOD_SYSTEM_NAME
machine = 'frontier'
found = True
if not found and 'NERSC_HOST' in os.environ:
if machine is None and 'NERSC_HOST' in os.environ:
hostname = os.environ['NERSC_HOST']
if hostname == 'perlmutter':
# perlmutter's hostname is too generic to detect, so relying on
Expand Down

0 comments on commit dd2661e

Please sign in to comment.