From 9c4f0a535d0b6a850be757c2661d3a46c7a2fd9b Mon Sep 17 00:00:00 2001 From: Benjamin Labrecque Date: Mon, 6 Jul 2026 11:56:52 +0200 Subject: [PATCH] chore: extract service creator class --- ansible/new-service-playbook.yml | 2 +- cli/src/core/models.py | 30 +++++++++- cli/src/core/render_templates.py | 33 ----------- cli/src/service.py | 33 ++--------- docs/ioc.md | 16 +++++ .../ioc/AGEBD-CPCL-MASTER-DEV_parameters.yaml | 2 +- .../ioc/AGEBD-CPCL-MASTER_main.subs | 58 +++++++++---------- .../ioc/AGEBD-CPCL-MASTER_parameters.yaml | 2 +- 8 files changed, 79 insertions(+), 97 deletions(-) delete mode 100644 cli/src/core/render_templates.py diff --git a/ansible/new-service-playbook.yml b/ansible/new-service-playbook.yml index b92c11f..ec4617e 100644 --- a/ansible/new-service-playbook.yml +++ b/ansible/new-service-playbook.yml @@ -1,5 +1,5 @@ - name: Auto-provision new service pipeline - hosts: localhost + hosts: sls-lc gather_facts: false #TODO: docs? diff --git a/cli/src/core/models.py b/cli/src/core/models.py index d66416c..0f53506 100644 --- a/cli/src/core/models.py +++ b/cli/src/core/models.py @@ -1,16 +1,19 @@ import re -from pathlib import Path from typing import ClassVar import yaml from pydantic import BaseModel, field_validator from core.enums import ServiceStatus +from core.utils import get_git_root -HERE_DIR = Path(__file__).parent -CONFIG_DIR = HERE_DIR / ".." / ".." / ".." / "config" +REPO_ROOT = get_git_root(__file__) +CONFIG_DIR = REPO_ROOT / "config" SERVICE_REGISTRY_FILENAME = CONFIG_DIR / "services_registry.yml" +MASTER_SERVICE_DIR = REPO_ROOT / "services" / "000-master" +MASTER_SERVICE_CONFIG_DIR = MASTER_SERVICE_DIR / "app" / "config" + class Service(BaseModel): id: int @@ -75,3 +78,24 @@ class ServiceRegistry(BaseModel): def write_to_config(self) -> None: with open(self.config_path, "w") as f: yaml.safe_dump(self.model_dump(), f) + + +class MasterHLANames(BaseModel): + config_path: ClassVar[str] = str(MASTER_SERVICE_CONFIG_DIR) + + hla_apps: list[str] + + @classmethod + def read_from_config(cls) -> "MasterHLANames": + with open(cls.config_path) as f: + d = yaml.safe_load(f) + + hla_names = MasterHLANames.model_validate(d) + return hla_names + + def add_hla_name(self, name: str): + self.hla_apps.append(name) + + def write_to_config(self) -> None: + with open(self.config_path, "w") as f: + yaml.safe_dump(self.model_dump(), f) diff --git a/cli/src/core/render_templates.py b/cli/src/core/render_templates.py deleted file mode 100644 index fba7b4b..0000000 --- a/cli/src/core/render_templates.py +++ /dev/null @@ -1,33 +0,0 @@ -import copier - -from core.utils import get_git_root - -REPO_ROOT = get_git_root(__file__) -SERVICE_TEMPLATES_DIR = REPO_ROOT / "templates" / "service" -SERVICE_DEST_DIR = REPO_ROOT / "services" - - -def render_new_service_templates( - service_id: str, - service_name_upper: str, - service_name_lower: str, - ioc_host: str, - ioc_port: int, - user: str, -): - """ - Render template files for a new service - """ - copier.run_copy( - src_path=str(SERVICE_TEMPLATES_DIR), - dst_path=str(SERVICE_DEST_DIR), - data={ - "service_id": service_id, - "service_name_upper": service_name_upper, - "service_name_lower": service_name_lower, - # TODO: restrict this, use enum - "ioc_host": ioc_host, - "ioc_port": ioc_port, - "user": user, - }, - ) diff --git a/cli/src/service.py b/cli/src/service.py index 9c64488..239f88e 100644 --- a/cli/src/service.py +++ b/cli/src/service.py @@ -1,9 +1,7 @@ -import git import typer -from core.git import assert_clean_repo, git_push_changes, switch_branch from core.models import ServiceRegistry -from core.render_templates import render_new_service_templates +from core.service_creator import ServiceCreator from core.utils import get_git_root, init_logging service = typer.Typer(no_args_is_help=True) @@ -16,35 +14,12 @@ def add( name: str = typer.Option(..., "--name", "-n"), ): init_logging() - - registry = ServiceRegistry.read_from_config() - service = registry.add_service(name) - - repo = git.Repo(REPO_ROOT) - assert_clean_repo(repo) - original_branch = repo.active_branch.name - branch_name = f"feature/add-service-{service.name_lower}" - switch_branch(repo, branch_name) - - render_new_service_templates( - service_id=service.id_str, - service_name_upper=service.name_upper, - service_name_lower=service.name_lower, + # TODO: Maybe create a GitPusher context manager + ServiceCreator( ioc_host="ex-host", # TODO ioc_port=9999, # TODO user="user", # TODO - ) - registry.write_to_config() - - git_push_changes( - repo=repo, - branch_name=f"feature/add-service-{service.name_lower}", - service_dir_rel_path=f"services/{service.dir_name}", - registry_file_rel_path="config/services_registry.yml", - commit_msg=f"feature: add new service {service.name_lower}", - ) - - switch_branch(repo, original_branch) + ).add_service(name=name) @service.command() diff --git a/docs/ioc.md b/docs/ioc.md index 747745b..3e9d24f 100644 --- a/docs/ioc.md +++ b/docs/ioc.md @@ -33,3 +33,19 @@ Result: on ioc host, e.g. `sls-vserv-bd-01-dev` ```shell vim /etc/shellbox/ ``` + +## Check PVs of installed IOC + +```shell +ioc shell AGEBD-CPCL-MASTER-DEV +``` + +```shell +> dbl +``` + +Exit: + +```shell +Ctrl + d +``` \ No newline at end of file diff --git a/services/000-master/ioc/AGEBD-CPCL-MASTER-DEV_parameters.yaml b/services/000-master/ioc/AGEBD-CPCL-MASTER-DEV_parameters.yaml index 6c46231..3c8d77a 100644 --- a/services/000-master/ioc/AGEBD-CPCL-MASTER-DEV_parameters.yaml +++ b/services/000-master/ioc/AGEBD-CPCL-MASTER-DEV_parameters.yaml @@ -1,6 +1,6 @@ cpu_architecture: x86_64 epics_version: 7.0.8 ioc_host: sls-vserv-bd-01-dev -ioc_port: 50000 +ioc_port: 50011 os: RHEL8 os_id: rhel diff --git a/services/000-master/ioc/AGEBD-CPCL-MASTER_main.subs b/services/000-master/ioc/AGEBD-CPCL-MASTER_main.subs index 5879e80..62e1099 100644 --- a/services/000-master/ioc/AGEBD-CPCL-MASTER_main.subs +++ b/services/000-master/ioc/AGEBD-CPCL-MASTER_main.subs @@ -1,33 +1,33 @@ file MASTER.template { pattern { SUFFIX SERVICE STARTON AUTOOFF } - { "-DEV", "MASTER" , "0", "30" } - { "-DEV", "NTURNS" , "0", "0" } - { "-DEV", "DBPM3CURR" , "1", "0" } - { "-DEV", "TAUBPM" , "1", "0" } - { "-DEV", "TAUPCT" , "1", "0" } - { "-DEV", "SCRUBBING" , "1", "0" } - { "-DEV", "TIMING" , "0", "0" } - { "-DEV", "TUNE" , "1", "0" } - { "-DEV", "INJECTIONGUARD" , "1", "0" } - { "-DEV", "POSTMORTEMLOG" , "1", "0" } - { "-DEV", "TUNEBUMP" , "1", "0" } - { "-DEV", "PLOTS" , "0", "0" } - { "-DEV", "ORBITBUMP" , "0", "0" } - { "-DEV", "TOPUPTOOL" , "0", "0" } - { "-DEV", "SHIFTTOOL" , "1", "0" } - { "-DEV", "BEAMTRANSFERCHECKS" , "0", "0" } - { "-DEV", "TUNEFBX" , "0", "0" } - { "-DEV", "TUNEFBY" , "0", "0" } - { "-DEV", "OPTICSFF-X02S" , "0", "0" } # I-TOMCAT - { "-DEV", "OPTICSFF-X03M" , "0", "0" } # ADRESS - { "-DEV", "OPTICSFF-X04S" , "0", "0" } # ADDAMS - { "-DEV", "OPTICSFF-X05L" , "0", "0" } # QUEST - { "-DEV", "OPTICSFF-X06S" , "0", "0" } # PXI - { "-DEV", "OPTICSFF-X07M" , "0", "0" } # PHOENIX/XTREME - { "-DEV", "OPTICSFF-X08S" , "0", "0" } # MicroXAS - { "-DEV", "OPTICSFF-X09L" , "0", "0" } # OPERA - { "-DEV", "OPTICSFF-X10S" , "0", "0" } # PXII - { "-DEV", "OPTICSFF-X11M" , "0", "0" } # SIM - { "-DEV", "OPTICSFF-X12S" , "0", "0" } # cSAXS + { "", "MASTER" , "0", "30" } + { "", "NTURNS" , "0", "0" } + { "", "DBPM3CURR" , "1", "0" } + { "", "TAUBPM" , "1", "0" } + { "", "TAUPCT" , "1", "0" } + { "", "SCRUBBING" , "1", "0" } + { "", "TIMING" , "0", "0" } + { "", "TUNE" , "1", "0" } + { "", "INJECTIONGUARD" , "1", "0" } + { "", "POSTMORTEMLOG" , "1", "0" } + { "", "TUNEBUMP" , "1", "0" } + { "", "PLOTS" , "0", "0" } + { "", "ORBITBUMP" , "0", "0" } + { "", "TOPUPTOOL" , "0", "0" } + { "", "SHIFTTOOL" , "1", "0" } + { "", "BEAMTRANSFERCHECKS" , "0", "0" } + { "", "TUNEFBX" , "0", "0" } + { "", "TUNEFBY" , "0", "0" } + { "", "OPTICSFF-X02S" , "0", "0" } # I-TOMCAT + { "", "OPTICSFF-X03M" , "0", "0" } # ADRESS + { "", "OPTICSFF-X04S" , "0", "0" } # ADDAMS + { "", "OPTICSFF-X05L" , "0", "0" } # QUEST + { "", "OPTICSFF-X06S" , "0", "0" } # PXI + { "", "OPTICSFF-X07M" , "0", "0" } # PHOENIX/XTREME + { "", "OPTICSFF-X08S" , "0", "0" } # MicroXAS + { "", "OPTICSFF-X09L" , "0", "0" } # OPERA + { "", "OPTICSFF-X10S" , "0", "0" } # PXII + { "", "OPTICSFF-X11M" , "0", "0" } # SIM + { "", "OPTICSFF-X12S" , "0", "0" } # cSAXS } diff --git a/services/000-master/ioc/AGEBD-CPCL-MASTER_parameters.yaml b/services/000-master/ioc/AGEBD-CPCL-MASTER_parameters.yaml index 6c46231..3c8d77a 100644 --- a/services/000-master/ioc/AGEBD-CPCL-MASTER_parameters.yaml +++ b/services/000-master/ioc/AGEBD-CPCL-MASTER_parameters.yaml @@ -1,6 +1,6 @@ cpu_architecture: x86_64 epics_version: 7.0.8 ioc_host: sls-vserv-bd-01-dev -ioc_port: 50000 +ioc_port: 50011 os: RHEL8 os_id: rhel