def add(cls, service: Type["CoreService"]) -> None: """ Add a service to manager. :param service: service to add :return: nothing :raises ValueError: when service cannot be loaded """ name = service.name logger.debug("loading service: class(%s) name(%s)", service.__name__, name) # avoid services with no name if name is None: logger.debug("not loading class(%s) with no name", service.__name__) return # avoid duplicate services if name in cls.services: raise ValueError(f"duplicate service being added: {name}") # validate dependent executables are present for executable in service.executables: try: utils.which(executable, required=True) except CoreError as e: raise CoreError(f"service({name}): {e}") # validate service on load succeeds try: service.on_load() except Exception as e: logger.exception("error during service(%s) on load", service.name) raise ValueError(e) # make service available cls.services[name] = service
def add(self, service: ConfigService) -> None: """ Add service to manager, checking service requirements have been met. :param service: service to add to manager :return: nothing :raises CoreError: when service is a duplicate or has unmet executables """ name = service.name logging.debug("loading service: class(%s) name(%s)", service.__class__, name) # avoid duplicate services if name in self.services: raise CoreError(f"duplicate service being added: {name}") # validate dependent executables are present for executable in service.executables: try: utils.which(executable, required=True) except ValueError: raise CoreError( f"service({service.name}) missing executable {executable}" ) # make service available self.services[name] = service
def _validate_env(self) -> None: """ Validates executables CORE depends on exist on path. :return: nothing :raises core.errors.CoreError: when an executable does not exist on path """ use_ovs = self.config.get("ovs") == "1" for requirement in get_requirements(use_ovs): utils.which(requirement, required=True)
def emane_check(self) -> None: """ Check if emane is installed and load models. :return: nothing """ # check for emane path = utils.which("emane", required=False) if not path: logging.info("emane is not installed") return # get version emane_version = utils.cmd("emane --version") logging.info("using emane: %s", emane_version) # load default emane models self.load_models(EMANE_MODELS) # load custom models custom_models_path = self.session.options.get_config( "emane_models_dir") if custom_models_path: emane_models = utils.load_classes(custom_models_path, EmaneModel) self.load_models(emane_models)
def _load_emane(self) -> None: """ Check if emane is installed and load models. :return: nothing """ # check for emane path = utils.which("emane", required=False) self.has_emane = path is not None if not self.has_emane: logger.info("emane is not installed, emane functionality disabled") return # get version emane_version = utils.cmd("emane --version") logger.info("using emane: %s", emane_version) emane_prefix = self.config.get("emane_prefix", DEFAULT_EMANE_PREFIX) emane_prefix = Path(emane_prefix) EmaneModelManager.load_locals(emane_prefix) # load custom models custom_path = self.config.get("emane_models_dir") if custom_path is not None: logger.info("loading custom emane models: %s", custom_path) custom_path = Path(custom_path) EmaneModelManager.load(custom_path, emane_prefix)