Saving and Using Sessions
The vSphere SDK for Perl library includes several subroutines that save and reuse sessions, so you can maintain sessions across scripts. Using sessions can enhance security: Instead of storing passwords in scripts, you can run the Vim::login() subroutine in your script using the name of the session file. The session file does not expose password information.
Saving Sessions
You can save a session using the subroutine call syntax as follows:
Vim::save_session():
 
...
# usual login procedure with connect()
Util::connect();
...
# save the global session in file .mysession
Vim::save_session(session_file => '.mysession');
Alternatively, you can use save_session() with the object-oriented syntax (see Using Multiple Sessions):
...
# object-oriented login
my $service_url = "https://$server/sdk/vimService";
my $vim = Vim->new(service_url => $service_url);
$vim->login(user_name => $username, password => $password); ...
# save session $vim in file .mysession
$vim->save_session(session_file => '.mysession');
The session remains active until the program runs a log out or disconnect operation, or until the program times out. Time out is 30 minutes after the last operation was performed.
Loading Sessions
You can use load_session() to load a saved session into the global session as follows:
Vim::load_session(session_file => '.visession');
Alternatively, you can load a session using the object-oriented syntax as follows:
my $service_url = "https://$server/sdk/vimService";
my $vim = Vim->new(service_url => $service_url);
$vim = $vim->load_session(session_file => '.visession');