Пример #1
0
    async def start(self, destination=None):
        """
        Starts the TraceNG process.
        """

        if not sys.platform.startswith("win"):
            raise TraceNGError("Sorry, TraceNG can only run on Windows")
        await self._check_requirements()
        if not self.is_running():
            nio = self._ethernet_adapter.get_nio(0)
            command = self._build_command(destination)
            await self._stop_ubridge()  # make use we start with a fresh uBridge instance
            try:
                log.info("Starting TraceNG: {}".format(command))
                flags = 0
                if hasattr(subprocess, "CREATE_NEW_CONSOLE"):
                    flags = subprocess.CREATE_NEW_CONSOLE
                self.command_line = ' '.join(command)
                self._process = await asyncio.create_subprocess_exec(*command,
                                                                          cwd=self.working_dir,
                                                                          creationflags=flags)
                monitor_process(self._process, self._termination_callback)

                await self._start_ubridge()
                if nio:
                    await self.add_ubridge_udp_connection("TraceNG-{}".format(self._id), self._local_udp_tunnel[1], nio)

                log.info("TraceNG instance {} started PID={}".format(self.name, self._process.pid))
                self._started = True
                self.status = "started"
            except (OSError, subprocess.SubprocessError) as e:
                log.error("Could not start TraceNG {}: {}\n".format(self._traceng_path(), e))
                raise TraceNGError("Could not start TraceNG {}: {}\n".format(self._traceng_path(), e))
Пример #2
0
    async def start(self):
        """
        Starts the uBridge hypervisor process.
        """

        env = os.environ.copy()
        if sys.platform.startswith("win"):
            # add the Npcap directory to $PATH to force uBridge to use npcap DLL instead of Winpcap (if installed)
            system_root = os.path.join(os.path.expandvars("%SystemRoot%"),
                                       "System32", "Npcap")
            if os.path.isdir(system_root):
                env["PATH"] = system_root + ';' + env["PATH"]
        await self._check_ubridge_version(env)
        try:
            command = self._build_command()
            log.info("starting ubridge: {}".format(command))
            self._stdout_file = os.path.join(self._working_dir, "ubridge.log")
            log.info("logging to {}".format(self._stdout_file))
            with open(self._stdout_file, "w", encoding="utf-8") as fd:
                self._process = await asyncio.create_subprocess_exec(
                    *command,
                    stdout=fd,
                    stderr=subprocess.STDOUT,
                    cwd=self._working_dir,
                    env=env)

            log.info("ubridge started PID={}".format(self._process.pid))
            monitor_process(self._process, self._termination_callback)
        except (OSError, subprocess.SubprocessError) as e:
            ubridge_stdout = self.read_stdout()
            log.error("Could not start ubridge: {}\n{}".format(
                e, ubridge_stdout))
            raise UbridgeError("Could not start ubridge: {}\n{}".format(
                e, ubridge_stdout))
Пример #3
0
    async def _start_vnc(self):
        """
        Starts a VNC server for this container
        """

        self._display = self._get_free_display_port()
        tigervnc_path = shutil.which("Xtigervnc") or shutil.which("Xvnc")
        if not (tigervnc_path
                or shutil.which("Xvfb") and shutil.which("x11vnc")):
            raise DockerError(
                "Please install TigerVNC server (recommended) or Xvfb + x11vnc before using VNC support"
            )
        await self._start_vnc_process()
        x11_socket = os.path.join("/tmp/.X11-unix/",
                                  "X{}".format(self._display))
        try:
            await wait_for_file_creation(x11_socket)
        except asyncio.TimeoutError:
            raise DockerError(
                'x11 socket file "{}" does not exist'.format(x11_socket))

        if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
            # Start vncconfig for tigervnc clipboard support, connection available only after socket creation.
            tigervncconfig_path = shutil.which("vncconfig")
            if tigervnc_path and tigervncconfig_path:
                self._vncconfig_process = await asyncio.create_subprocess_exec(
                    tigervncconfig_path, "-display",
                    ":{}".format(self._display), "-nowin")

        # sometimes the VNC process can crash
        monitor_process(self._vnc_process, self._vnc_callback)
Пример #4
0
    def start(self):
        """
        Starts the VPCS process.
        """

        yield from self._check_requirements()
        if not self.is_running():
            if not self._ethernet_adapter.get_nio(0):
                raise VPCSError("This VPCS instance must be connected in order to start")

            self._command = self._build_command()
            try:
                log.info("Starting VPCS: {}".format(self._command))
                self._vpcs_stdout_file = os.path.join(self.working_dir, "vpcs.log")
                log.info("Logging to {}".format(self._vpcs_stdout_file))
                flags = 0
                if sys.platform.startswith("win32"):
                    flags = subprocess.CREATE_NEW_PROCESS_GROUP
                with open(self._vpcs_stdout_file, "w", encoding="utf-8") as fd:
                    self._process = yield from asyncio.create_subprocess_exec(*self._command,
                                                                              stdout=fd,
                                                                              stderr=subprocess.STDOUT,
                                                                              cwd=self.working_dir,
                                                                              creationflags=flags)
                    monitor_process(self._process, self._termination_callback)
                log.info("VPCS instance {} started PID={}".format(self.name, self._process.pid))
                self._started = True
                self.status = "started"
            except (OSError, subprocess.SubprocessError) as e:
                vpcs_stdout = self.read_vpcs_stdout()
                log.error("Could not start VPCS {}: {}\n{}".format(self.vpcs_path, e, vpcs_stdout))
                raise VPCSError("Could not start VPCS {}: {}\n{}".format(self.vpcs_path, e, vpcs_stdout))
Пример #5
0
    async def start(self):
        """
        Starts this Docker container.
        """

        try:
            state = await self._get_container_state()
        except DockerHttp404Error:
            raise DockerError("Docker container '{name}' with ID {cid} does not exist or is not ready yet. Please try again in a few seconds.".format(name=self.name,
                                                                                                                                                      cid=self._cid))
        if state == "paused":
            await self.unpause()
        elif state == "running":
            return
        else:

            if self._console_type == "vnc" and not self._vnc_process:
                # restart the vnc process in case it had previously crashed
                await self._start_vnc_process(restart=True)
                monitor_process(self._vnc_process, self._vnc_callback)

            await self._clean_servers()

            await self.manager.query("POST", "containers/{}/start".format(self._cid))
            self._namespace = await self._get_namespace()

            await self._start_ubridge(require_privileged_access=True)

            for adapter_number in range(0, self.adapters):
                nio = self._ethernet_adapters[adapter_number].get_nio(0)
                async with self.manager.ubridge_lock:
                    try:
                        await self._add_ubridge_connection(nio, adapter_number)
                    except UbridgeNamespaceError:
                        log.error("Container %s failed to start", self.name)
                        await self.stop()

                        # The container can crash soon after the start, this means we can not move the interface to the container namespace
                        logdata = await self._get_log()
                        for line in logdata.split('\n'):
                            log.error(line)
                        raise DockerError(logdata)

            if self.console_type == "telnet":
                await self._start_console()
            elif self.console_type == "http" or self.console_type == "https":
                await self._start_http()

            if self.allocate_aux:
                await self._start_aux()

        self._permissions_fixed = False
        self.status = "started"
        log.info("Docker container '{name}' [{image}] started listen for {console_type} on {console}".format(name=self._name,
                                                                                                             image=self._image,
                                                                                                             console=self.console,
                                                                                                             console_type=self.console_type))
Пример #6
0
    async def _start_vnc(self):
        """
        Starts a VNC server for this container
        """

        self._display = self._get_free_display_port()
        if not (shutil.which("Xtigervnc") or shutil.which("Xvfb") and shutil.which("x11vnc")):
            raise DockerError("Please install tigervnc-standalone-server (recommended) or Xvfb + x11vnc before using VNC support")
        await self._start_vnc_process()
        x11_socket = os.path.join("/tmp/.X11-unix/", "X{}".format(self._display))
        await wait_for_file_creation(x11_socket)

        # sometimes the VNC process can crash
        monitor_process(self._vnc_process, self._vnc_callback)
Пример #7
0
    async def start(self):
        """
        Starts the VPCS process.
        """

        await self._check_requirements()
        if not self.is_running():
            nio = self._ethernet_adapter.get_nio(0)
            command = self._build_command()
            try:
                log.info("Starting VPCS: {}".format(command))
                self._vpcs_stdout_file = os.path.join(self.working_dir,
                                                      "vpcs.log")
                log.info("Logging to {}".format(self._vpcs_stdout_file))
                flags = 0
                if sys.platform.startswith("win32"):
                    flags = subprocess.CREATE_NEW_PROCESS_GROUP
                with open(self._vpcs_stdout_file, "w", encoding="utf-8") as fd:
                    self.command_line = ' '.join(command)
                    self._process = await asyncio.create_subprocess_exec(
                        *command,
                        stdout=fd,
                        stderr=subprocess.STDOUT,
                        cwd=self.working_dir,
                        creationflags=flags)
                    monitor_process(self._process, self._termination_callback)

                await self._start_ubridge()
                if nio:
                    await self.add_ubridge_udp_connection(
                        "VPCS-{}".format(self._id), self._local_udp_tunnel[1],
                        nio)

                await self.start_wrap_console()

                log.info("VPCS instance {} started PID={}".format(
                    self.name, self._process.pid))
                self._started = True
                self.status = "started"
            except (OSError, subprocess.SubprocessError) as e:
                vpcs_stdout = self.read_vpcs_stdout()
                log.error("Could not start VPCS {}: {}\n{}".format(
                    self._vpcs_path(), e, vpcs_stdout))
                raise VPCSError("Could not start VPCS {}: {}\n{}".format(
                    self._vpcs_path(), e, vpcs_stdout))
Пример #8
0
    async def _start_vnc(self):
        """
        Starts a VNC server for this container
        """

        self._display = self._get_free_display_port()
        if not (shutil.which("Xtigervnc")
                or shutil.which("Xvfb") and shutil.which("x11vnc")):
            raise DockerError(
                "Please install tigervnc-standalone-server (recommended) or Xvfb + x11vnc before using VNC support"
            )
        await self._start_vnc_process()
        x11_socket = os.path.join("/tmp/.X11-unix/",
                                  "X{}".format(self._display))
        await wait_for_file_creation(x11_socket)

        # sometimes the VNC process can crash
        monitor_process(self._vnc_process, self._vnc_callback)
Пример #9
0
    async def start(self, destination=None):
        """
        Starts the TraceNG process.
        """

        if not sys.platform.startswith("win"):
            raise TraceNGError("Sorry, TraceNG can only run on Windows")
        await self._check_requirements()
        if not self.is_running():
            nio = self._ethernet_adapter.get_nio(0)
            command = self._build_command(destination)
            await self._stop_ubridge(
            )  # make use we start with a fresh uBridge instance
            try:
                log.info("Starting TraceNG: {}".format(command))
                flags = 0
                if hasattr(subprocess, "CREATE_NEW_CONSOLE"):
                    flags = subprocess.CREATE_NEW_CONSOLE
                self.command_line = ' '.join(command)
                self._process = await asyncio.create_subprocess_exec(
                    *command, cwd=self.working_dir, creationflags=flags)
                monitor_process(self._process, self._termination_callback)

                await self._start_ubridge()
                if nio:
                    await self.add_ubridge_udp_connection(
                        "TraceNG-{}".format(self._id),
                        self._local_udp_tunnel[1], nio)

                log.info("TraceNG instance {} started PID={}".format(
                    self.name, self._process.pid))
                self._started = True
                self.status = "started"
            except (OSError, subprocess.SubprocessError) as e:
                log.error("Could not start TraceNG {}: {}\n".format(
                    self._traceng_path(), e))
                raise TraceNGError("Could not start TraceNG {}: {}\n".format(
                    self._traceng_path(), e))
Пример #10
0
    async def start(self):
        """
        Starts this Docker container.
        """

        try:
            state = await self._get_container_state()
        except DockerHttp404Error:
            raise DockerError(
                "Docker container '{name}' with ID {cid} does not exist or is not ready yet. Please try again in a few seconds."
                .format(name=self.name, cid=self._cid))
        if state == "paused":
            await self.unpause()
        elif state == "running":
            return
        else:

            if self._console_type == "vnc" and not self._vnc_process:
                # restart the vnc process in case it had previously crashed
                await self._start_vnc_process(restart=True)
                monitor_process(self._vnc_process, self._vnc_callback)

            await self._clean_servers()

            await self.manager.query("POST",
                                     "containers/{}/start".format(self._cid))
            self._namespace = await self._get_namespace()

            await self._start_ubridge(require_privileged_access=True)

            for adapter_number in range(0, self.adapters):
                nio = self._ethernet_adapters[adapter_number].get_nio(0)
                async with self.manager.ubridge_lock:
                    try:
                        await self._add_ubridge_connection(nio, adapter_number)
                    except UbridgeNamespaceError:
                        log.error("Container %s failed to start", self.name)
                        await self.stop()

                        # The container can crash soon after the start, this means we can not move the interface to the container namespace
                        logdata = await self._get_log()
                        for line in logdata.split('\n'):
                            log.error(line)
                        raise DockerError(logdata)

            if self.console_type == "telnet":
                await self._start_console()
            elif self.console_type == "http" or self.console_type == "https":
                await self._start_http()

            if self.allocate_aux:
                await self._start_aux()

        self._permissions_fixed = False
        self.status = "started"
        log.info(
            "Docker container '{name}' [{image}] started listen for {console_type} on {console}"
            .format(name=self._name,
                    image=self._image,
                    console=self.console,
                    console_type=self.console_type))