VMware {code} Community
flowlsj
Contributor
Contributor

Can't get vim_service - the session object is uninitialized or not logged in at C:/Perl/site/lib/VMware/VICommon.pm line 1654.

Hi,

When I use ViPerlToolkit to create a virtual disk on a datastore, I always get this error, do you have any idea on this please?

my codes are like:

     my $vimObj = Vim->new(server => XXX);

     my $content = $vimObj->get_service_content();

     my $vDiskManager= $vimObj->get_view(mo_ref => $content->virtualDiskManager);

     $vDiskManager->CreateVirtualDisk_Task(

        name => XXX,

        spec => XXX,

    );

Any comments will be appreciate!

Thanks

Reply
0 Kudos
4 Replies
mpr4ul
Contributor
Contributor

You need to login to the server, then you can use VIM object, how can you use by creating just empty VIM object ?

use VMware::VIRuntime;

Opts::parse();

Opts::validate();

Util::connect();

-------------------------------

your code here

------------------------------

Util::disconnect();

Reply
0 Kudos
flowlsj
Contributor
Contributor

Hi mpr4ful,

Thanks for your answer, but I did log into server. Sorry to miss it here

$vimObj->login(username => xxx, password => xxx');

Thanks

Reply
0 Kudos
mpr4ul
Contributor
Contributor

Try this

my $url = "https://<serverip>/sdk/webService";

Vim::login(service_url => $url, user_name => <>, password => <> );

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

As mpr4ul pointed out, you have to login.

You can use the usual global SDK methods - Util::connect().

You can also use the VIM object calls.  If you review the code, you'll see it does a lot of global variables.  If you skip service_url, will try to deduce one (usually ends up as localhost).

Use the form mpr4ul pointed out, but if you want to use a $vim instance (perhaps to login to multiple vCenters), then use the form:

$vim = Vim::login(service_url => $service_url, user_name => $username, password => $password);

$Vim::vim_global = undef;

The second line will clear the SDK's global VIM variable if you decide to use multiple vCenters endpoints.  Otherwise, you may have some unexpected side effects.

You can also look into logging in with a saved session from a previous login, NTLM, etc.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos