Merge branch '2.2' into 3.0

# Conflicts:
#	gns3server/controller/__init__.py
#	gns3server/controller/compute.py
#	gns3server/schemas/gns3vm.py
#	gns3server/utils/application_id.py
#	gns3server/version.py
#	gns3server/web/web_server.py
This commit is contained in:
grossmj committed 2020-11-05 17:15:25 +10:30
commit a5d89b428a
29 files changed
+206 -85

No files matched your search

+4 -4
View File
@@ -268,7 +268,7 @@ class Controller:
"""
server_config = Config.instance().get_section_config("Server")
images_path = os.path.expanduser(server_config.get("images_path", "~/GNS3/projects"))
images_path = os.path.expanduser(server_config.get("images_path", "~/GNS3/images"))
os.makedirs(images_path, exist_ok=True)
return images_path
@@ -278,9 +278,9 @@ class Controller:
"""
server_config = Config.instance().get_section_config("Server")
images_path = os.path.expanduser(server_config.get("configs_path", "~/GNS3/projects"))
os.makedirs(images_path, exist_ok=True)
return images_path
configs_path = os.path.expanduser(server_config.get("configs_path", "~/GNS3/configs"))
os.makedirs(configs_path, exist_ok=True)
return configs_path
async def add_compute(self, compute_id=None, name=None, force=False, connect=True, **kwargs):
"""
+1 -1
View File
@@ -71,7 +71,7 @@ class ApplianceManager:
"""
server_config = Config.instance().get_section_config("Server")
appliances_path = os.path.expanduser(server_config.get("appliances_path", "~/GNS3/projects"))
appliances_path = os.path.expanduser(server_config.get("appliances_path", "~/GNS3/appliances"))
os.makedirs(appliances_path, exist_ok=True)
return appliances_path
+4 -3
View File
@@ -64,8 +64,8 @@ class Compute:
A GNS3 compute.
"""
def __init__(self, compute_id, controller=None, protocol="http", host="localhost", port=3080, user=None,
password=None, name=None, console_host=None):
def __init__(self, compute_id, controller=None, protocol="http", host="localhost",
port=3080, user=None, password=None, name=None, console_host=None, ssl_context=None):
self._http_session = None
assert controller is not None
log.info("Create compute %s", compute_id)
@@ -90,6 +90,7 @@ class Compute:
self._memory_usage_percent = 0
self._disk_usage_percent = 0
self._last_error = None
self._ssl_context = ssl_context
self._capabilities = {
"version": "",
"platform": "",
@@ -105,7 +106,7 @@ class Compute:
def _session(self):
if self._http_session is None or self._http_session.closed is True:
connector = aiohttp.TCPConnector(force_close=True)
connector = aiohttp.TCPConnector(force_close=True, ssl_context=self._ssl_context)
self._http_session = aiohttp.ClientSession(connector=connector)
return self._http_session
+2
View File
@@ -49,6 +49,7 @@ class GNS3VM:
"headless": False,
"enable": False,
"engine": "vmware",
"allocate_vcpus_ram": True,
"ram": 2048,
"vcpus": 1,
"port": 80,
@@ -311,6 +312,7 @@ class GNS3VM:
if self._settings["vmname"] is None:
return
log.info("Start the GNS3 VM")
engine.allocate_vcpus_ram = self._settings["allocate_vcpus_ram"]
engine.vmname = self._settings["vmname"]
engine.ram = self._settings["ram"]
engine.vcpus = self._settings["vcpus"]
@@ -30,6 +30,7 @@ class BaseGNS3VM:
self._ip_address = None
self._port = 80 # value not used, will be overwritten
self._headless = False
self._allocate_vcpus_ram = True
self._vcpus = 1
self._ram = 1024
self._user = ""
@@ -203,6 +204,26 @@ class BaseGNS3VM:
self._headless = value
@property
def allocate_vcpus_ram(self):
"""
Returns whether VCPUs and RAM settings should be configured for the GNS3 VM.
:returns: boolean
"""
return self._allocate_vcpus_ram
@allocate_vcpus_ram.setter
def allocate_vcpus_ram(self, value):
"""
Sets whether VCPUs and RAM settings should be configured for the GNS3 VM.
:param value: boolean
"""
self._allocate_vcpus_ram = value
@property
def vcpus(self):
"""
@@ -251,9 +251,10 @@ class HyperVGNS3VM(BaseGNS3VM):
raise GNS3VMError("Could not find Hyper-V VM {}".format(self.vmname))
if not self._is_running():
log.info("Update GNS3 VM settings (CPU and RAM)")
# set the number of vCPUs and amount of RAM
self._set_vcpus_ram(self.vcpus, self.ram)
if self.allocate_vcpus_ram:
log.info("Update GNS3 VM settings (CPU and RAM)")
# set the number of vCPUs and amount of RAM
self._set_vcpus_ram(self.vcpus, self.ram)
# start the VM
try:
@@ -15,8 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import asyncio
from .base_gns3_vm import BaseGNS3VM
from .gns3_vm_error import GNS3VMError
@@ -260,9 +260,12 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
log.info('"{}" state is {}'.format(self._vmname, vm_state))
if vm_state == "poweroff":
log.info("Update GNS3 VM settings (CPU, RAM and Hardware Virtualization)")
await self.set_vcpus(self.vcpus)
await self.set_ram(self.ram)
if self.allocate_vcpus_ram:
log.info("Update GNS3 VM vCPUs and RAM settings")
await self.set_vcpus(self.vcpus)
await self.set_ram(self.ram)
log.info("Update GNS3 VM Hardware Virtualization setting")
await self.enable_nested_hw_virt()
if vm_state in ("poweroff", "saved"):
@@ -148,9 +148,12 @@ class VMwareGNS3VM(BaseGNS3VM):
except VMwareError as e:
raise GNS3VMError("Could not list VMware VMs: {}".format(str(e)))
if not running:
log.info("Update GNS3 VM settings (CPU, RAM and Hardware Virtualization)")
# set the number of vCPUs and amount of RAM
await self._set_vcpus_ram(self.vcpus, self.ram)
if self.allocate_vcpus_ram:
log.info("Update GNS3 VM vCPUs and RAM settings")
await self._set_vcpus_ram(self.vcpus, self.ram)
log.info("Update GNS3 VM Hardware Virtualization setting")
await self._set_extra_options()
# start the VM
+16 -2
View File
@@ -174,6 +174,7 @@ class Project:
self._links = {}
self._drawings = {}
self._snapshots = {}
self._computes = []
# List the available snapshots
snapshot_dir = os.path.join(self.path, "snapshots")
@@ -564,6 +565,9 @@ class Project:
if node_id in self._nodes:
return self._nodes[node_id]
if compute.id not in self._computes:
self._computes.append(compute.id)
if node_type == "iou":
async with self._iou_id_lock:
# wait for a IOU node to be completely created before adding a new one
@@ -571,10 +575,10 @@ class Project:
# to generate MAC addresses) when creating multiple IOU node at the same time
if "properties" in kwargs.keys():
# allocate a new application id for nodes loaded from the project
kwargs.get("properties")["application_id"] = get_next_application_id(self._controller.projects, compute)
kwargs.get("properties")["application_id"] = get_next_application_id(self._controller.projects, self._computes)
elif "application_id" not in kwargs.keys() and not kwargs.get("properties"):
# allocate a new application id for nodes added to the project
kwargs["application_id"] = get_next_application_id(self._controller.projects, compute)
kwargs["application_id"] = get_next_application_id(self._controller.projects, self._computes)
node = await self._create_node(compute, name, node_id, node_type, **kwargs)
else:
node = await self._create_node(compute, name, node_id, node_type, **kwargs)
@@ -604,6 +608,8 @@ class Project:
self.remove_allocated_node_name(node.name)
del self._nodes[node.id]
await node.destroy()
# refresh the compute IDs list
self._computes = [n.compute.id for n in self.nodes.values()]
self.dump()
self.emit_notification("node.deleted", node.__json__())
@@ -931,6 +937,14 @@ class Project:
topology = project_data["topology"]
for compute in topology.get("computes", []):
await self.controller.add_compute(**compute)
# Get all compute used in the project
# used to allocate application IDs for IOU nodes.
for node in topology.get("nodes", []):
compute_id = node.get("compute_id")
if compute_id not in self._computes:
self._computes.append(compute_id)
for node in topology.get("nodes", []):
compute = self.controller.get_compute(node.pop("compute_id"))
name = node.pop("name")