【发布时间】:2015-04-17 16:51:08
【问题描述】:
使用 VMware.Vim 库(我相信是 PowerCLI 的一部分)我试图找到 vSphere 中存在的特定机器。我的代码如下所示:
using VMware.Vim;
var client = new VimClient();
client.Connect("http://my-vsphere/sdk");
client.Login("username", "password");
var filter = new NameValueCollection();
filter.Add("name", "my-vm-name");
var vms1 = client.FindEntityViews(typeof(VirtualMachine), null, filter, null);
// vms1 is null here. WTF?
var vms2 = client.FindEntityViews(typeof(VirtualMachine), null, null, null);
foreach (VirtualMachine vm in vms)
{
if(vm.Name = "my-vm-name")
{
Console.WriteLine("Found it!");
}
}
// This works!
基本上如果我按照SDK文档中列出的方法,我找不到机器。如果我盲目地查询所有机器并遍历集合,我可以找到它。
我错过了什么吗?
【问题讨论】:
标签: c# vmware vsphere powercli