@@ -111,6 +111,50 @@ def check_consents(globus_info: GlobusInfo):
111111 native_client .login (requested_scopes = scopes )
112112
113113
114+ # Used exclusively in globus_activate
115+ def set_local_endpoint (globus_info : GlobusInfo ):
116+ ini_path = os .path .expanduser ("~/.zstash.ini" )
117+ ini = configparser .ConfigParser ()
118+ if ini .read (ini_path ):
119+ if "local" in ini .sections ():
120+ globus_info .local_endpoint = ini ["local" ].get ("globus_endpoint_uuid" )
121+ logger .debug (
122+ f"globus endpoint in ~/.zstash.ini: { ep_to_name (globus_info .local_endpoint )} "
123+ )
124+ else :
125+ ini ["local" ] = {"globus_endpoint_uuid" : "" }
126+ try :
127+ with open (ini_path , "w" ) as f :
128+ ini .write (f )
129+ except Exception as e :
130+ logger .error (e )
131+ sys .exit (1 )
132+ if not globus_info .local_endpoint :
133+ fqdn = socket .getfqdn ()
134+ if re .fullmatch (r"n.*\.local" , fqdn ) and os .getenv ("HOSTNAME" , "NA" ).startswith (
135+ "compy"
136+ ):
137+ fqdn = "compy.pnl.gov"
138+ for pattern in REGEX_ENDPOINT_MAP .keys ():
139+ if re .fullmatch (pattern , fqdn ):
140+ globus_info .local_endpoint = REGEX_ENDPOINT_MAP .get (pattern )
141+ break
142+ # FQDN is not set on Perlmutter at NERSC
143+ if not globus_info .local_endpoint :
144+ nersc_hostname = os .environ .get ("NERSC_HOST" )
145+ if nersc_hostname and (
146+ nersc_hostname == "perlmutter" or nersc_hostname == "unknown"
147+ ):
148+ globus_info .local_endpoint = REGEX_ENDPOINT_MAP .get (
149+ r"perlmutter.*\.nersc\.gov"
150+ )
151+ if not globus_info .local_endpoint :
152+ logger .error (
153+ f"{ ini_path } does not have the local Globus endpoint set nor could one be found in REGEX_ENDPOINT_MAP."
154+ )
155+ sys .exit (1 )
156+
157+
114158# Used exclusively in globus_transfer
115159def file_exists (globus_info : GlobusInfo , name : str ) -> bool :
116160 if not globus_info .archive_directory_listing :
@@ -260,45 +304,7 @@ def globus_activate(globus_info: GlobusInfo, alt_hpss: str = ""): # noqa: C901
260304 globus_info .remote_endpoint = globus_info .url .netloc
261305 else :
262306 globus_info .remote_endpoint = globus_info .url .netloc
263-
264- ini_path = os .path .expanduser ("~/.zstash.ini" )
265- ini = configparser .ConfigParser ()
266- if ini .read (ini_path ):
267- if "local" in ini .sections ():
268- globus_info .local_endpoint = ini ["local" ].get ("globus_endpoint_uuid" )
269- else :
270- ini ["local" ] = {"globus_endpoint_uuid" : "" }
271- try :
272- with open (ini_path , "w" ) as f :
273- ini .write (f )
274- except Exception as e :
275- logger .error (e )
276- sys .exit (1 )
277- if not globus_info .local_endpoint :
278- fqdn = socket .getfqdn ()
279- if re .fullmatch (r"n.*\.local" , fqdn ) and os .getenv ("HOSTNAME" , "NA" ).startswith (
280- "compy"
281- ):
282- fqdn = "compy.pnl.gov"
283- for pattern in REGEX_ENDPOINT_MAP .keys ():
284- if re .fullmatch (pattern , fqdn ):
285- globus_info .local_endpoint = REGEX_ENDPOINT_MAP .get (pattern )
286- break
287- # FQDN is not set on Perlmutter at NERSC
288- if not globus_info .local_endpoint :
289- nersc_hostname = os .environ .get ("NERSC_HOST" )
290- if nersc_hostname and (
291- nersc_hostname == "perlmutter" or nersc_hostname == "unknown"
292- ):
293- globus_info .local_endpoint = REGEX_ENDPOINT_MAP .get (
294- r"perlmutter.*\.nersc\.gov"
295- )
296- if not globus_info .local_endpoint :
297- logger .error (
298- f"{ ini_path } does not have the local Globus endpoint set nor could one be found in REGEX_ENDPOINT_MAP."
299- )
300- sys .exit (1 )
301-
307+ set_local_endpoint (globus_info )
302308 if globus_info .remote_endpoint .upper () in HPSS_ENDPOINT_MAP .keys ():
303309 globus_info .remote_endpoint = HPSS_ENDPOINT_MAP .get (
304310 globus_info .remote_endpoint .upper ()
0 commit comments