1

我想自动扩展虚拟磁盘文件的大小,但遇到了异常。我的系统运行的是vCenter 4和vSphere 4,不知道下面的代码是否正确。有什么解决办法吗?

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", "Datacenter");
                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;
            }
        }

谢谢你的帮助!

4

0 回答 0