diff --git a/gns3server/compute/qemu/__init__.py b/gns3server/compute/qemu/__init__.py index 10d8187f..07d0ff97 100644 --- a/gns3server/compute/qemu/__init__.py +++ b/gns3server/compute/qemu/__init__.py @@ -53,12 +53,19 @@ class Qemu(BaseManager): :returns: QemuVM instance """ - async with self._guest_cid_lock: - # wait for a node to be completely created before adding a new one - # this is important otherwise we allocate the same application ID - # when creating multiple Qemu VMs at the same time - guest_cid = get_next_guest_cid(self.nodes) - node = await super().create_node(*args, guest_cid=guest_cid, **kwargs) + node = await super().create_node(*args, **kwargs) + + # allocate a guest console ID (CID) + if node.console_type != "none" and node.console: + # by default, the guest CID is equal to the console port + node.guest_cid = node.console + else: + # otherwise pick a guest CID if no console port is configured + async with self._guest_cid_lock: + # wait for a node to be completely created before adding a new one + # this is important otherwise we allocate the same guest ID + # when creating multiple Qemu VMs at the same time + node.guest_cid = get_next_guest_cid(self.nodes) return node @staticmethod diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index 301eaa20..af1cf859 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -67,7 +67,7 @@ class QemuVM(BaseNode): :param platform: Platform to emulate """ - def __init__(self, name, node_id, project, manager, guest_cid=None, linked_clone=True, qemu_path=None, console=None, console_type="telnet", platform=None): + def __init__(self, name, node_id, project, manager, linked_clone=True, qemu_path=None, console=None, console_type="telnet", platform=None): super().__init__(name, node_id, project, manager, console=console, console_type=console_type, linked_clone=linked_clone, wrap_console=True) server_config = manager.config.get_section_config("Server") @@ -80,7 +80,7 @@ class QemuVM(BaseNode): self._qemu_img_stdout_file = "" self._execute_lock = asyncio.Lock() self._local_udp_tunnels = {} - self._guest_cid = guest_cid + self._guest_cid = None # QEMU VM settings if qemu_path: @@ -128,13 +128,23 @@ class QemuVM(BaseNode): @property def guest_cid(self): """ - Returns guest_cid (console ID) which unique identifier between 3 and 65535 + Returns the CID (console ID) which is an unique identifier between 3 and 65535 :returns: integer between 3 and 65535 """ return self._guest_cid + @guest_cid.setter + def guest_cid(self, guest_cid): + """ + Set the CID (console ID) which is an unique identifier between 3 and 65535 + + :returns: integer between 3 and 65535 + """ + + self._guest_cid = guest_cid + @property def monitor(self): """