Python implementation of remote MEDM executor
In case it's useful, below is a prototype for a pure-Python implementation of the LIGO remote MEDM executor, which may be easier to extend generically than a bash script.
I have not explored it thoroughly, and haven't put any thought into packaging/distribution/testing/..., but it works for me as a proof-of-concept.
Feel free to ignore.
# -*- coding: utf-8 -*-
# Copyright (C) 2023 Cardiff University
"""Launch MEDM using EPICS tunnelled through SSH.
"""
import getpass
import logging
import os
import shlex
import subprocess
from shutil import which
import sshtunnel
log = logging.getLogger("ligo-remote-medm")
PORT = 5000
USERNAME = "duncan.macleod"
PASSWD = getpass.getpass(prompt=f"Password for {USERNAME}: ")
OBS = "H"
IFO = f"{OBS}1"
SITE = f"L{OBS}O"
MACROS = {
"IFO": IFO,
"ifo": IFO.lower(),
"SITE": SITE,
"site": SITE.lower(),
"USERAPPS": "/opt/rtcds/userapps/release/",
}
SITEMAP = f"/ligo/cds/{SITE.lower()}/medm/sitemap.adl"
EPICS_REMOTE_HOST = {
"H": "lhoepics.ligo-wa.caltech.edu",
"L": "lloepics.ligo-wa.caltech.edu",
}[OBS]
log.info("Opening SSH tunnel to f{EPICS_REMOTE_HOST}")
with sshtunnel.open_tunnel(
EPICS_REMOTE_HOST,
ssh_username=USERNAME,
ssh_password=PASSWD,
remote_bind_address=("192.168.25.2", 5064),
local_bind_address=("127.0.0.1", PORT),
logger=log,
) as tunnel:
log.info("SSH tunnel open, launching medm")
try:
cmd = [
which("medm"),
"-macro",
",".join((f"{k}={v}" for k, v in MACROS.items())),
"-x",
SITEMAP,
]
log.debug(f"$ {shlex.join(cmd)}")
subprocess.run(
cmd,
env=os.environ | {
"EPICS_CA_AUTO_ADDR_LIST": "NO",
"EPICS_CA_ADDR_LIST": "",
"EPICS_CA_NAME_SERVERS": f"localhost:{PORT}",
"EPICS_REMOTE_PATH": f"https://{EPICS_REMOTE_HOST}/",
}
)
except KeyboardInterrupt:
log.info("Closing down...")
To run:
mamba create -n medm python=3.11 ligo-medm sshtunnel
conda activate medm
python3 ./remote_medm.py
Edited by Duncan Macleod