VMware {code} Community
maxpil
Contributor
Contributor

Can't call method "roleid" on unblessed reference

I am a getting this error when running my code:

Can't call method "roleid" on unblessed reference at /home/mlevine/vm-perms.pl line 34.

My code is below:

#!/usr/bin/perl

use strict;

use warnings;

use VMware::VIRuntime;

Opts::parse();

Opts::validate();

Util::connect();

my $entity_type = "VirtualMachine";

my $vm_view = Vim::find_entity_views(

view_type => "VirtualMachine",

filter => {

'config.guestFullName' => qr/Solaris/

}

);

my $auth_mgr = Vim::get_view(mo_ref => Vim::get_service_content()->authorizationManager);

my %role_hash;

my $role_list = $auth_mgr->roleList;

foreach (@$role_list) {

$role_hash{$_->roleId} = $_->name;

}

foreach my $vm (@$vm_view) {

my $vm_name = $vm->name;

next unless $vm_name eq "sol-test";

my @permissions = $auth_mgr->RetrieveEntityPermissions(entity=>$vm, inherited=>"true");

foreach my $perm (@permissions) {

if ($perm->roleid eq "102" or $perm->roleid eq "251658360") {

delete $permissions[$perm];

}

}

Util::trace(0, "Found $entity_type: $vm_name\n");

}

  1. Disconnect from the server

Util::disconnect();

Any clue about this error?

0 Kudos
1 Reply
lamw
Community Manager
Community Manager

One thing that stands out is that you're not passing in the right property name, it's roleId and not roleid take a look at the API reference for the return permission object - http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.AuthorizationManager....

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

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".

0 Kudos