VMware {code} Community
mman
Contributor
Contributor
Jump to solution

VI Perl API multiple sessions problem

Hello,

I'm using VI Perl Toolkit version 1.0.

As said in:

http://www.vmware.com/support/developer/viperltoolkit/doc/perl_toolkit_guide_idx.html

"Saving and Using Sessions

The VI Perl Toolkit library includes several subroutines that let

you save and re-use sessions, enabling you to maintain sessions across

scripts and use multiple sessions within the same script—for example,

to copy information from one server to another."

I'm trying to use script that uses multiple sessions within.

Here is the source:

#!/usr/bin/perl

use strict;

use warnings;

use Storable;

use Data::Dumper;

use VMware::VIRuntime;

use VMware::VILib;

my $session1 = Vim->new(service_url => 'https://esx1/sdk');

$session1->login(

+ user_name => 'root',+

+ password => 'password');+

my $session2 = Vim->new(service_url => 'https://esx2/sdk');

$session2->login(

+ user_name => 'root',+

+ password => 'password');+

my $hostview1 = $session1->find_entity_view(view_type => 'HostSystem');

#my $hostview2 = $session2->find_entity_view(view_type => 'HostSystem');

print Dumper($hostview1);

#print Dumper($hostview2);

I get the following:

at /usr/local/share/perl/5.8.8/VMware/VIM2Stub.pm line 180

+ SoapClient::request('SoapClient=HASH(0x9745aa8)', 'RetrieveProperties', '<_this type="PropertyCollector">ha-property-collector</_this>...')+

called at /usr/local/share/perl/5.8.8/VMware/VIM2Stub.pm line 25848

+ VimService::RetrieveProperties('VimService=HASH(0x9755f0c)', '_this', 'ManagedObjectReference=HASH(0x9883974)', 'specSet',+

'PropertyFilterSpec=HASH(0x98a93cc)') called at /usr/local/share/perl/5.8.8/VMware/VIM2Runtime.pm line 502

+ ViewBase::update_view_data('HostSystem=HASH(0x82f9268)', '') called at /usr/local/share/perl/5.8.8/VMware/VIM2Runtime.pm line 367+

+ Vim::get_view('Vim=HASH(0x8149540)', 'mo_ref', 'ManagedObjectReference=HASH(0x98a9828)', 'view_type', 'HostSystem', 'properties', '') called+

at /usr/local/share/perl/5.8.8/VMware/VIM2Runtime.pm line 229

+ Vim::find_entity_view('Vim=HASH(0x8149540)', 'view_type', 'HostSystem') called at ./multi_session_test.pl line 24+

Is it possible to use two connection sessions

not storing session in a file and then reconnecting to another host?

Reply
0 Kudos
1 Solution

Accepted Solutions
jnhall
Enthusiast
Enthusiast
Jump to solution

It's possible to use Opts for your options processing, but you can't use the validate() code in a conventional way, and then obviously connect() won't work at all because it has no notion of multiple sessions. That's not a bug - it's a product of the simpler design implemented for the vast majority of cases where only a single connection is required. For multiple connections you need a different programming model a la the sessions example I pointed you to.

Trust me - this will be documented correctly in the future. Right now I don't know whether that will be in the next release, or in a separate release note. It will certainly be integrated into the regular product documentation at some point.

View solution in original post

Reply
0 Kudos
6 Replies
mman
Contributor
Contributor
Jump to solution

Ok, is there any way to connect ti multiple hosts within one script?

Util::connect can't use option like 'server' to connect to another server, not to the same we disconnected using 'Util::disconnect' before.

Vim::login dumps big XML with all information and after perl trace i've shown before.

I've found the only way add options like 'second_server', 'second_username', 'second_password'. And then rerunning script within itself with --server='second_server' and stuff

Reply
0 Kudos
jnhall
Enthusiast
Enthusiast
Jump to solution

Try the coding pattern in the samples/session/multisession.pl example. You need to use the login() method.

The documentation is not clear / incorrect on how to do this. It will be corrected in a future version.

mman
Contributor
Contributor
Jump to solution

This script is truly working with multiple sessions. Thank you.

But I think if you want to use multiple sessions, you should follow EXACTLY that code, I've copypasted major part of that script, changing only the way url for Vim::new is constructed (not using Opts) and I get the same error.

Reply
0 Kudos
jnhall
Enthusiast
Enthusiast
Jump to solution

It's possible to use Opts for your options processing, but you can't use the validate() code in a conventional way, and then obviously connect() won't work at all because it has no notion of multiple sessions. That's not a bug - it's a product of the simpler design implemented for the vast majority of cases where only a single connection is required. For multiple connections you need a different programming model a la the sessions example I pointed you to.

Trust me - this will be documented correctly in the future. Right now I don't know whether that will be in the next release, or in a separate release note. It will certainly be integrated into the regular product documentation at some point.

Reply
0 Kudos
mman
Contributor
Contributor
Jump to solution

Ok, thank you. I'm glad I can use this feature.

Reply
0 Kudos
Jasonvm
Contributor
Contributor
Jump to solution

I tried to make the script of multisession.pl to work without any alteration but it was not working. I tried many different combinations of the optional parameters. Below is one of the commands that I tried:

$ perl multisession.pl -protocol2 https -url2 10.200.68.143 -username xxxx -password xxxx -host2 localhost -portnumber2 80 -servicepath2 /sdk/webService

THe erroe messages ar:

Error: Server version unavailable at 'https://localhost/sdk/vimService.wsdl' :1: parser error : Space required after the Public Identifier

^

:1: parser error : SystemLiteral " or ' expected

^

:1: parser error : SYSTEM or PUBLIC, the URI is missing

^

:9: parser error : Opening and ending tag mismatch: hr line 7 and body

^

:9: parser error : Opening and ending tag mismatch: body line 4 and html

^

:10: parser error : Premature end of data in tag html line 2

^

at /usr/lib/perl5/site_perl/5.8.5/VMware/VICommon.pm line 267

Is this script used only for copying/pasting not for running?

Thanks.

jj

Reply
0 Kudos