【发布时间】:2013-07-23 18:37:50
【问题描述】:
我正在尝试编写一个应用程序,该应用程序将作为计划任务在 vCenter 服务器上运行,并将监控集群中每个主机的当前时间。时间是由 NTP 设置的,但我发现这些主机上运行的 VM 服务器最多会延迟一分钟,需要监控会发生什么。
我的主机运行的是 ESXi v5.1
根据文档 (http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.DateTimeSystem.html#queryDateTime),有一种方法可以获取主机的当前日期时间 - QueryDateTime()。
我正在努力让它工作......我的示例代码如下。它总是抱怨QueryDateTime 方法不存在!
这可能是我不了解 SDK,但我无法弄清楚......
VimClient vimClient = new VimClient();
vimClient.Connect(vcenter.ServiceURL);
vimClient.Login(vcenter.Username, vcenter.Password);
List<EntityViewBase> hosts = vimClient.FindEntityViews(typeof(VMware.Vim.HostSystem), null, null, null);
foreach (HostSystem host in hosts)
{
Console.WriteLine(host.Config.Network.Vnic[0].Spec.Ip.IpAddress);
HostConfigManager hostConfigManager = host.ConfigManager;
HostDateTimeSystem hostDateTimeSystem = hostConfigManager.DateTimeSystem;
DateTime hostDateTime = hostDateTimeSystem.QueryDateTime();
}
【问题讨论】: