本文整理匯總了Python中gns3server.compute.vmware.VMware.parse_vmware_file方法的典型用法代碼示例。如果您正苦於以下問題:Python VMware.parse_vmware_file方法的具體用法?Python VMware.parse_vmware_file怎麽用?Python VMware.parse_vmware_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gns3server.compute.vmware.VMware
的用法示例。
在下文中一共展示了VMware.parse_vmware_file方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _set_vcpus_ram
# 需要導入模塊: from gns3server.compute.vmware import VMware [as 別名]
# 或者: from gns3server.compute.vmware.VMware import parse_vmware_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))
示例2: test_parse_vmware_file
# 需要導入模塊: from gns3server.compute.vmware import VMware [as 別名]
# 或者: from gns3server.compute.vmware.VMware import parse_vmware_file [as 別名]
def test_parse_vmware_file(manager, tmpdir):
path = str(tmpdir / "test.vmx")
with open(path, "w+") as f:
f.write('displayname = "GNS3 VM"\nguestOS = "ubuntu-64"')
vmx = VMware.parse_vmware_file(path)
assert vmx["displayname"] == "GNS3 VM"
assert vmx["guestos"] == "ubuntu-64"
示例3: _set_extra_options
# 需要導入模塊: from gns3server.compute.vmware import VMware [as 別名]
# 或者: from gns3server.compute.vmware.VMware import parse_vmware_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))