public IReadOnlyCollection <string> GetVirtualDiskPaths(ManagedObjectReference virtualMachineRef)
        {
            var virtualDiskPaths = new List <string>();

            VirtualMachineConfigInfo virtualMachineConfig = (VirtualMachineConfigInfo)GetDynamicProperty(virtualMachineRef, "config");

            Verifiers.VerifyNotNull(virtualMachineConfig, "Failed to obtain virtual machine configuration information");

            VirtualDevice[] virtualDevices = virtualMachineConfig.hardware.device;
            foreach (VirtualDevice virtualDevice in virtualDevices)
            {
                if (virtualDevice is VirtualDisk)
                {
                    VirtualDeviceFileBackingInfo backingInfo = (VirtualDeviceFileBackingInfo)virtualDevice.backing;
                    virtualDiskPaths.Add(backingInfo.fileName);
                }
            }

            return(virtualDiskPaths);
        }
예제 #2
0
        private String [] getVDiskLocations(ManagedObjectReference vmmor)
        {
            VirtualMachineConfigInfo vmConfigInfo
                = (VirtualMachineConfigInfo)cb.getServiceUtil().GetDynamicProperty(vmmor, "config");

            if (vmConfigInfo != null)
            {
                VirtualDevice [] vDevice = vmConfigInfo.hardware.device;
                int       count          = 0;
                String [] virtualDisk    = new String [vDevice.Length];

                for (int i = 0; i < vDevice.Length; i++)
                {
                    if (vDevice[i].GetType().FullName.Equals("VimApi.VirtualDisk"))
                    {
                        try {
                            VirtualDeviceFileBackingInfo backingInfo
                                = (VirtualDeviceFileBackingInfo)
                                  vDevice[i].backing;
                            virtualDisk[count] = backingInfo.fileName;
                            count++;
                        } catch (Exception e) {
                            // DO NOTHING
                        }
                    }
                }

                return(virtualDisk);
            }
            else
            {
                Console.WriteLine("Connot Restore VM. Not Able To"
                                  + " Find The Virtual Machine Config Info");
                return(null);
            }
        }