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))
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))
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
def _start_vnc(self): """ Start a VNC server for this container """ self._display = self._get_free_display_port() if shutil.which("Xvfb") is None or shutil.which("x11vnc") is None: raise DockerError("Please install Xvfb and x11vnc before using the VNC support") self._xvfb_process = yield from asyncio.create_subprocess_exec("Xvfb", "-nolisten", "tcp", ":{}".format(self._display), "-screen", "0", self._console_resolution + "x16") # We pass a port for TCPV6 due to a crash in X11VNC if not here: https://github.com/GNS3/gns3-server/issues/569 self._x11vnc_process = yield from asyncio.create_subprocess_exec("x11vnc", "-forever", "-nopw", "-shared", "-geometry", self._console_resolution, "-display", "WAIT:{}".format(self._display), "-rfbport", str(self.console), "-rfbportv6", str(self.console), "-noncache", "-listen", self._manager.port_manager.console_host) x11_socket = os.path.join("/tmp/.X11-unix/", "X{}".format(self._display)) yield from wait_for_file_creation(x11_socket)
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
def _asyncio_open_serial_unix(path): """ Open a unix socket or a windows named pipe :returns: An IO like object """ try: # wait for VM to create the pipe file. yield from wait_for_file_creation(path) except asyncio.TimeoutError: raise NodeError('Pipe file "{}" is missing'.format(path)) output = SerialReaderWriterProtocol() try: yield from asyncio.get_event_loop().create_unix_connection(lambda: output, path) except ConnectionRefusedError: raise NodeError('Can\'t open pipe file "{}"'.format(path)) return output
def _asyncio_open_serial_unix(path): """ Open a unix socket or a windows named pipe :returns: An IO like object """ try: # wait for VM to create the pipe file. yield from wait_for_file_creation(path) except asyncio.TimeoutError: raise NodeError('Pipe file "{}" is missing'.format(path)) output = SerialReaderWriterProtocol() try: yield from asyncio.get_event_loop().create_unix_connection( lambda: output, path) except ConnectionRefusedError: raise NodeError('Can\'t open pipe file "{}"'.format(path)) return output