def _ensure_scheduler_in_each_hostgroup()

in gridengine/src/gridengine/driver.py [0:0]


    def _ensure_scheduler_in_each_hostgroup(self) -> None:
        if not self.autoscale_config.get("grideninge", {}).get(
            "add_schedulers_to_hostgroups", True
        ):
            return
        scheduler_hostnames = self.ge_env.qbin.qconf(["-sss"]).split()

        for hostgroup in self.ge_env.qbin.qconf(["-shgrpl"]).split():
            fqdns = self.ge_env.qbin.qconf(["-shgrp_resolved", hostgroup]).split()
            hostnames = [n.split(".")[0] for n in fqdns]
            for sched_hostname in scheduler_hostnames:
                if sched_hostname not in hostnames:
                    logging.warning(
                        "Scheduler %s is not in hostgroup %s", sched_hostname, hostgroup
                    )
                    logging.warning(
                        'To disable this behavior, set {"gridengine": "add_schedulers_to_hostgroups": false}}'
                    )
                    hg_path = None
                    try:
                        fd, hg_path = tempfile.mkstemp()
                        contents = self.ge_env.qbin.qconf(["-shgrp", hostgroup]).strip()
                        if contents.endswith("NONE"):
                            contents = contents[: -len("NONE")]

                        contents = "{}\\\n{}".format(contents, sched_hostname)
                        logging.getLogger("gridengine.driver").info(
                            "hostgroup contents written to %s", hg_path
                        )
                        logging.getLogger("gridengine.driver").info(contents)
                        with open(fd, "w") as fw:
                            fw.write(contents)
                        self.ge_env.qbin.qconf(["-Mhgrp", hg_path])
                    finally:
                        if hg_path and os.path.exists(hg_path):
                            try:
                                os.remove(hg_path)
                            except Exception:
                                logging.exception(
                                    "Failed to remove temporary file %s.", hg_path
                                )