mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Finish support of VMware based GNS3 VM.
This commit is contained in:
1 parent
45af721164
commit
225e4f7528
3 files changed
+30
-3
No files matched your search
@@ -15,10 +15,13 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from .gns3_vm_error import GNS3VMError
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import asyncio
|
||||
import psutil
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -43,6 +46,16 @@ class BaseGNS3VM:
|
||||
else:
|
||||
config_path = os.path.join(os.path.expanduser("~"), ".config", "GNS3")
|
||||
self._config_file = os.path.join(config_path, "gns3_vm.conf")
|
||||
|
||||
# limit the number of vCPUs to the number of physical cores (hyper thread CPUs are excluded)
|
||||
# because this is likely to degrade performances.
|
||||
self._vcpus = psutil.cpu_count(logical=False)
|
||||
# we want to allocate half of the available physical memory
|
||||
ram = int(psutil.virtual_memory().total / (1024 * 1024) / 2)
|
||||
# value must be a multiple of 4 (VMware requirement)
|
||||
ram -= ram % 4
|
||||
self._ram = ram
|
||||
|
||||
self.load()
|
||||
|
||||
def __json__(self):
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import os
|
||||
import logging
|
||||
import asyncio
|
||||
import psutil
|
||||
|
||||
from gns3server.compute.vmware import (
|
||||
VMware,
|
||||
@@ -56,6 +57,18 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
:param ram: amount of RAM
|
||||
"""
|
||||
|
||||
available_ram = int(psutil.virtual_memory().available / (1024 * 1024))
|
||||
if ram > available_ram:
|
||||
raise GNS3VMError("You have allocated too much memory for the GNS3 VM! (available memory is {} MB)".format(available_ram))
|
||||
|
||||
# memory must be a multiple of 4 (VMware requirement)
|
||||
if ram % 4 != 0:
|
||||
raise GNS3VMError("Allocated memory for the GNS3 VM must be a multiple of 4".format(available_ram))
|
||||
|
||||
available_vcpus = psutil.cpu_count(logical=False)
|
||||
if vcpus > available_vcpus:
|
||||
raise GNS3VMError("You have allocated too many vCPUs for the GNS3 VM! (max available is {} vCPUs)".format(available_vcpus))
|
||||
|
||||
try:
|
||||
pairs = VMware.parse_vmware_file(self._vmx_path)
|
||||
pairs["numvcpus"] = str(vcpus)
|
||||
@@ -91,8 +104,8 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
if not os.path.exists(self._vmx_path):
|
||||
raise GNS3VMError("VMware VMX file {} doesn't exist".format(self._vmx_path))
|
||||
|
||||
# set the number of vCPUs and amount of RAM # FIXME
|
||||
# yield from self._set_vcpus_ram(self.vcpus, self.ram)
|
||||
# set the number of vCPUs and amount of RAM
|
||||
yield from self._set_vcpus_ram(self.vcpus, self.ram)
|
||||
|
||||
# start the VM
|
||||
args = [self._vmx_path]
|
||||
|
||||
Reference in new issue
Block a user