def initialize_environment()

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


    def initialize_environment(self) -> None:
        if self.read_only:
            return

        try:
            self._ensure_scheduler_in_each_hostgroup()
        except Exception:
            logging.exception(
                "Failed to ensure scheduler was added to each hostgroup. This may cause stability issues."
            )

        expected = 'Complex attribute "ccnodeid" does not exist'
        try:
            if "ccnodeid " in self.ge_env.qbin.qconf(["-sc"]):
                return
        except CalledProcessError as e:
            if e.stdout and e.stdout.decode().strip() != expected:
                raise
        ccnodeid_path = None
        try:
            if self.ge_env.is_uge and self.ge_env.version >= "8.5":
                contents = """name        ccnodeid
shortcut    ccnodeid
type        RESTRING
relop       ==
requestable YES
consumable  NO
default     NONE
urgency     0
aapre       NO
affinity    0.000000"""
                fd, ccnodeid_path = tempfile.mkstemp()

                logging.getLogger("gridengine.driver").info(
                    "ccnodeid complex contents written to %s", ccnodeid_path
                )
                logging.getLogger("gridengine.driver").info(contents)
                with open(fd, "w") as fw:
                    fw.write(contents)
                self.ge_env.qbin.qconf(["-Ace", ccnodeid_path])
            else:
                current_sc = self.ge_env.qbin.qconf(["-sc"])
                current_sc = "\n".join(current_sc.strip().splitlines()[:-1])
                # name shortcut type relop requestable consumable default urgency
                if self.ge_env.is_uge:
                    contents = (
                        current_sc.strip()
                        + "\nccnodeid ccnodeid RESTRING == YES NO NONE 0 NO\n"
                    )
                else:
                    contents = (
                        current_sc.strip()
                        + "\nccnodeid ccnodeid RESTRING == YES NO NONE 0\n"
                    )
                fd, ccnodeid_path = tempfile.mkstemp()

                logging.getLogger("gridengine.driver").info(
                    "ccnodeid appended to complex: contents written to %s",
                    ccnodeid_path,
                )
                logging.getLogger("gridengine.driver").info(contents)
                with open(fd, "w") as fw:
                    fw.write(contents)
                self.ge_env.qbin.qconf(["-Mc", ccnodeid_path])
        finally:
            if ccnodeid_path and os.path.exists(ccnodeid_path):
                try:
                    os.remove(ccnodeid_path)
                except Exception:
                    logging.exception(
                        "Failed to remove temporary file %s.", ccnodeid_path
                    )