Highlighted
Expert
Expert

put connected server to variable

Jump to solution

I am busy with a script do some tasks, but i want to store the vCenter server to which i connect in a variable.

What was the best option for this?

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Community Manager
Community Manager

You can get the vCenter instance name by using that advanced key VirtualCenter.InstanceName as you mentioned, but this is not guaranteed to match the actual hostname of your vCenter.

If I understand you correctly and you're using vSphere SDK for Perl and you're already connected to vCenter server since you're querying for the advanced VPX configurations, you can actually get the IP or Hostname by doing the following:

my $server = Opts::get_option('server');

VMware has already created a few modules that helps creating new vSphere SDK for Perl scripts and handles most of the authentication and by default you can access the username, password and server among other variables. So if you're already connecting to vCenter using IP or FQDN, you can just extract that variable out. Now if you want the full FQDN and you're connecting via IP, then just use Perl to do a reverse lookup, assuming DNS is fully functional in your environment as it should be.

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

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

View solution in original post

0 Kudos
4 Replies
Highlighted
Virtuoso
Virtuoso

Do you mean the server IP/FQDN? Or you want to store the VIM object so you can reuse it? Basically the SOAP is all session based. So long as your cookie based SID is saved you can reconnect. But the Perl SDK has an a save session option just for that scenario.

Might need more information to understand what you're looking to do.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Highlighted
Expert
Expert

I need the server vCenter server FQDN,

What i am doing now is the following:

my $content = Vim::get_service_content();

my $vpxsetting = Vim::get-view(mo_ref => $content->setting);

my $query_vpx = $vpxsetting->QueryOptions(name=>"VirtualCenter.InstanceName");

The $query_vpx is an array, but i have some troubles getting the FQDN from this array.

It's been to long since i last used perl for VMware.

0 Kudos
Highlighted
Community Manager
Community Manager

You can get the vCenter instance name by using that advanced key VirtualCenter.InstanceName as you mentioned, but this is not guaranteed to match the actual hostname of your vCenter.

If I understand you correctly and you're using vSphere SDK for Perl and you're already connected to vCenter server since you're querying for the advanced VPX configurations, you can actually get the IP or Hostname by doing the following:

my $server = Opts::get_option('server');

VMware has already created a few modules that helps creating new vSphere SDK for Perl scripts and handles most of the authentication and by default you can access the username, password and server among other variables. So if you're already connecting to vCenter using IP or FQDN, you can just extract that variable out. Now if you want the full FQDN and you're connecting via IP, then just use Perl to do a reverse lookup, assuming DNS is fully functional in your environment as it should be.

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

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

View solution in original post

0 Kudos
Highlighted
Expert
Expert

Thanks, Why didn it hink of that.

I has been a while ago since i last used perl for vmware. I am a bit rusty :smileygrin:

0 Kudos