Skip to content

Instantly share code, notes, and snippets.

@hartsock
Created April 17, 2017 19:28
Show Gist options
  • Save hartsock/09050712ab0a09feeb02912b5d6bc4cd to your computer and use it in GitHub Desktop.
Save hartsock/09050712ab0a09feeb02912b5d6bc4cd to your computer and use it in GitHub Desktop.
adding a disk code sketch
from pyVmomi import vim
spec = vim.vm.device.VirtualDiskSpec()
spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
spec.fileOperation = vim.vm.device.VirtualDeviceSpec.FileOperation.create
spec.device = vim.vm.device.VirtualDisk(
capacityInBytes=capacity_bytes,
capacityInKB = capacity_kb,
connectable = vim.vm.device.VirtualDevice.ConnectInfo(
startConnected = True,
connected = True
),
backing = vim.vm.device.VirtualDisk.FlatVer2BackingInfo(
thinProvisioned = True,
diskMode = vim.vm.device.VirtualDiskOption.DiskMode.persistent,
fileName = disk_conf.path,
)
)
spec.device.key = device_key # calculate or look up some how
spec.device.controllerKey = key # calculate or look up some how
spec.device.unitNumber = unit # calculate or look up some how
spec_list = [spec]
reconfig_spec = vim.vm.ConfigSpec(name=vm_name, deviceChange=spec_list)
vm.ReconfigVM_Task(spec=reconfig_spec)
#SEE also:
# https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/add_disk_to_vm.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment