VMware Cloud Community
mohd1024
Contributor
Contributor

How to delete or edit a VirtualDisk using c# API?

Hello All,

I am developing an application in c# in which Iam connecting to Virtual Center 2.0 to clone a particular VM multiple times, the cloning process is working correctly, but now I need to delete the VirtualDisk from the resultant clones, I tried the following but it doesn't work, Can any body tell me what am I missing?

// VM is a managedobjectreference to the newly cloned VM

VirtualDeviceConfigSpec VDspec = new VirtualDeviceConfigSpec();

//******************************************************************

PropertySpec pSpec1 = new PropertySpec();

pSpec1.all = false;

pSpec1.type = "VirtualMachine";

pSpec1.pathSet = new String[] { "config.hardware.device" };

ObjectSpec oSpec1 = new ObjectSpec();

oSpec1.obj = VM;

PropertyFilterSpec pfSpec1 = new PropertyFilterSpec();

pfSpec1.objectSet = new ObjectSpec[] ;

pfSpec1.propSet = new PropertySpec[] ;

ObjectContent[http://] objs1 = service.RetrieveProperties(sic.propertyCollector, new PropertyFilterSpec[|http://] objs1 = service.RetrieveProperties(sic.propertyCollector, new PropertyFilterSpec[] );

if (objs1 == null)

return null;

DynamicProperty[] dProps1 = objs1[0].propSet;

VirtualDevice[] devices1 = (VirtualDevice[])dProps1[0].val;

for (int i = 0; i < devices1.Length; i++)

{

if (devices1[i] is VirtualDisk)

VDspec.device = devices1[i];

}

VDspec.fileOperation = VirtualDeviceConfigSpecFileOperation.destroy;

VDspec.operation = VirtualDeviceConfigSpecOperation.remove;

VirtualMachineConfigSpec confSpec = new VirtualMachineConfigSpec();

confSpec.deviceChange = new VirtualDeviceConfigSpec[] ;

service.ReconfigVMTask(VM, confSpec);

0 Kudos
0 Replies