Exemplo n.º 1
0
    async def _set_vcpus_ram(self, vcpus, ram):
        """
        Set the number of vCPU cores and amount of RAM for the GNS3 VM.

        :param vcpus: number of vCPU cores
        :param ram: amount of 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(ram))

        available_vcpus = psutil.cpu_count(logical=True)
        if not float(vcpus).is_integer():
            raise GNS3VMError("The allocated vCPUs value is not an integer: {}".format(vcpus))
        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)
            if vcpus > 1:
                pairs["numvcpus"] = str(vcpus)
                cores_per_sockets = int(vcpus / psutil.cpu_count(logical=False))
                if cores_per_sockets > 1:
                    pairs["cpuid.corespersocket"] = str(cores_per_sockets)
                pairs["memsize"] = str(ram)
                VMware.write_vmx_file(self._vmx_path, pairs)
            log.info("GNS3 VM vCPU count set to {} and RAM amount set to {}".format(vcpus, ram))
        except OSError as e:
            raise GNS3VMError('Could not read/write VMware VMX file "{}": {}'.format(self._vmx_path, e))
Exemplo n.º 2
0
    async def _set_vcpus_ram(self, vcpus, ram):
        """
        Set the number of vCPU cores and amount of RAM for the GNS3 VM.

        :param vcpus: number of vCPU cores
        :param ram: amount of 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(ram))

        available_vcpus = psutil.cpu_count(logical=True)
        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)
            if vcpus > 1:
                pairs["numvcpus"] = str(vcpus)
                cores_per_sockets = int(vcpus / psutil.cpu_count(logical=False))
                if cores_per_sockets > 1:
                    pairs["cpuid.corespersocket"] = str(cores_per_sockets)
                pairs["memsize"] = str(ram)
                VMware.write_vmx_file(self._vmx_path, pairs)
            log.info("GNS3 VM vCPU count set to {} and RAM amount set to {}".format(vcpus, ram))
        except OSError as e:
            raise GNS3VMError('Could not read/write VMware VMX file "{}": {}'.format(self._vmx_path, e))
Exemplo n.º 3
0
    async def _set_extra_options(self):
        try:
            """
            Due to bug/change in VMWare 14 we're not able to pass Hardware Virtualization in GNS3VM.
            We only enable this when it's not present in current configuration and user hasn't deactivated that.
            """
            extra_config = (("vhv.enable", "TRUE"), )
            pairs = VMware.parse_vmware_file(self._vmx_path)
            updated = False
            for key, value in extra_config:
                if key not in pairs.keys():
                    pairs[key] = value
                    updated = True
                    log.info("GNS3 VM VMX `{}` set to `{}`".format(key, value))

            if updated:
                VMware.write_vmx_file(self._vmx_path, pairs)
                log.info("GNS3 VM VMX has been updated.")
        except OSError as e:
            raise GNS3VMError(
                'Could not read/write VMware VMX file "{}": {}'.format(
                    self._vmx_path, e))
Exemplo n.º 4
0
    async def _set_extra_options(self):
        try:
            """
            Due to bug/change in VMWare 14 we're not able to pass Hardware Virtualization in GNS3VM.
            We only enable this when it's not present in current configuration and user hasn't deactivated that.
            """
            extra_config = (
                ("vhv.enable", "TRUE"),
            )
            pairs = VMware.parse_vmware_file(self._vmx_path)
            updated = False
            for key, value in extra_config:
                if key not in pairs.keys():
                    pairs[key] = value
                    updated = True
                    log.info("GNS3 VM VMX `{}` set to `{}`".format(key, value))

            if updated:
                VMware.write_vmx_file(self._vmx_path, pairs)
                log.info("GNS3 VM VMX has been updated.")
        except OSError as e:
            raise GNS3VMError('Could not read/write VMware VMX file "{}": {}'.format(self._vmx_path, e))