Beispiel #1
0
    def create_instance(self, image: Image, name: str = None, environment: RuntimeEnvironment = None, run=False,
                        runner_kwargs: Dict[str, object] = None,
                        **instance_kwargs) -> RuntimeInstance:
        """
        Runs model service instance and stores it to repository

        :param image: image to run instance from
        :param name: name of instance to run
        :param environment: environment to run instance in, if no given `localhost` is used
        :param run:  whether to automatically run instance after creation
        :param runner_kwargs: additional parameters for runner
        :param instance_kwargs: additional parameters for instance
        :return: :class:`~ebonite.core.objects.RuntimeInstance` instance representing run instance
        """

        if environment is None:
            environment = self.get_default_environment()

        if name is not None and self.meta_repo.get_instance_by_name(name, image, environment) is not None:
            raise ExistingInstanceError(name)

        runner = environment.params.get_runner()

        instance = RuntimeInstance(name)

        instance.params = runner.create_instance(instance.name, **instance_kwargs)
        instance.image = image
        instance.environment = environment
        instance.bind_runner(runner)
        instance = self.meta_repo.create_instance(instance)
        if run:
            runner_kwargs = runner_kwargs or {}
            instance.run(**runner_kwargs)
        return self._bind(instance)
Beispiel #2
0
    def run_instance(self,
                     name: str,
                     image: Image,
                     environment: RuntimeEnvironment = None,
                     **kwargs) -> RuntimeInstance:
        """
        Runs model service instance and stores it to repository

        :param name: name of instance to run
        :param image: image to run instance from
        :param environment: environment to run instance in, if no given `localhost` is used
        :return: :class:`~ebonite.core.objects.RuntimeInstance` instance representing run instance
        """

        if environment is None:
            environment = self.get_default_environment()
        runner = environment.params.get_runner()

        params = runner.create_instance(name, **kwargs)

        instance = RuntimeInstance(name, params=params)
        instance.image = image
        instance.environment = environment
        instance = self.meta_repo.create_instance(instance)

        runner.run(params, image.params, environment.params, **kwargs)

        return instance.bind_runner(runner)