Hi, I want to extend the size of a virtual disk file automatically, but I'm running into a Exception. My system is running vCenter 4 and vSphere 4.
I don't know if the following code is correct. Any solution?
public bool ExpandDiskSize(string vmname, int diskNumber, int diskSize)
{
NameValueCollection filter = new NameValueCollection();
filter.Add("Summary.vm", vmname);
VMware.Vim.VirtualMachine vm = (VMware.Vim.VirtualMachine)client.FindEntityView(typeof(VMware.Vim.VirtualMachine), null, filter, null);
try
{
NameValueCollection nvc = new NameValueCollection();
nvc.Add("name", "Boeblingen");
VMware.Vim.Datacenter dc = (VMware.Vim.Datacenter)client.FindEntityView(typeof(VMware.Vim.Datacenter), null, nvc, null);
VirtualDiskManager vdm = new VirtualDiskManager(client, new ManagedObjectReference());
vdm.ExtendVirtualDisk_Task(vm.Layout.Disk[diskNumber].DiskFile[0].ToString(), dc.MoRef, diskSize *1024 * 1024, false);
return true;
}
catch (Exception ex)
{
Logger.Instance.WriteLog(LoggingLevel.ERROR, ex.Message);
return false;
}
}
Thanks for your help!