0

Vmware's .net api reference is somewhat confusing and hard to follow. I have been able to connect to my vcenter host then get a list of esxi hosts. Then I have been able get all the running modules on the host using HostKernelModuleSystem, and probe the properties on the variable "mod"... but I am not able to figure out how to get license info, I tried creating an object lic below, trying all different kinds of "types" from vmware with the word license in the type. but, it never works it has a problem converting the line with LicenseManagerLicenseInfo lic = .... I always get the following:

"Cannot convert type 'Vmware.Vim.Viewbase' to 'Vmware.Vim.LicenseManagerLicenseInfo'"

but the declaration above it for "mod" works fine.

I have also tried:

  • HostLicenseConnectInfo
  • LicenseAssignmentManagerLicenseAssignment
  • LicenseManager

I am hoping someone who has worked with vmware .net api can shed some light on what i am doing wrong? I am new to C# about 1 year :) but these VMware APIs are somewhat confusing to me.

esxList = client.FindEntityViews(typeof(HostSystem), null, null, null);

foreach (HostSystem host in esxList)
{
    HostKernelModuleSystem mod = (HostKernelModuleSystem)client.GetView(host.ConfigManager.KernelModuleSystem, null);
    LicenseManagerLicenseInfo lic = (LicenseManagerLicenseInfo)client.GetView(host.ConfigManager.LicenseManager, null);

    string name = lic.Name;
}
Dmitrii Lobanov
  • 4,897
  • 1
  • 33
  • 50
john johnson
  • 699
  • 1
  • 12
  • 34

2 Answers2

0

I'll have to go to work tomorrow to look at this ( don't have ESX and VMWare SDK for .NET at home ) but I've done a bit of this work.

I wrote a generics method that wraps FindEntityViews and takes a filter as an argument. That makes it easy to search for anything. Also I've noticed that searches come back as ManagedObjectReferences and can't be cast to the subclasses. You have to construct them passing the ManagedObjectReference as an argument.

Also I find searching for PowerCLI examples and watching the classes in the immeadiate window very help in navigating this API. It's a fairly decent SDK but they put all of the classes in a single namespace and there's lots of little style inconsistencies ( Device instead of Devices and properties that take strings instead of enums when an enum exists ).

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • Update: I'm working on this but when I get a host back and look at the ConfigManager.LicenseManager property it is null so it's hard to try to then do something with it. – Christopher Painter Feb 02 '12 at 14:36
  • yeah i know i got the same thing, i can't figure it out LOL.. i thought i was following the api from vmware but i have no idea, i figured if it null can't do anything with it, then what or how to get licenses is the question – john johnson Feb 03 '12 at 13:40
  • Sorry, I'm stumped. I'm also on vacation for the next week. If you still haven't figured it out I'll look at it again as I'm really trying to get familiar with the API myself. – Christopher Painter Feb 03 '12 at 15:30
0

i figured out how to do it :) , by using http://vcenter_hostname/mob I was able to walk through api better. here is what I did, plus instead of of using "host" which was type HostSystem I jused my instance of my vCenter host "client"

VMware.Vim.LicenseManager lic_manager = (VMware.Vim.LicenseManager)client.GetView(client.ServiceContent.LicenseManager, null);
LicenseManagerLicenseInfo[] lic_found = lic_manager.Licenses;

foreach (LicenseManagerLicenseInfo lic in lic_found)
{
    string test = lic.Name.ToString();
    string test2 = lic.LicenseKey.ToString();
}
Dmitrii Lobanov
  • 4,897
  • 1
  • 33
  • 50
john johnson
  • 699
  • 1
  • 12
  • 34