4 Replies Latest reply on Apr 3, 2019 11:21 AM by petermie

    VirtualDisk VDiskId always null

    petermie Enthusiast

      I'm trying to use the VcenterVStorageObjectManager ExtendDisk_Task operation to extend a virtual machine's virtual disk to 30GB, but for the VirtualDisk device it seems that the VDiskId property is always returned as null no matter which VM or disk try it on. I'm not sure why that is, we are running 6.5 on all hosts and VCSA and all VMs are VM version 13. The code seems pretty straightforward if I could figure out why VDiskId doesn't seem to be populating. Does anyone have any ideas? Useful information on using the virtual disk manager seems pretty scarce from what I can find searching


      VcenterVStorageObjectManager vDiskMan = (VcenterVStorageObjectManager)vimClient.GetView(vimClient.ServiceContent.VStorageObjectManager, null);
      VirtualDevice[] devices = vm.Config.Hardware.Device;
      VirtualDisk vd = null;
      foreach (VirtualDevice device in devices)
           device.DeviceInfo.Label.Equals("Hard disk 1"))
                vd = (VirtualDisk)device;
                VirtualDiskFlatVer2BackingInfo backInfo = (VirtualDiskFlatVer2BackingInfo)vd.Backing;
                //vd.VDiskId always reports null
                vDiskMan.ExtendDisk_Task(vd.VDiskId, backInfo.Datastore, 30720);
        • 1. Re: VirtualDisk VDiskId always null
          vmcoder4000 Lurker

          The same problem with same environment versions here. Did you find the cause or workaround for this problem yet?


          • 2. Re: VirtualDisk VDiskId always null
            petermie Enthusiast

            No, I never got anywhere with it so I ended up abandoning the idea. Having abysmal documentation doesn't help either. I'm also starting to think this forum is dead, looking at the post to reply counts. Not sure where a better place would be to ask questions though, you'd think vmware would have better community support and documentation for stuff like this but I guess they just don't care.

            • 3. Re: VirtualDisk VDiskId always null
              vmcoder4000 Lurker

              I have looked at this problem again and i have found information which put me in the right direction.

              With the below code i can now extend the disk of a VM, i hope you can use it too.


                                                              long diskCapacityinKB = 0;

                                                              int deviceCKey = 0;

                                                              int deviceUNumber = 0;

                                                              int deviceKey = 0;                                               

                                                              VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec();                                               

                                                              VirtualDisk diskModify = new VirtualDisk();                                               

                                                              VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();

                                                              VirtualDiskFlatVer2BackingInfo diskfileBacking = new VirtualDiskFlatVer2BackingInfo();

                                                              VirtualDevice[] devices_List = vm.Config.Hardware.Device;

                                                              foreach (VirtualDevice device in devices_List)


                                                                  if (device.DeviceInfo.Label.ToLower().Contains("hard disk"))


                                                                      VirtualDisk vd = device as VirtualDisk;                                                       

                                                                      diskfileBacking = (VirtualDiskFlatVer2BackingInfo)device.Backing;


                                                                      //Modify Selected disk

                                                                      if (device.DeviceInfo.Label.Contains(selected_Harddisk))


                                                                          deviceCKey = device.ControllerKey.Value;

                                                                          deviceUNumber = device.UnitNumber.Value;

                                                                          deviceKey = device.Key;

                                                                          diskCapacityinKB += vd.CapacityInKB + (extend_Size * 1024 * 1024);





                                                                          diskModify.ControllerKey = deviceCKey;

                                                                          diskModify.UnitNumber = deviceUNumber;

                                                                          diskModify.Backing = diskfileBacking;

                                                                          diskModify.CapacityInKB = diskCapacityinKB;

                                                                          diskModify.Key = deviceKey;

                                                                          diskSpec.Operation = VirtualDeviceConfigSpecOperation.edit;

                                                                          diskSpec.Device = diskModify;

                                                                          vmConfigSpec.DeviceChange = new VirtualDeviceConfigSpec[] { diskSpec };

                                                                          //VMware.Vim.Task task = new VMware.Vim.Task(MainWindow.viClient, vm.ReconfigVM_Task(vmConfigSpec));






              • 4. Re: VirtualDisk VDiskId always null
                petermie Enthusiast

                That works great! Thanks for sharing!