문제

C #에 상당히 간단한 응용 프로그램을 작성하려고 노력하고 있습니다 (적어도, 모든 VM의 모든 ESX 서버에 대한 vCenter를 폴링하는 것은 vCenter를 폴링하는 것입니다. 그것은 간단하고 실시간 통계 및 깃털을 데이터베이스로 수집합니다. 쉬운 Peasy, 오른쪽? 흠.

vmware api를 사용해야하는지 알아 내려고 멈추고, 더 혼란스러워서 VMware의 끔찍하게 조직 된 문서 사이트를 더 많이 찾아보십시오. 나는 vSphere Web Services SDK Programmin Guide 의 약 60 페이지를 읽었으며 여전히 데이터를 얻는 을 아직도 (그러나 나는 VMware의 알파벳에 대해 톤을 배웠습니다) 수프 ... yippie).

내 질문은 다음과 같습니다. CPU, 메모리, 네트워크 및 하드 드라이브 통계를 수집하는 데 중점을 둔 읽기 전용 응용 프로그램에 대해 어떤 VMware API를 사용해야합니까? 전형적인 vCenter + DESX 설정 에서이 데이터를 수집해야합니다.

편집 : 나는 PowerCli 스크립트를 성공적으로 썼는데, 제작 준비가되는 제품을 위해 너무 느리고 불안정한 것으로 언급하는 것을 잊었습니다 (그리고 PowerShell은 , IMO, 잘 설계된 스크립팅 언어 인 경우). .NET 에 대해 VMware vSphere SDK가 있지만 제공된 문서는 ... 적어도 말하기는 간단합니다. .NET Docs 용 실제 vSphere SDK가 누락 되었습니까?

도움이 되었습니까?

해결책

I feel your pain. I'm sitting on a longer rant about how painful their APIs are, but I'll spare you. Here's what worked reasonably well for me (I am connecting directly to ESX boxes, but I think you should be able to build on this to get where you want to go):

(Edit: Formatting fixed)

  1. Grab the vSphere PowerCLI here (previously called VI Toolkit (for Windows)); it includes the VMware.Vim API and the required underlying implementation classes that interface defers to (though naturally, the later is not obvious from reading the docs). Install it on your dev machine (this puts the .NET VMware.Vim implementation libraries in your Global Assembly Cache; we'll extract the libraries we care about for portability later)

  2. Create a VS project, and throw in some hello world code.

    using VMware.Vim;
    
    //some namespace, some class, some method...
    
    VimClient c = new VimClient();
    ServiceContent sc = c.Connect("hostnameOrIpHere");
    UserSession us = c.Login("usernameHere", "passwordHere");
    
    IList<VMware.Vim.EntityViewBase> vms = c.FindEntityViews(typeof(VMware.Vim.VirtualMachine), null, null, null);
    foreach (VMware.Vim.EntityViewBase tmp in vms)
    {
        VMware.Vim.VirtualMachine vm = (VMware.Vim.VirtualMachine)tmp;
        Console.WriteLine((bool)(vm.Guest.GuestState.Equals("running") ? true : false));
        Console.WriteLine(new Uri(ENDPOINTURL_PREFIX + (vm.Guest.IpAddress != null ? vm.Guest.IpAddress : "0.0.0.0") + ENDPOINTURL_SUFFIX));
        Console.WriteLine((string)vm.Client.ServiceUrl);
        Console.WriteLine(vm.Guest.HostName != null ? (string)vm.Guest.HostName : "");
        Console.WriteLine("----------------");        
    

    }

  3. If that works and prints out some info about your VMs then so far, so good. If you see something like System.IO.FileNotFoundException: Could not load file or assembly 'VimService40, Version=4.0.0.0, Culture=neutral, Public KeyToken=10980b081e887e9f' or one of its dependencies. The system cannot find the file specified. then you know you don't have the actual implementation files installed: VMware.Vim.dll is just the interface, and the actual per-protocol implementations are in files like VimService40.dll that you should have gotten with step 1.

  4. Once you want to deploy this code somewhere, you have to send the actual implementation dlls with it (again, VMware.vim.dll isn't sufficient). You can use the command line (not Explorer, it won't work) to copy them out of the Global Assembly Cache.

    Get VimService DLL from GAC:

    cd %windir%\assembly\GAC_MSIL
    cp VimService20\2.0.0.0__10980b081e887e9f\VimService20.dll %HOMEDRIVE%\%HOMEPATH%\Desktop
    cp VimService20.XmlSerializers\2.0.0.0__10980b081e887e9f\VimService20.XmlSerializers.dll %HOMEDRIVE%\%HOMEPATH%
    cp VimService25\2.5.0.0__10980b081e887e9f\VimService20.dll %HOMEDRIVE%\%HOMEPATH%\Desktop
    cp VimService25.XmlSerializers\2.5.0.0__10980b081e887e9f\VimService20.XmlSerializers.dll %HOMEDRIVE%\%HOMEPATH%
    ... etc, for all the VimService versions you might use ...
    
  5. When you deploy your code to another machine, put those DLLs in the same folder (or on the path) and you should have a decent basis for building and deploying code that works with ESX boxes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top