예제 #1
0
    def stop(self, *, instance_name: str) -> None:
        """Passthrough for running multipass stop.

        :param str instance_name: the name of the instance to stop.
        """
        cmd = [self.provider_cmd, "stop", instance_name]
        try:
            _run(cmd)
        except subprocess.CalledProcessError as process_error:
            raise errors.ProviderStopError(
                provider_name=self.provider_name,
                exit_code=process_error.returncode) from process_error
예제 #2
0
 def stop(self) -> None:
     self._ssh_client.close()
     try:
         telnet = telnetlib.Telnet(host="localhost", port=self._telnet_port)
     except socket.gaierror as telnet_error:
         raise errors.ProviderCommunicationError(
             protocol="telnet",
             port=self._telnet_port,
             error=telnet_error.strerror) from telnet_error
     try:
         telnet.read_until("(qemu) ".encode())
         telnet.write("savevm latest\n".encode())
         telnet.read_until("(qemu) ".encode())
         telnet.write("quit\n".encode())
     except (OSError, EOFError) as telnet_error:
         raise errors.ProviderStopError(provider_name=self.provider_name,
                                        exit_code=None) from telnet_error
예제 #3
0
    def stop(self, *, instance_name: str, time: int = None) -> None:
        """Passthrough for running multipass stop.

        :param str instance_name: the name of the instance to stop.
        :param str time: time from now, in minutes, to delay shutdown of the
                         instance.
        """
        cmd = [self.provider_cmd, "stop"]
        if time:
            cmd.extend(["--time", str(time)])
        cmd.append(instance_name)
        try:
            _run(cmd)
        except subprocess.CalledProcessError as process_error:
            raise errors.ProviderStopError(
                provider_name=self.provider_name, exit_code=process_error.returncode
            ) from process_error