Skip to content

Commit

Permalink
Switch to regular expression for discovery by host
Browse files Browse the repository at this point in the history
Use this to add expressions for compute nodes on Chrysalis,
Blues and Compy.
  • Loading branch information
xylar committed Sep 21, 2023
1 parent 45ad55c commit 600c7fe
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 600c7fe

Please sign in to comment.