def change_disk_mode(si, vm_obj, disk_number, mode, disk_prefix_label='Hard disk '):
 disk_label = (disk_prefix_label + str(disk_number))
 virtual_disk_device = None
 for dev in vm_obj.config.hardware.device:
  if (isinstance(dev, vim.vm.device.VirtualDisk) and (dev.deviceInfo.label == disk_label)):
   virtual_disk_device = dev
 if (not virtual_disk_device):
  raise RuntimeError('Virtual {} could not be found.'.format(disk_label))
 virtual_disk_spec = vim.vm.device.VirtualDeviceSpec()
 virtual_disk_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit
 virtual_disk_spec.device = virtual_disk_device
 virtual_disk_spec.device.backing.diskMode = mode
 dev_changes = []
 dev_changes.append(virtual_disk_spec)
 spec = vim.vm.ConfigSpec()
 spec.deviceChange = dev_changes
 task = vm_obj.ReconfigVM_Task(spec=spec)
 tasks.wait_for_tasks(si, [task])
 return True

def change_disk_mode ( si , vm_obj , disk_number , mode , disk_prefix_label = 'Hard disk ' ) : disk_label = ( disk_prefix_label + str ( disk_number ) ) virtual_disk_device = None for dev in vm_obj . config . hardware . device : if ( isinstance ( dev , vim . vm . device . VirtualDisk ) and ( dev . deviceInfo . label == disk_label ) ) : virtual_disk_device = dev if ( not virtual_disk_device ) : raise RuntimeError ( 'Virtual {} could not be found.' . format ( disk_label ) ) virtual_disk_spec = vim . vm . device . VirtualDeviceSpec ( ) virtual_disk_spec . operation = vim . vm . device . VirtualDeviceSpec . Operation . edit virtual_disk_spec . device = virtual_disk_device virtual_disk_spec . device . backing . diskMode = mode dev_changes = [ ] dev_changes . append ( virtual_disk_spec ) spec = vim . vm . ConfigSpec ( ) spec . deviceChange = dev_changes task = vm_obj . ReconfigVM_Task ( spec = spec ) tasks . wait_for_tasks ( si , [ task ] ) return True
change the disk mode on a virtual hard disk .