コード例 #1
0
    def start(self, *, instance_name: str) -> None:
        """Passthrough for running multipass start.

        :param str instance_name: the name of the instance to start.
        """
        cmd = [self.provider_cmd, "start", instance_name]
        try:
            _run(cmd)
        except subprocess.CalledProcessError as process_error:
            raise errors.ProviderStartError(
                provider_name=self.provider_name,
                exit_code=process_error.returncode) from process_error
コード例 #2
0
    def _wait_for_multipass_ready(cls, *, echoer):
        echoer.wrapped("Waiting for multipass...")
        retry_count = 20
        while retry_count:
            try:
                output = subprocess.check_output([cls.provider_cmd, "version"]).decode()
            except subprocess.CalledProcessError:
                output = ""
            except FileNotFoundError:
                raise errors.ProviderStartError(provider_name=cls.provider_name,
                                                error_message="multipass not found - please check that it"
                                                              " can be found in the configured PATH")

            # if multipassd is in the version information, it means the service is up
            # and we can carry on
            if "multipassd" in output:
                break

            retry_count -= 1
            sleep(1)
コード例 #3
0
    def setup_multipass(cls, *, echoer, platform: str) -> None:
        if platform == "linux":
            install_snaps(["multipass/latest/stable"])
        elif platform == "darwin":
            try:
                subprocess.check_call(["brew", "cask", "install", "multipass"])
            except subprocess.CalledProcessError:
                raise errors.ProviderStartError(provider_name=cls.provider_name,
                                                error_message="Failed to install multipass using homebrew.\n"
                                                              "Verify your homebrew installation and try again.\n"
                                                              "Alternatively, manually install multipass by running"
                                                              " 'brew cask install multipass'.")
        elif platform == "win32":
            windows_install_multipass(echoer)
        else:
            raise EnvironmentError(
                "Setting up multipass for {!r} is not supported.".format(platform)
            )

        # wait for multipassd to be available
        cls._wait_for_multipass_ready(echoer=echoer)