mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Improve server/modules termination and how to wait for an hypervisor.
connection. System to avoid duplicated name for nodes. Reload and idle-pc support for Dynamips routers. Hypervisor allocation for other Dynamips devices.
This commit is contained in:
1 parent
df798f4bea
commit
72d303069c
16 files changed
+257
-56
No files matched your search
@@ -35,6 +35,7 @@ class ATMSwitch(object):
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
_allocated_names = []
|
||||
_instance_count = 1
|
||||
|
||||
def __init__(self, hypervisor, name=None):
|
||||
@@ -45,8 +46,15 @@ class ATMSwitch(object):
|
||||
|
||||
# let's create a unique name if none has been chosen
|
||||
if not name:
|
||||
name = "ATM" + str(self._id)
|
||||
name_id = self._id
|
||||
while True:
|
||||
name = "ATM" + str(name_id)
|
||||
# check if the name has already been allocated to another switch
|
||||
if name not in self._allocated_names:
|
||||
break
|
||||
name_id += 1
|
||||
|
||||
self._allocated_names.append(name)
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("atmsw create {}".format(self._name))
|
||||
@@ -61,10 +69,11 @@ class ATMSwitch(object):
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
"""
|
||||
Reset the instance count.
|
||||
Resets the instance count and the allocated names list.
|
||||
"""
|
||||
|
||||
cls._instance_count = 1
|
||||
cls._allocated_names.clear()
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
@@ -94,6 +103,7 @@ class ATMSwitch(object):
|
||||
:param new_name: New name for this switch
|
||||
"""
|
||||
|
||||
new_name_no_quotes = new_name
|
||||
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
|
||||
self._hypervisor.send("atmsw rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
@@ -102,7 +112,9 @@ class ATMSwitch(object):
|
||||
id=self._id,
|
||||
new_name=new_name))
|
||||
|
||||
self._allocated_names.remove(self.name)
|
||||
self._name = new_name
|
||||
self._allocated_names.append(new_name_no_quotes)
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
@@ -153,6 +165,7 @@ class ATMSwitch(object):
|
||||
log.info("ATM switch {name} [id={id}] has been deleted".format(name=self._name,
|
||||
id=self._id))
|
||||
self._hypervisor.devices.remove(self)
|
||||
self._allocated_names.remove(self.name)
|
||||
|
||||
def has_port(self, port):
|
||||
"""
|
||||
|
||||
@@ -31,6 +31,8 @@ class Bridge(object):
|
||||
:param name: name for this bridge
|
||||
"""
|
||||
|
||||
_allocated_names = []
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
@@ -57,11 +59,14 @@ class Bridge(object):
|
||||
:param new_name: New name for this bridge
|
||||
"""
|
||||
|
||||
new_name_no_quotes = new_name
|
||||
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
|
||||
self._hypervisor.send("nio_bridge rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
|
||||
self._allocated_names.remove(self.name)
|
||||
self._name = new_name
|
||||
self._allocated_names.append(new_name_no_quotes)
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
@@ -99,6 +104,7 @@ class Bridge(object):
|
||||
|
||||
self._hypervisor.send("nio_bridge delete {}".format(self._name))
|
||||
self._hypervisor.devices.remove(self)
|
||||
self._allocated_names.remove(self.name)
|
||||
|
||||
def add_nio(self, nio):
|
||||
"""
|
||||
|
||||
@@ -44,16 +44,16 @@ class C2600(Router):
|
||||
|
||||
# adapters to insert by default corresponding the
|
||||
# chosen chassis.
|
||||
integrated_adapters = {'2610': C2600_MB_1E,
|
||||
'2611': C2600_MB_2E,
|
||||
'2620': C2600_MB_1FE,
|
||||
'2621': C2600_MB_2FE,
|
||||
'2610XM': C2600_MB_1FE,
|
||||
'2611XM': C2600_MB_2FE,
|
||||
'2620XM': C2600_MB_1FE,
|
||||
'2621XM': C2600_MB_2FE,
|
||||
'2650XM': C2600_MB_1FE,
|
||||
'2651XM': C2600_MB_2FE}
|
||||
integrated_adapters = {"2610": C2600_MB_1E,
|
||||
"2611": C2600_MB_2E,
|
||||
"2620": C2600_MB_1FE,
|
||||
"2621": C2600_MB_2FE,
|
||||
"2610XM": C2600_MB_1FE,
|
||||
"2611XM": C2600_MB_2FE,
|
||||
"2620XM": C2600_MB_1FE,
|
||||
"2621XM": C2600_MB_2FE,
|
||||
"2650XM": C2600_MB_1FE,
|
||||
"2651XM": C2600_MB_2FE}
|
||||
|
||||
def __init__(self, hypervisor, name=None, chassis="2610"):
|
||||
Router.__init__(self, hypervisor, name, platform="c2600")
|
||||
|
||||
@@ -36,6 +36,7 @@ class EthernetSwitch(object):
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
_allocated_names = []
|
||||
_instance_count = 1
|
||||
|
||||
def __init__(self, hypervisor, name=None):
|
||||
@@ -46,8 +47,15 @@ class EthernetSwitch(object):
|
||||
|
||||
# let's create a unique name if none has been chosen
|
||||
if not name:
|
||||
name = "SW" + str(self._id)
|
||||
name_id = self._id
|
||||
while True:
|
||||
name = "SW" + str(name_id)
|
||||
# check if the name has already been allocated to another switch
|
||||
if name not in self._allocated_names:
|
||||
break
|
||||
name_id += 1
|
||||
|
||||
self._allocated_names.append(name)
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("ethsw create {}".format(self._name))
|
||||
@@ -62,10 +70,11 @@ class EthernetSwitch(object):
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
"""
|
||||
Reset the instance count.
|
||||
Resets the instance count and the allocated names list.
|
||||
"""
|
||||
|
||||
cls._instance_count = 1
|
||||
cls._allocated_names.clear()
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
@@ -95,6 +104,7 @@ class EthernetSwitch(object):
|
||||
:param new_name: New name for this switch
|
||||
"""
|
||||
|
||||
new_name_no_quotes = new_name
|
||||
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
|
||||
self._hypervisor.send("ethsw rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
@@ -103,7 +113,9 @@ class EthernetSwitch(object):
|
||||
id=self._id,
|
||||
new_name=new_name))
|
||||
|
||||
self._allocated_names.remove(self.name)
|
||||
self._name = new_name
|
||||
self._allocated_names.append(new_name_no_quotes)
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
@@ -154,6 +166,7 @@ class EthernetSwitch(object):
|
||||
log.info("Ethernet switch {name} [id={id}] has been deleted".format(name=self._name,
|
||||
id=self._id))
|
||||
self._hypervisor.devices.remove(self)
|
||||
self._allocated_names.remove(self.name)
|
||||
|
||||
def add_nio(self, nio, port):
|
||||
"""
|
||||
|
||||
@@ -35,6 +35,7 @@ class FrameRelaySwitch(object):
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
_allocated_names = []
|
||||
_instance_count = 1
|
||||
|
||||
def __init__(self, hypervisor, name=None):
|
||||
@@ -45,8 +46,15 @@ class FrameRelaySwitch(object):
|
||||
|
||||
# let's create a unique name if none has been chosen
|
||||
if not name:
|
||||
name = "FR" + str(self._id)
|
||||
name_id = self._id
|
||||
while True:
|
||||
name = "FR" + str(name_id)
|
||||
# check if the name has already been allocated to another switch
|
||||
if name not in self._allocated_names:
|
||||
break
|
||||
name_id += 1
|
||||
|
||||
self._allocated_names.append(name)
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("frsw create {}".format(self._name))
|
||||
@@ -61,10 +69,11 @@ class FrameRelaySwitch(object):
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
"""
|
||||
Reset the instance count.
|
||||
Resets the instance count and the allocated names list.
|
||||
"""
|
||||
|
||||
cls._instance_count = 1
|
||||
cls._allocated_names.clear()
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
@@ -94,6 +103,7 @@ class FrameRelaySwitch(object):
|
||||
:param new_name: New name for this switch
|
||||
"""
|
||||
|
||||
new_name_no_quotes = new_name
|
||||
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
|
||||
self._hypervisor.send("frsw rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
@@ -102,7 +112,9 @@ class FrameRelaySwitch(object):
|
||||
id=self._id,
|
||||
new_name=new_name))
|
||||
|
||||
self._allocated_names.remove(self.name)
|
||||
self._name = new_name
|
||||
self._allocated_names.append(new_name_no_quotes)
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
@@ -153,6 +165,7 @@ class FrameRelaySwitch(object):
|
||||
log.info("Frame Relay switch {name} [id={id}] has been deleted".format(name=self._name,
|
||||
id=self._id))
|
||||
self._hypervisor.devices.remove(self)
|
||||
self._allocated_names.remove(self.name)
|
||||
|
||||
def has_port(self, port):
|
||||
"""
|
||||
|
||||
@@ -45,8 +45,15 @@ class Hub(Bridge):
|
||||
|
||||
# let's create a unique name if none has been chosen
|
||||
if not name:
|
||||
name = "Hub" + str(self._id)
|
||||
name_id = self._id
|
||||
while True:
|
||||
name = "Hub" + str(name_id)
|
||||
# check if the name has already been allocated to another switch
|
||||
if name not in self._allocated_names:
|
||||
break
|
||||
name_id += 1
|
||||
|
||||
self._allocated_names.append(name)
|
||||
self._mapping = {}
|
||||
Bridge.__init__(self, hypervisor, name)
|
||||
|
||||
@@ -56,10 +63,11 @@ class Hub(Bridge):
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
"""
|
||||
Reset the instance count.
|
||||
Resets the instance count and the allocated names list.
|
||||
"""
|
||||
|
||||
cls._instance_count = 1
|
||||
cls._allocated_names.clear()
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
|
||||
@@ -22,6 +22,7 @@ http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L77
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from ..dynamips_error import DynamipsError
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
|
||||
@@ -39,6 +40,7 @@ class Router(object):
|
||||
:param ghost_flag: used when creating a ghost IOS.
|
||||
"""
|
||||
|
||||
_allocated_names = []
|
||||
_instance_count = 1
|
||||
_status = {0: "inactive",
|
||||
1: "shutting down",
|
||||
@@ -53,8 +55,15 @@ class Router(object):
|
||||
|
||||
# let's create a unique name if none has been chosen
|
||||
if not name:
|
||||
name = "R" + str(self._id)
|
||||
name_id = self._id
|
||||
while True:
|
||||
name = "R" + str(name_id)
|
||||
# check if the name has already been allocated to another router
|
||||
if name not in self._allocated_names:
|
||||
break
|
||||
name_id += 1
|
||||
|
||||
self._allocated_names.append(name)
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._platform = platform
|
||||
@@ -106,10 +115,11 @@ class Router(object):
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
"""
|
||||
Reset the instance count.
|
||||
Resets the instance count and the allocated names list.
|
||||
"""
|
||||
|
||||
cls._instance_count = 1
|
||||
cls._allocated_names.clear()
|
||||
|
||||
def defaults(self):
|
||||
"""
|
||||
@@ -179,6 +189,10 @@ class Router(object):
|
||||
:param new_name: new name string
|
||||
"""
|
||||
|
||||
if new_name in self._allocated_names:
|
||||
raise DynamipsError('Name "{}" is already used by another router'.format(new_name))
|
||||
|
||||
new_name_no_quotes = new_name
|
||||
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
|
||||
self._hypervisor.send("vm rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
@@ -187,7 +201,9 @@ class Router(object):
|
||||
id=self._id,
|
||||
new_name=new_name))
|
||||
|
||||
self._allocated_names.remove(self.name)
|
||||
self._name = new_name
|
||||
self._allocated_names.append(new_name_no_quotes)
|
||||
|
||||
@property
|
||||
def platform(self):
|
||||
@@ -237,6 +253,7 @@ class Router(object):
|
||||
self._hypervisor.devices.remove(self)
|
||||
|
||||
log.info("router {name} [id={id}] has been deleted".format(name=self._name, id=self._id))
|
||||
self._allocated_names.remove(self.name)
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
@@ -457,7 +474,7 @@ class Router(object):
|
||||
old_ram=self._ram,
|
||||
new_ram=ram))
|
||||
|
||||
self._hypervisor.decrease_memory_load(self._ram)
|
||||
self._hypervisor.decrease_memory_load(ram)
|
||||
self._ram = ram
|
||||
self._hypervisor.increase_memory_load(self._ram)
|
||||
|
||||
@@ -627,7 +644,17 @@ class Router(object):
|
||||
:returns: list of idle PC proposal
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("vm get_idle_pc_prop {} 0".format(self._name))
|
||||
if not self.is_running():
|
||||
# router is not running
|
||||
raise DynamipsError("router {name} is not running".format(name=self._name))
|
||||
|
||||
log.info("router {name} [id={id}] has started calculating idle-pc values".format(name=self._name, id=self._id))
|
||||
begin = time.time()
|
||||
idlepcs = self._hypervisor.send("vm get_idle_pc_prop {} 0".format(self._name))
|
||||
log.info("router {name} [id={id}] has finished calculating idle-pc values after {time:.4f} seconds".format(name=self._name,
|
||||
id=self._id,
|
||||
time=time.time() - begin))
|
||||
return idlepcs
|
||||
|
||||
def show_idle_pc_prop(self):
|
||||
"""
|
||||
@@ -636,6 +663,10 @@ class Router(object):
|
||||
:returns: list of idle PC proposal
|
||||
"""
|
||||
|
||||
if not self.is_running():
|
||||
# router is not running
|
||||
raise DynamipsError("router {name} is not running".format(name=self._name))
|
||||
|
||||
return self._hypervisor.send("vm show_idle_pc_prop {} 0".format(self._name))
|
||||
|
||||
@property
|
||||
|
||||
Reference in new issue
Block a user