C# VMware ESXi QueryDateTime()方法示例

C# VMware ESXi QueryDateTime()方法示例,c#,esxi,C#,Esxi,我正在尝试编写一个应用程序,它将作为vCenter server上的计划任务运行,并将监视群集中每个主机的当前时间。时间是由NTP设定的,但我看到这些主机上运行的VM服务器将停止运行一分钟,需要监控发生了什么 我的主机正在运行ESXi v5.1 根据文档(),有一个方法可以获取主机的当前日期时间-QueryDateTime() 我正在努力让它工作,虽然。。。。我的示例代码如下。它总是抱怨QueryDateTime方法不存在 这可能是因为我不理解SDK,但我无法理解 VimClient vimCl

我正在尝试编写一个应用程序,它将作为vCenter server上的计划任务运行,并将监视群集中每个主机的当前时间。时间是由NTP设定的,但我看到这些主机上运行的VM服务器将停止运行一分钟,需要监控发生了什么

我的主机正在运行ESXi v5.1

根据文档(),有一个方法可以获取主机的当前日期时间-
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();
}
VimClient-VimClient=new-VimClient();
vimClient.Connect(vcenter.ServiceURL);
vimClient.Login(vcenter.Username、vcenter.Password);
List hosts=vimClient.FindEntityViews(typeof(VMware.Vim.HostSystem),null、null、null;
foreach(主机中的主机系统主机)
{
Console.WriteLine(host.Config.Network.Vnic[0].Spec.Ip.IpAddress);
HostConfigManager HostConfigManager=host.ConfigManager;
HostDateTimeSystem HostDateTimeSystem=hostConfigManager.DateTimeSystem;
DateTime hostDateTime=hostDateTimeSystem.QueryDateTime();
}
您应该试试这个

foreach (HostSystem host in vmHosts)
{
HostConfigManager hostConfigManager = host.ConfigManager;
HostDateTimeSystem hostDateTimeSystem = (HostDateTimeSystem) vimClient.GetView(hostConfigManager.DateTimeSystem, null));
DateTime hostDateTime = hostDateTimeSystem.QueryDateTime();
}