سؤال

أحاول كتابة تطبيق بسيط إلى حد ما في C # (أو على الأقل، أعتقد أنه يجب أن يكون بسيطا) استطلاعات VCenter لجميع خوادم ESX الخاصة به، ثم كل خادم ESX لجميع VMS. ستجمع بعض الإحصاءات البسيطة والوقت في الوقت الفعلي وتطوير قاعدة بيانات. سهلة السريعة، أليس كذلك؟ هم.

أنا عالق في محاولة لمعرفة أي api vmware، يجب أن أستخدمها وأنا أحصل على المزيد من الخلط بين أكثر من موقع الوثائق المنظمة المنظمة VMware VMWare. لقد قرأت حوالي 60 صفحة من VSPHERE Services SDK Guide وما زالت لا تحتوي على أي فكرة كيف للحصول على بيانات (لكنني تعلمت طن عن الأبجدية VMWare حساء ... Yippie).

سؤالي هو بالتالي: أي برنامج VMware API يجب أن أستخدمه للحصول على تطبيق للقراءة فقط يركز حول جمع وحدة المعالجة المركزية والذاكرة والشبكة والإحصائيات الصلبة؟ أحتاج إلى جمع هذه البيانات من برنامج إعداد VCCenter + متعدد ESX.

تحرير: قد نسيت أن أذكر أنني كتبت بنجاح برنامج نصي ل PowerCli للقيام بما أوضحته، ولكنه بطيء للغاية وغير مستقر لمنتج جاهز للإنتاج (و PowerShell ، IMO، لغة نصية سيئة التصميم). لدي vmware vsphere SDK .NET ، ولكن الوثائق المقدمة هي ... موجز ليقول أقل. هل أنا في عداد المفقودين real vsphere sdk for .Net مستندات؟

هل كانت مفيدة؟

المحلول

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