VMware Cloud Community
NGraham
Contributor
Contributor

Setting a VM disk to nonpersistent

I have a VM with two disks, and I'd like to set the system disk to be non-persistent after it's finished being customized. What's the best way to do this in a script? I've found System.getModule("com.vmware.library.vc.vm").setDiskToNonPersitent(vm), but that changes all the disks, when I just want to change one of them.

Tags (1)
0 Kudos
3 Replies
tschoergez
Leadership
Leadership

HAve a look at the code of this action.

It does a simple loop through all the devices of a VM, figures out it the device is a disk, and then changes it.

You can duplicate this action, and put in some additional "filter" logic to only change the disks that you want.

How can you identify the "system" disk?

Is it always the first disk of the VM? (then you might just break the loop after the first found disk. But do extensive testing, not sure if the order is that deterministic)

Or does the disk has a certain defined name in the VM configuration? ( then you can add filter logic by getting the device name)

Joerg

NGraham
Contributor
Contributor

Thanks for the info! I actually had no idea you could view the code of those actions until now. The system disk is always first, so that sounds like a good solution. I'll test a couple times using that methodology and then update here if it works properly.

0 Kudos
NGraham
Contributor
Contributor

It took me a while to get around to trying this, but it looks like this action actually doesn't do anything. Originally I tried editing it like you suggested and it had no effect, but then I just tried running the factory version and it has no effect either. It runs some sort of reconfigure task that shows up in the vcenter task list, but the disk independence/persistence remains the same.

0 Kudos