When I run find_entity_views with no begin_entity it works. However, when I want to filter and ONLY get vm's from a certain esx host it erorrs.
$Vm_servers = Vim::find_entity_views (view_type => 'VirtualMachine',
begin_entity => $Esx_Host);
Cannot serialize obj as ManagedObjectReference at C:/Program Files/VMware/VMware VI Perl Toolkit/Perl/lib/VMware/VICommon.pm line 1635
ComplexType::serialize('ObjectSpec=HASH(0x3128894)', 'objectSet', 'undef') called at C:/Program Files/VMware/VMware VI Perl
Toolkit/Perl/lib/VMware/VICommon.pm line 1640
ComplexType::serialize('PropertyFilterSpec=HASH(0x3906080)', 'specSet') called at C:/Program Files/VMware/VMware VI Perl
Toolkit/Perl/lib/VMware/VIM25Stub.pm line 31359
VimService::get_arg_string('PropertyFilterSpec=HASH(0x3906080)', 'specSet', 'PropertyFilterSpec') called at C:/Program Files/VMware/VMware VI
Perl Toolkit/Perl/lib/VMware/V
IM25Stub.pm line 31379
VimService::build_arg_string('ARRAY(0x42a548c)', 'HASH(0x42a542c)') called at C:/Program Files/VMware/VMware VI Perl
Toolkit/Perl/lib/VMware/VIM25Stub.pm line 31418
VimService::RetrieveProperties('VimService=HASH(0x226a948)', '_this', 'ManagedObjectReference=HASH(0x24ee28c)', 'specSet',
'PropertyFilterSpec=HASH(0x3906080)') called at C
:/Program Files/VMware/VMware VI Perl Toolkit/Perl/lib/VMware/VICommon.pm line 739
Vim::find_entity_views('view_type', 'VirtualMachine', 'begin_entity', 'axnyesx21') called at C:\WORK\current\perl\Vmware\/VMWARE_DR.pm line
114
VMWARE_DR::vmCreateViews('testesxserver') called at C:\WORK\current\perl\Vmware\vmwaredr_test.pl line 56
Hello,
Can you run the code I posted? That works just fine for me. Including the part about the VMs....
In order to receive mail on a forum you need to set your profile to receive email. Generally that only happens on the items to which you post or have posted a followup.
Best regards,
Edward L. Haletky
VMware Communities User Moderator
====
Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education.
CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354
As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization
Hello,
Look at the host/hostevacuate.pl demo script to understand how to use begin_entity. Mainly this has to be an entity and not a string. The following may work but the hostevacuate.pl code has the example you desire.
my $source_host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => {name => $sourcehost}); $Vm_servers = Vim::find_entity_views (view_type => 'VirtualMachine', begin_entity => $source_host_view);
Best regards,
Edward L. Haletky
VMware Communities User Moderator
====
Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education.
CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354
As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization
Thank you for your response. However, I have tried that many times and it always dies on me.
my $Esx_Host = host21;
$single_host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => {name => $Esx_Host});
if (! $single_host_view) {
die " host: '$Esx_Host' not found\n";
}
Hello,
I took the hostevacuate.pl and stripped all but the Vim::find_entity_view and Vim::find_entity_views and it seems to work for me.
Note you have
my $Esx_Host = host21;
Do you not mean
my $Esx_Host="host21";
Else host21 is taken as a variable not a string.
Best regards,
Edward L. Haletky
VMware Communities User Moderator
====
Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education.
CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354
As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization
i guess a library or something might be messing me up. I just don't get it what's the problem.
those scripts are assuming you are running on the control center machine. However, I am running on a separate box connecting to the control machine. Maybe it's different ? I took the same code and the filter just don't work
Hello,
The scripts do not assume that. Run the script with --help and you will see a host of options and one is to specify the URL to use. I run everything from a Linux box separate from everything. Are you trying to connect to a single ESX host or or the VC Server.
This works for me from anywhere, note that it takes as args:
--url https://machine/sdk/webService --sourcehost hostnameAsItAppearsInVIC
If the url is incorrect and the sourcehost does not match what is seen in the vic it will not work. I call it with....
perl hoste.pl --url https://vcserver/sdk/webService --username VICLogin --password VICpass --sourcehost hostAsitAppearsInVIC
#!/usr/bin/perl -w use strict; use warnings; use VMware::VIRuntime; use VMware::VILib; $SIG{__DIE__} = sub{Util::disconnect()}; $Util::script_version = "1.0"; my %opts = ( sourcehost => { type => "=s", help => "Host name containing virtual machines to be evacuated", required => 1, }, ); Opts::add_options(%opts); Opts::parse(); Opts::validate(\&validate); Util::connect(); my $source_host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => {name => Opts::get_option('sourcehost')}); my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine', begin_entity => $source_host_view); my $vm; for $vm (@{$vm_views}) { print $vm->name."\n"; } Util::disconnect(); sub validate { return 1; }
Best regards,
Edward L. Haletky
VMware Communities User Moderator
====
Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education.
CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354
As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization
ok, i am making some progress here is the code snippet
if i set $Esx_Host to be hostname - doesn't work. If I set it to be $Esx_Host = hostname.mlob.com it works fine. however, now i am stuck in the vm section. hope you can continue to help here.
my $src_host_view = Vim::find_entity_view(view_type => 'HostSystem',
filter => { name => "$Esx_Host" });
if (!$src_host_view) {
die "Source host '$Esx_Host' not found\n";
}
here is where I get to and that's great
get all VM's under src host
my $Vm_servers = Vim::find_entity_views(view_type => 'VirtualMachine',
begin_entity => $src_host_view);
}
if (!$Vm_servers) {
die "Source host '$Esx_Host' can not find any vm's \n";
}
here is where I die out !
BTW, is there a way for me to help others.. How can I get an email when someone posts a questions ?
Hello,
Can you run the code I posted? That works just fine for me. Including the part about the VMs....
In order to receive mail on a forum you need to set your profile to receive email. Generally that only happens on the items to which you post or have posted a followup.
Best regards,
Edward L. Haletky
VMware Communities User Moderator
====
Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education.
CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354
As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization
ok, great - thanks it works !