VMware {code} Community
Aristizabal
Enthusiast
Enthusiast
Jump to solution

QueryAssignedLicenses problem getting ESX host licensed features

Hello,

I am trying to obtain the list of licensed features for a vSphere 4.0 host using the the QueryAssignedLicenses method via perl SDK.

I can get the license Manager object but every time I get the managed object "LicenseAssignmentManager" it is undefined.

Here is the code I am using:

my $host;

my $host_views =

Vim::find_entity_views(view_type => 'HostSystem');

$host = @$host_views[0];

my $licenseSystem = Vim::get_view(mo_ref => ($host->configManager->licenseManager) );

my $licenses = Vim::get_view(mo_ref => ($licenseSystem->licenseAssignmentManager) );

my $licenseDummy = $licenses->QueryAssignedLicenses();

And this is the error message:

"Can't call method "type" on an undefined value at /usr/share/perl/5.8/VMware/VICommon.pm line 1244."

I have tried assigning the return value of QueryAssignedLicenses(); directly to an object but the result is the same, and I think the method can't be called since the LicenseAssignmentManager" object is undefined.

As pointed out on the thread: http://communities.vmware.com/message/1271444, I tried with different methods but all of them are deprecated for vSphere and I get a SOAP error.

Any help is highly appreciated.

Thanks.

Juan Aristizabal.

Reply
0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager
Jump to solution

When connecting to vCenter, you're unable to access the LicenseManager through the HostSystem object, you need to use the vCenter's Service Content: http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.LicenseManager.html

That is where you'll find licenseAssignmentManager

=========================================================================

William Lam

VMware vExpert 2009,2010

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

View solution in original post

Reply
0 Kudos
4 Replies
lamw
Community Manager
Community Manager
Jump to solution

The reason this is occurring is because the licenseAssignmentManager is not actually available and so when you try to get a reference to that object, it's actually returning NULL and then you try to perform a method on an unknown object.

You should always check to see if it's valid before attempting an operation, good to put it in eval {...} statement.

eval {
my $licenseDummy = $licenses->QueryAssignedLicenses();
};
if($@) {  print "ERROR: . $@ . "\n"; }

Basically, licenseAssignmentManager is only available when connecting to a vCenter server and not to an individual host

=========================================================================

William Lam

VMware vExpert 2009,2010

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

Aristizabal
Enthusiast
Enthusiast
Jump to solution

Thanks for the reply William.

I modified my script and now I run it against a vCenter server. I get the HostSystem object and then I try to get the LicenseManager object from it, but now the object is undefined. Before I was able to get the LicenseManager talking directly to the ESX host.

Here is the code I am using:

my $hostname = Opts::get_option('hostname');

my $host_view = Vim::find_entity_view(view_type => 'HostSystem',filter => {name => $hostname});

my $licenseSystem = $host_view->configManager->licenseManager;

print $licenseSystem;

And this is the error I get when I run it:

Use of uninitialized value in print at ./check_license.pl line 33.

Juan.

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

When connecting to vCenter, you're unable to access the LicenseManager through the HostSystem object, you need to use the vCenter's Service Content: http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.LicenseManager.html

That is where you'll find licenseAssignmentManager

=========================================================================

William Lam

VMware vExpert 2009,2010

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
Aristizabal
Enthusiast
Enthusiast
Jump to solution

Thanks William, that makes sense; I got it working now.

Juan.

Reply
0 Kudos