本文介绍了我应该使用哪种VMware的API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想C#编写一个相当简单的应用程序(或至少,我认为它应该是简单)轮询其所有ESX服务器中的vCenter,那么对于所有的虚拟机每台ESX服务器。它会收集一些简单的,实时统计和放下'时间到数据库中。易peasy,对不对?嗯。I'm trying to write a fairly simple application in C# (or at least, I think it should be simple) that polls a vCenter for all of its ESX servers, then each ESX server for all of its VMs. It will collect some simple, real-time statistics and plop 'em into a database. Easy peasy, right? Hmm.我卡试图找出其中的VMware API我应该用和我得到越糊涂越觉得浏览VMware的非常有组织的文档站点。我已经通过大约60页的阅读的的vSphere Web服务SDK编程与指南的,仍然有不知道的如何的获取数据(但我学到了每吨VMware的字母表。汤...开心辞典)I'm stuck trying to figure out which VMware API I should use and I'm getting more confused the more I browse VMware's terribly organized documentation site. I've read through about 60 pages of the vSphere Web Services SDK Programmin Guide and still have no idea how to get data (but I've learned a ton about VMware's alphabet soup... yippie).我的问题是这样的:经过VMware API我应该使用重点围绕收集CPU,内存,网络和硬盘只读应用统计?我需要从一个典型的vCenter +多ESX安装收集这些数据。My question is thus: Which VMware API should I use for a read-only application focused around gathering CPU, memory, network, and harddrive statistics? I need to gather this data from a typical vCenter + multiple-ESX setup. 编辑:我忘了提,我已经成功地写道:一个脚本的PowerCLI做什么,我已经解释了,但它只是过于缓慢和不稳定的生产就绪型产品(和PowerShell是,海事组织,一个设计不当的脚本语言)。我确实有的VMware vSphere SDK用于.NET 的,但所提供的文档......短暂的,至少可以说。我错过了真正的vSphere SDK用于.NET文档? I forgot to mention that I've successfully wrote a PowerCLI script to do what I've explained, but its just too slow and unstable for a production-ready product (and PowerShell is, imo, a poorly designed scripting language). I do have the VMware vSphere SDK for .NET, but the provided documentation is... brief to say the least. Am I missing the real vSphere SDK for .NET docs?推荐答案我觉得你的痛苦。我坐在他们的API多么痛苦的是一个较长的咆哮,但我会饶你。以下是运作相当良好,对我(我是直接连接到ESX箱,但我认为你应该能够建立在这个以到达你想要去的):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):(编辑:格式化固定) 抢的vSphere的PowerCLI 这里(以前称为 VI工具包(适用于Windows));它包括VMware.Vim API和接口推迟到所需的底层实现类(尽管当然,后来的并不明显,从阅读文档)。您的开发机器上安装它(这会在你的全局程序集缓存.NET VMware.Vim实施库;我们将提取我们关心的便携性后库)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)创建VS项目,并在一些世界你好代码抛出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("----------------"); }}如果说作品并打印出有关虚拟机的一些信息,然后到目前为止,一切都很好。如果你看到类似 System.IO.FileNotFoundException:未能加载文件或程序集VimService40,版本= 4.0.0.0,文化=中立,公共KeyToken = 10980b081e887e9f'或它的一个依赖。该系统找不到指定的文件那么你知道你没有安装实际执行文件执行:VMware.Vim.dll只是接口,实际按方案实现在文件一样VimService40.dll,你应该有步骤1中得到。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.在你想要的地方部署该代码,你必须与它发送的实际执行的DLL(再次,VMware.vim.dll是不够的)。您可以使用命令行(而不是浏览器,它不会工作)将其复制出来的全局程序集缓存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.获取从GAC VimService DLL:Get VimService DLL from GAC:cd %windir%\assembly\GAC_MSILcp VimService20\2.0.0.0__10980b081e887e9f\VimService20.dll %HOMEDRIVE%\%HOMEPATH%\Desktopcp VimService20.XmlSerializers\2.0.0.0__10980b081e887e9f\VimService20.XmlSerializers.dll %HOMEDRIVE%\%HOMEPATH%cp VimService25\2.5.0.0__10980b081e887e9f\VimService20.dll %HOMEDRIVE%\%HOMEPATH%\Desktopcp VimService25.XmlSerializers\2.5.0.0__10980b081e887e9f\VimService20.XmlSerializers.dll %HOMEDRIVE%\%HOMEPATH%... etc, for all the VimService versions you might use ... 在部署你的代码到另一台机器,把那些DLL文件在同一文件夹(或路径),你应该有用于构建和部署代码,与ESX箱工作体面的基础。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. 这篇关于我应该使用哪种VMware的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 16:26