2013-07-24 104 views
0

我正在嘗試編寫一個應用程序,該應用程序將作爲vCenter服務器上的計劃任務運行,並將監視羣集中每個主機的當前時間。時間由NTP設定,但我看到在這些主機上運行的虛擬機服務器長達一分鐘,需要監視發生的情況。VMware ESXi QueryDateTime()方法示例

我的主機都運行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(); 
} 

回答

0

你應該試試這個。

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