-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from epics-containers/RTEMS
first working draft
- Loading branch information
Showing
15 changed files
with
587 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
# This is the folder the PVC for the nfsv2tftp shared volume is mounted into. | ||
export RTEMS_TFTP_PATH=${RTEMS_TFTP_PATH:-/nfsv2-tftp} | ||
|
||
if [ ! -d ${RTEMS_TFTP_PATH} ]; then | ||
echo "ERROR: No PVC folder found." | ||
# make a folder for testing outside of the cluster | ||
mkdir -p ${RTEMS_TFTP_PATH} | ||
fi | ||
|
||
# copy the IOC instance's runtime assets into the shared volume | ||
cp -rL /epics/ioc ${RTEMS_TFTP_PATH} | ||
cp -r /epics/runtime ${RTEMS_TFTP_PATH} | ||
# move binary to the root for shorter paths | ||
mv ${RTEMS_TFTP_PATH}/ioc/bin/*/ioc.boot ${RTEMS_TFTP_PATH} | ||
# fix up the paths in st.cmd | ||
sed -i "s|/epics/|/iocs/${IOC_LOCATION}/${IOC_NAME}/|" ${RTEMS_TFTP_PATH}/runtime/st.cmd | ||
|
||
# keep the container running ... | ||
while true; do | ||
sleep 2 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# these requirements are for additional python packages to install into the | ||
# container | ||
ibek==1.7.2b6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,148 @@ | ||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
import typer | ||
from jinja2 import Template | ||
from ruamel.yaml import YAML | ||
|
||
from . import __version__ | ||
from .copy import copy_rtems | ||
from .globals import GLOBALS | ||
from .telnet import ioc_connect | ||
|
||
__all__ = ["main"] | ||
|
||
cli = typer.Typer() | ||
|
||
|
||
def version_callback(value: bool): | ||
if value: | ||
typer.echo(__version__) | ||
raise typer.Exit() | ||
|
||
|
||
@cli.callback() | ||
def main( | ||
version: Optional[bool] = typer.Option( | ||
None, | ||
"--version", | ||
callback=version_callback, | ||
is_eager=True, | ||
help="Print the version of ibek and exit", | ||
), | ||
): | ||
""" | ||
Proxy for RTEMS IOCs controlling and monitoring | ||
""" | ||
|
||
|
||
@cli.command() | ||
def start( | ||
copy: bool = typer.Option( | ||
True, "--copy/--no-copy", help="copy binaries before connecting" | ||
), | ||
reboot: bool = typer.Option( | ||
True, "--reboot/--no-reboot", help="reboot the IOC first" | ||
), | ||
): | ||
""" | ||
Starts an RTEMS IOC. Places the IOC binaries in the expected location, | ||
restarts the IOC and connects stdio to the IOC console. | ||
This should be called inside of a runtime IOC container after ibek | ||
has generated the runtime assets for the IOC. | ||
The standard 'start.sh' in the runtime IOC will call this entry point if | ||
it detects that EPICS_HOST_ARCH==RTEMS-beatnik | ||
args: | ||
copy: Copy the RTEMS binaries to the IOCs TFTP and NFS directories first | ||
reboot: Reboot the IOC once the binaries are copied and the connection is made | ||
""" | ||
print( | ||
f"Remote control startup of RTEMS IOC {GLOBALS.IOC_NAME}" | ||
f" at {GLOBALS.RTEMS_IOC_IP}" | ||
) | ||
if copy: | ||
copy_rtems() | ||
ioc_connect(GLOBALS.RTEMS_CONSOLE, reboot=reboot) | ||
|
||
|
||
@cli.command() | ||
def dev( | ||
ioc_repo: Path = typer.Argument( | ||
..., | ||
help="The beamline/accelerator repo holding the IOC instance", | ||
file_okay=False, | ||
exists=True, | ||
), | ||
ioc_name: str = typer.Argument( | ||
..., | ||
help="The name of the IOC instance to work on", | ||
), | ||
): | ||
""" | ||
Sets up a devcontainer to work on an IOC instance. Must be run from within | ||
the developer container for the generic IOC that the instance uses. | ||
args: | ||
ioc_repo: The path to the IOC repository that holds the instance | ||
ioc_name: The name of the IOC instance to work on | ||
""" | ||
|
||
ioc_path = ioc_repo / "services" / ioc_name | ||
|
||
values = ioc_repo / "helm/shared/values.yaml" | ||
if not values.exists(): | ||
typer.echo(f"Global settings file {values} not found. Exiting") | ||
raise typer.Exit(1) | ||
|
||
ioc_values = ioc_path / "values.yaml" | ||
if not ioc_values.exists(): | ||
typer.echo(f"Instance settings file {ioc_values} not found. Exiting") | ||
raise typer.Exit(1) | ||
|
||
env_vars = {} | ||
# TODO in future use pydantic and make a model for this but for now let's cheese it. | ||
with open(values) as fp: | ||
yaml = YAML(typ="safe").load(fp) | ||
try: | ||
ioc_group = yaml["ioc-instance"]["ioc_group"] | ||
for item in yaml["ioc-instance"]["globalEnv"]: | ||
env_vars[item["name"]] = item["value"] | ||
except KeyError: | ||
typer.echo(f"{values} not in expected format") | ||
raise typer.Exit(1) from None | ||
|
||
with open(ioc_values) as fp: | ||
yaml = YAML(typ="safe").load(fp) | ||
try: | ||
for item in yaml["shared"]["ioc-instance"]["iocEnv"]: | ||
env_vars[item["name"]] = item["value"] | ||
except KeyError: | ||
typer.echo(f"{ioc_values} not in expected format") | ||
raise typer.Exit(1) from None | ||
|
||
this_dir = Path(__file__).parent | ||
template = Path(this_dir / "rsync.sh.jinja").read_text() | ||
|
||
script = Template(template).render( | ||
env_vars=env_vars, | ||
ioc_group=ioc_group, | ||
ioc_name=ioc_name, | ||
ioc_path=ioc_path, | ||
) | ||
|
||
script_file = Path("/tmp/dev_proxy.sh") | ||
script_file.write_text(script) | ||
|
||
def main(args=None): | ||
parser = ArgumentParser() | ||
parser.add_argument("-v", "--version", action="version", version=__version__) | ||
args = parser.parse_args(args) | ||
typer.echo(f"\nIOC {ioc_name} dev environment prepared for {ioc_repo}") | ||
typer.echo("You can now change and compile support module or iocs.") | ||
typer.echo("Then start the ioc with '/epics/ioc/start.sh'") | ||
typer.echo(f"\n\nPlease first source {script_file} to set up the dev environment.") | ||
|
||
|
||
# test with: python -m rtems_proxy | ||
# test with: | ||
# pipenv run python -m ibek | ||
if __name__ == "__main__": | ||
main() | ||
cli() |
Oops, something went wrong.