def start(self):
        """
        Starts this VMware VM.
        """

        if (yield from self.is_running()):
            raise VMwareError("The VM is already running in VMware")

        ubridge_path = self.ubridge_path
        if not ubridge_path or not os.path.isfile(ubridge_path):
            raise VMwareError("ubridge is necessary to start a VMware VM")

        if self._use_ubridge:
            yield from self._start_ubridge()

        self._read_vmx_file()
        # check if there is enough RAM to run
        if "memsize" in self._vmx_pairs:
            self.check_available_ram(int(self._vmx_pairs["memsize"]))
        self._set_network_options()
        self._set_serial_console()
        self._write_vmx_file()

        if self._headless:
            yield from self._control_vm("start", "nogui")
        else:
            yield from self._control_vm("start")

        try:
            if self._use_ubridge and self._ubridge_hypervisor:
                for adapter_number in range(0, self._adapters):
                    nio = self._ethernet_adapters[adapter_number].get_nio(0)
                    if nio:
                        yield from self._add_ubridge_connection(
                            nio, adapter_number)

            if self._enable_remote_console and self._console is not None:
                try:
                    if sys.platform.startswith("win"):
                        yield from wait_for_named_pipe_creation(
                            self._get_pipe_name())
                    else:
                        yield from wait_for_file_creation(
                            self._get_pipe_name()
                        )  # wait for VMware to create the pipe file.
                except asyncio.TimeoutError:
                    raise VMwareError(
                        'Pipe file "{}" for remote console has not been created by VMware'
                        .format(self._get_pipe_name()))
                self._start_remote_console()
        except VMwareError:
            yield from self.stop()
            raise

        if self._get_vmx_setting("vhv.enable", "TRUE"):
            self._hw_virtualization = True

        self._started = True
        log.info("VMware VM '{name}' [{id}] started".format(name=self.name,
                                                            id=self.id))
Example #2
0
    def start(self):
        """
        Starts this VMware VM.
        """

        if (yield from self.is_running()):
            raise VMwareError("The VM is already running in VMware")

        ubridge_path = self.ubridge_path
        if not ubridge_path or not os.path.isfile(ubridge_path):
            raise VMwareError("ubridge is necessary to start a VMware VM")

        if self._use_ubridge:
            yield from self._start_ubridge()

        self._read_vmx_file()
        # check if there is enough RAM to run
        if "memsize" in self._vmx_pairs:
            self.check_available_ram(int(self._vmx_pairs["memsize"]))
        self._set_network_options()
        self._set_serial_console()
        self._write_vmx_file()

        if self._headless:
            yield from self._control_vm("start", "nogui")
        else:
            yield from self._control_vm("start")

        try:
            if self._use_ubridge and self._ubridge_hypervisor:
                for adapter_number in range(0, self._adapters):
                    nio = self._ethernet_adapters[adapter_number].get_nio(0)
                    if nio:
                        yield from self._add_ubridge_connection(nio, adapter_number)

            if self._enable_remote_console and self._console is not None:
                try:
                    if sys.platform.startswith("win"):
                        yield from wait_for_named_pipe_creation(self._get_pipe_name())
                    else:
                        yield from wait_for_file_creation(self._get_pipe_name())  # wait for VMware to create the pipe file.
                except asyncio.TimeoutError:
                    raise VMwareError('Pipe file "{}" for remote console has not been created by VMware'.format(self._get_pipe_name()))
                self._start_remote_console()
        except VMwareError:
            yield from self.stop()
            raise

        if self._get_vmx_setting("vhv.enable", "TRUE"):
            self._hw_virtualization = True

        self._started = True
        log.info("VMware VM '{name}' [{id}] started".format(name=self.name, id=self.id))
Example #3
0
def _asyncio_open_serial_windows(path):
    """
    Open a windows named pipe

    :returns: An IO like object
    """

    try:
        yield from wait_for_named_pipe_creation(path)
    except asyncio.TimeoutError:
        raise NodeError('Pipe file "{}" is missing'.format(path))
    return WindowsPipe(path)
Example #4
0
def _asyncio_open_serial_windows(path):
    """
    Open a windows named pipe

    :returns: An IO like object
    """

    try:
        yield from wait_for_named_pipe_creation(path)
    except asyncio.TimeoutError:
        raise NodeError('Pipe file "{}" is missing'.format(path))
    return WindowsPipe(path)
Example #5
0
    def start(self):
        """
        Starts this VirtualBox VM.
        """

        # resume the VM if it is paused
        vm_state = yield from self._get_vm_state()
        if vm_state == "paused":
            yield from self.resume()
            return

        # VM must be powered off to start it
        if vm_state != "poweroff":
            raise VirtualBoxError("VirtualBox VM not powered off")

        yield from self._set_network_options()
        yield from self._set_serial_console()

        # check if there is enough RAM to run
        self.check_available_ram(self.ram)

        args = [self._vmname]
        if self._headless:
            args.extend(["--type", "headless"])
        result = yield from self.manager.execute("startvm", args)
        log.info("VirtualBox VM '{name}' [{id}] started".format(name=self.name,
                                                                id=self.id))
        log.debug("Start result: {}".format(result))

        # add a guest property to let the VM know about the GNS3 name
        yield from self.manager.execute(
            "guestproperty", ["set", self._vmname, "NameInGNS3", self.name])
        # add a guest property to let the VM know about the GNS3 project directory
        yield from self.manager.execute(
            "guestproperty",
            ["set", self._vmname, "ProjectDirInGNS3", self.working_dir])

        if self._enable_remote_console and self._console is not None:
            try:
                # wait for VirtualBox to create the pipe file.
                if sys.platform.startswith("win"):
                    yield from wait_for_named_pipe_creation(
                        self._get_pipe_name())
                else:
                    yield from wait_for_file_creation(self._get_pipe_name())
            except asyncio.TimeoutError:
                raise VirtualBoxError(
                    'Pipe file "{}" for remote console has not been created by VirtualBox'
                    .format(self._get_pipe_name()))
            self._start_remote_console()

        if (yield from self.check_hw_virtualization()):
            self._hw_virtualization = True
Example #6
0
    def start(self):
        """
        Starts this VirtualBox VM.
        """

        # resume the VM if it is paused
        vm_state = yield from self._get_vm_state()
        if vm_state == "paused":
            yield from self.resume()
            return

        # VM must be powered off to start it
        if vm_state != "poweroff":
            raise VirtualBoxError("VirtualBox VM not powered off")

        yield from self._set_network_options()
        yield from self._set_serial_console()

        # check if there is enough RAM to run
        self.check_available_ram(self.ram)

        args = [self._vmname]
        if self._headless:
            args.extend(["--type", "headless"])
        result = yield from self.manager.execute("startvm", args)
        log.info("VirtualBox VM '{name}' [{id}] started".format(name=self.name, id=self.id))
        log.debug("Start result: {}".format(result))

        # add a guest property to let the VM know about the GNS3 name
        yield from self.manager.execute("guestproperty", ["set", self._vmname, "NameInGNS3", self.name])
        # add a guest property to let the VM know about the GNS3 project directory
        yield from self.manager.execute("guestproperty", ["set", self._vmname, "ProjectDirInGNS3", self.working_dir])

        if self._enable_remote_console and self._console is not None:
            try:
                # wait for VirtualBox to create the pipe file.
                if sys.platform.startswith("win"):
                    yield from wait_for_named_pipe_creation(self._get_pipe_name())
                else:
                    yield from wait_for_file_creation(self._get_pipe_name())
            except asyncio.TimeoutError:
                raise VirtualBoxError('Pipe file "{}" for remote console has not been created by VirtualBox'.format(self._get_pipe_name()))
            self._start_remote_console()

        if (yield from self.check_hw_virtualization()):
            self._hw_virtualization = True