當前位置: 首頁>>代碼示例>>Python>>正文


Python VMware.write_vmx_file方法代碼示例

本文整理匯總了Python中gns3server.compute.vmware.VMware.write_vmx_file方法的典型用法代碼示例。如果您正苦於以下問題:Python VMware.write_vmx_file方法的具體用法?Python VMware.write_vmx_file怎麽用?Python VMware.write_vmx_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gns3server.compute.vmware.VMware的用法示例。


在下文中一共展示了VMware.write_vmx_file方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _set_vcpus_ram

# 需要導入模塊: from gns3server.compute.vmware import VMware [as 別名]
# 或者: from gns3server.compute.vmware.VMware import write_vmx_file [as 別名]
    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))
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:30,代碼來源:vmware_gns3_vm.py

示例2: _set_extra_options

# 需要導入模塊: from gns3server.compute.vmware import VMware [as 別名]
# 或者: from gns3server.compute.vmware.VMware import write_vmx_file [as 別名]
    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))
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:24,代碼來源:vmware_gns3_vm.py


注:本文中的gns3server.compute.vmware.VMware.write_vmx_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。