我研究了Vsphere https://github.com/vmware/vsphere-automation-sdk-python,以找到示例来扩展vCenter中现有的VM磁盘。似乎没有办法修改现有的磁盘,我们只能删除一个现有的磁盘并添加一个新的磁盘。
那么,我们是否可以使用python来执行这个任务呢?任何样品都非常感谢。
谢谢,
发布于 2022-06-28 10:10:17
我最终使用了pyvmomi提供的SOAP来扩展磁盘。
def extend_disk(client, vm, size, disk_number):
disk_label = 'Hard disk '+disk_number
disk_size = int(size) * 1024 * 1024 * 1024
disk = None
for device in vm.config.hardware.device:
if hasattr(device.backing, 'fileName'):
if device.deviceInfo.label == disk_label:
disk = device
break
if disk:
if disk.capacityInBytes >= disk_size:
return 1
else:
disk.capacityInBytes = disk_size
updated_spec = vim.vm.device.VirtualDeviceSpec(device=disk, operation="edit")
spec = vim.vm.ConfigSpec()
spec.deviceChange.append(updated_spec)
WaitForTask(vm.Reconfigure(spec))
return 0
else:
return 1https://stackoverflow.com/questions/72717521
复制相似问题