mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 16:28:11 +00:00
Allocation of console port in base vm
This commit is contained in:
parent
4a3e6632c1
commit
25bcbfb073
@ -28,12 +28,28 @@ log = logging.getLogger(__name__)
|
||||
|
||||
class BaseVM:
|
||||
|
||||
def __init__(self, name, vm_id, project, manager):
|
||||
"""
|
||||
Base vm implementation.
|
||||
|
||||
:param name: name of this IOU vm
|
||||
:param vm_id: IOU instance identifier
|
||||
:param project: Project instance
|
||||
:param manager: parent VM Manager
|
||||
:param console: TCP console port
|
||||
"""
|
||||
|
||||
def __init__(self, name, vm_id, project, manager, console=None):
|
||||
|
||||
self._name = name
|
||||
self._id = vm_id
|
||||
self._project = project
|
||||
self._manager = manager
|
||||
self._console = console
|
||||
|
||||
if self._console is not None:
|
||||
self._console = self._manager.port_manager.reserve_console_port(self._console)
|
||||
else:
|
||||
self._console = self._manager.port_manager.get_free_console_port()
|
||||
|
||||
log.debug("{module}: {name} [{id}] initialized".format(module=self.manager.module_name,
|
||||
name=self.name,
|
||||
@ -147,3 +163,32 @@ class BaseVM:
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
def console(self):
|
||||
"""
|
||||
Returns the console port of this VPCS vm.
|
||||
|
||||
:returns: console port
|
||||
"""
|
||||
|
||||
return self._console
|
||||
|
||||
@console.setter
|
||||
def console(self, console):
|
||||
"""
|
||||
Change console port
|
||||
|
||||
:params console: Console port (integer)
|
||||
"""
|
||||
|
||||
if console == self._console:
|
||||
return
|
||||
if self._console:
|
||||
self._manager.port_manager.release_console_port(self._console)
|
||||
self._console = self._manager.port_manager.reserve_console_port(console)
|
||||
log.info("{module}: '{name}' [{id}]: console port set to {port}".format(
|
||||
module=self.manager.module_name,
|
||||
name=self.name,
|
||||
id=self.id,
|
||||
port=console))
|
||||
|
@ -83,7 +83,6 @@ class Router(BaseVM):
|
||||
self._disk0 = 0 # Megabytes
|
||||
self._disk1 = 0 # Megabytes
|
||||
self._confreg = "0x2102"
|
||||
self._console = None
|
||||
self._aux = None
|
||||
self._mac_addr = ""
|
||||
self._system_id = "FTX0945W0MY" # processor board ID in IOS
|
||||
@ -106,11 +105,6 @@ class Router(BaseVM):
|
||||
raise DynamipsError("Dynamips identifier {} is already used by another router".format(dynamips_id))
|
||||
self._dynamips_ids[project.id].append(self._dynamips_id)
|
||||
|
||||
if self._console is not None:
|
||||
self._console = self._manager.port_manager.reserve_console_port(self._console)
|
||||
else:
|
||||
self._console = self._manager.port_manager.get_free_console_port()
|
||||
|
||||
if self._aux is not None:
|
||||
self._aux = self._manager.port_manager.reserve_console_port(self._aux)
|
||||
else:
|
||||
@ -863,16 +857,6 @@ class Router(BaseVM):
|
||||
new_confreg=confreg))
|
||||
self._confreg = confreg
|
||||
|
||||
@property
|
||||
def console(self):
|
||||
"""
|
||||
Returns the TCP console port.
|
||||
|
||||
:returns: console port (integer)
|
||||
"""
|
||||
|
||||
return self._console
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_console(self, console):
|
||||
"""
|
||||
@ -1014,8 +998,8 @@ class Router(BaseVM):
|
||||
if slot is not None:
|
||||
current_adapter = slot
|
||||
raise DynamipsError('Slot {slot_number} is already occupied by adapter {adapter} on router "{name}"'.format(name=self._name,
|
||||
slot_number=slot_number,
|
||||
adapter=current_adapter))
|
||||
slot_number=slot_number,
|
||||
adapter=current_adapter))
|
||||
|
||||
is_running = yield from self.is_running()
|
||||
|
||||
@ -1081,16 +1065,16 @@ class Router(BaseVM):
|
||||
slot_number=slot_number))
|
||||
|
||||
log.info('Router "{name}" [{id}]: OIR stop event sent to slot {slot_number}'.format(name=self._name,
|
||||
id=self._id,
|
||||
slot_number=slot_number))
|
||||
id=self._id,
|
||||
slot_number=slot_number))
|
||||
|
||||
yield from self._hypervisor.send('vm slot_remove_binding "{name}" {slot_number} 0'.format(name=self._name,
|
||||
slot_number=slot_number))
|
||||
|
||||
log.info('Router "{name}" [{id}]: adapter {adapter} removed from slot {slot_number}'.format(name=self._name,
|
||||
id=self._id,
|
||||
adapter=adapter,
|
||||
slot_number=slot_number))
|
||||
id=self._id,
|
||||
adapter=adapter,
|
||||
slot_number=slot_number))
|
||||
self._slots[slot_number] = None
|
||||
|
||||
@asyncio.coroutine
|
||||
@ -1119,14 +1103,14 @@ class Router(BaseVM):
|
||||
# WIC1 = 16, WIC2 = 32 and WIC3 = 48
|
||||
internal_wic_slot_number = 16 * (wic_slot_number + 1)
|
||||
yield from self._hypervisor.send('vm slot_add_binding "{name}" {slot_number} {wic_slot_number} {wic}'.format(name=self._name,
|
||||
slot_number=slot_number,
|
||||
wic_slot_number=internal_wic_slot_number,
|
||||
wic=wic))
|
||||
slot_number=slot_number,
|
||||
wic_slot_number=internal_wic_slot_number,
|
||||
wic=wic))
|
||||
|
||||
log.info('Router "{name}" [{id}]: {wic} inserted into WIC slot {wic_slot_number}'.format(name=self._name,
|
||||
id=self._id,
|
||||
wic=wic,
|
||||
wic_slot_number=wic_slot_number))
|
||||
id=self._id,
|
||||
wic=wic,
|
||||
wic_slot_number=wic_slot_number))
|
||||
|
||||
adapter.install_wic(wic_slot_number, wic)
|
||||
|
||||
@ -1496,7 +1480,7 @@ class Router(BaseVM):
|
||||
try:
|
||||
reply = yield from self._hypervisor.send("vm extract_config {}".format(self._name))
|
||||
except DynamipsError:
|
||||
#for some reason Dynamips gets frozen when it does not find the magic number in the NVRAM file.
|
||||
# for some reason Dynamips gets frozen when it does not find the magic number in the NVRAM file.
|
||||
return None, None
|
||||
reply = reply[0].rsplit(' ', 2)[-2:]
|
||||
startup_config = reply[0][1:-1] # get statup-config and remove single quotes
|
||||
|
@ -77,9 +77,8 @@ class IOUVM(BaseVM):
|
||||
l1_keepalives=None,
|
||||
initial_config=None):
|
||||
|
||||
super().__init__(name, vm_id, project, manager)
|
||||
super().__init__(name, vm_id, project, manager, console=console)
|
||||
|
||||
self._console = console
|
||||
self._command = []
|
||||
self._iouyap_process = None
|
||||
self._iou_process = None
|
||||
@ -103,11 +102,6 @@ class IOUVM(BaseVM):
|
||||
if initial_config is not None:
|
||||
self.initial_config = initial_config
|
||||
|
||||
if self._console is not None:
|
||||
self._console = self._manager.port_manager.reserve_console_port(self._console)
|
||||
else:
|
||||
self._console = self._manager.port_manager.get_free_console_port()
|
||||
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
|
||||
@ -226,30 +220,6 @@ class IOUVM(BaseVM):
|
||||
|
||||
return self._manager.config.get_section_config("IOU").get("iourc_path")
|
||||
|
||||
@property
|
||||
def console(self):
|
||||
"""
|
||||
Returns the console port of this IOU vm.
|
||||
|
||||
:returns: console port
|
||||
"""
|
||||
|
||||
return self._console
|
||||
|
||||
@console.setter
|
||||
def console(self, console):
|
||||
"""
|
||||
Change console port
|
||||
|
||||
:params console: Console port (integer)
|
||||
"""
|
||||
|
||||
if console == self._console:
|
||||
return
|
||||
if self._console:
|
||||
self._manager.port_manager.release_console_port(self._console)
|
||||
self._console = self._manager.port_manager.reserve_console_port(console)
|
||||
|
||||
@property
|
||||
def ram(self):
|
||||
"""
|
||||
|
1190
gns3server/modules/qemu/qemu_vm.py
Normal file
1190
gns3server/modules/qemu/qemu_vm.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -60,7 +60,6 @@ class VirtualBoxVM(BaseVM):
|
||||
self._closed = False
|
||||
|
||||
# VirtualBox settings
|
||||
self._console = None
|
||||
self._adapters = adapters
|
||||
self._ethernet_adapters = []
|
||||
self._headless = False
|
||||
@ -69,11 +68,6 @@ class VirtualBoxVM(BaseVM):
|
||||
self._use_any_adapter = False
|
||||
self._adapter_type = "Intel PRO/1000 MT Desktop (82540EM)"
|
||||
|
||||
if self._console is not None:
|
||||
self._console = self._manager.port_manager.reserve_console_port(self._console)
|
||||
else:
|
||||
self._console = self._manager.port_manager.get_free_console_port()
|
||||
|
||||
def __json__(self):
|
||||
|
||||
return {"name": self.name,
|
||||
@ -253,32 +247,6 @@ class VirtualBoxVM(BaseVM):
|
||||
log.info("VirtualBox VM '{name}' [{id}] reloaded".format(name=self.name, id=self.id))
|
||||
log.debug("Reload result: {}".format(result))
|
||||
|
||||
@property
|
||||
def console(self):
|
||||
"""
|
||||
Returns the TCP console port.
|
||||
|
||||
:returns: console port (integer)
|
||||
"""
|
||||
|
||||
return self._console
|
||||
|
||||
@console.setter
|
||||
def console(self, console):
|
||||
"""
|
||||
Sets the TCP console port.
|
||||
|
||||
:param console: console port (integer)
|
||||
"""
|
||||
|
||||
if self._console:
|
||||
self._manager.port_manager.release_console_port(self._console)
|
||||
|
||||
self._console = self._manager.port_manager.reserve_console_port(console)
|
||||
log.info("VirtualBox VM '{name}' [{id}]: console port set to {port}".format(name=self.name,
|
||||
id=self.id,
|
||||
port=console))
|
||||
|
||||
@asyncio.coroutine
|
||||
def _get_all_hdd_files(self):
|
||||
|
||||
|
@ -55,9 +55,8 @@ class VPCSVM(BaseVM):
|
||||
|
||||
def __init__(self, name, vm_id, project, manager, console=None, startup_script=None):
|
||||
|
||||
super().__init__(name, vm_id, project, manager)
|
||||
super().__init__(name, vm_id, project, manager, console=console)
|
||||
|
||||
self._console = console
|
||||
self._command = []
|
||||
self._process = None
|
||||
self._vpcs_stdout_file = ""
|
||||
@ -68,11 +67,6 @@ class VPCSVM(BaseVM):
|
||||
self.startup_script = startup_script
|
||||
self._ethernet_adapter = EthernetAdapter() # one adapter with 1 Ethernet interface
|
||||
|
||||
if self._console is not None:
|
||||
self._console = self._manager.port_manager.reserve_console_port(self._console)
|
||||
else:
|
||||
self._console = self._manager.port_manager.get_free_console_port()
|
||||
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
|
||||
@ -119,30 +113,6 @@ class VPCSVM(BaseVM):
|
||||
path = shutil.which("vpcs")
|
||||
return path
|
||||
|
||||
@property
|
||||
def console(self):
|
||||
"""
|
||||
Returns the console port of this VPCS vm.
|
||||
|
||||
:returns: console port
|
||||
"""
|
||||
|
||||
return self._console
|
||||
|
||||
@console.setter
|
||||
def console(self, console):
|
||||
"""
|
||||
Change console port
|
||||
|
||||
:params console: Console port (integer)
|
||||
"""
|
||||
|
||||
if console == self._console:
|
||||
return
|
||||
if self._console:
|
||||
self._manager.port_manager.release_console_port(self._console)
|
||||
self._console = self._manager.port_manager.reserve_console_port(console)
|
||||
|
||||
@BaseVM.name.setter
|
||||
def name(self, new_name):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user