VMware Cloud Community
anoopvb
Enthusiast
Enthusiast
Jump to solution

Return the fqdn for a vcenter based on a given VM

I'm slowly working on a set of workflows that will integrate with a powershell module I have created.

For my first workflow, I'm in the process of figuring out all the information I need when a user executes an orchestrator workflow on a virtual machine.

So far i've figured out the cluster but i'm having trouble identifying the right scripting object that will provide me with the fqdn for a vcenter host corresponding to that VM.

Being new to vCO doesn't help a great deal either.

I figured it would be part of VcManagedEntity but for some reason, that page results in a big ol 404!

https://www.vmware.com/support/orchestrator/doc/vco_vsphere51_api/html/VcManagedEntity.html#configSt...

I thought maybe it would be part of vm.runtime.parent.parent but my script is leading to errors.

Any help would be greatly appreciated!

thank you.

1 Solution

Accepted Solutions
ChristianWehner
VMware Employee
VMware Employee
Jump to solution

I think now you are one the right path, the display name of the vCenter server will be localhost, so the response of vm.sdkConnection.setting.sdkConnection is localhost.

Maybe this will help:

var sdkConnection = vm.sdkConnection;

var optionManager = sdkConnection.optionManager;

var vCenterInstanceName = optionManager.queryOptions( "VirtualCenter.InstanceName" ).shift().value;

var vCenterFqdn = optionManager.queryOptions( "VirtualCenter.FQDN" ).shift().value;

System.log( "vCenter Instance Name: " + vCenterInstanceName );

System.log( "vCenter FQDN: " + vCenterFqdn );

Where I think your instance name will show localhost.

But FQDN should be the thing you are searching.

Cheers

View solution in original post

17 Replies
sbeaver
Leadership
Leadership
Jump to solution

Using the vc:virtualmachine object you can get what you need with something like this

vm = vc:virtualmachine

var vc = vm.sdkConnection.setting.sdkConnection

System.log(vc)

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
anoopvb
Enthusiast
Enthusiast
Jump to solution

Hi sbeaver. Thanks for response. When i use

System.log("Vcenter: " + vc.name);

I get https://localhost:443/sdk

In my lab, my vcenter fqdn is serv-vc1.services.local

That's the value I'm trying to get.

thanks!

Reply
0 Kudos
sbeaver
Leadership
Leadership
Jump to solution

I am not sure you understood what I was posting so using the vc:virtualmachine object try the workflow in the package attached to this post

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
anoopvb
Enthusiast
Enthusiast
Jump to solution

My mistake. Thank you for being so patient.

When I try to import the package into the orchestrator client, it reports an error

"Unable to extract package from raw data"

I simply unzipped the zip and then imported the package from the Packages tab in the vCO client.

Am i missing something?

thank you again. I hope "likes" are used like currency here. Smiley Wink

Reply
0 Kudos
anoopvb
Enthusiast
Enthusiast
Jump to solution

If it helps, here's the scripting tab for my workflow.

The schema is very simple. It's just a single scriptable task

var cluster = ((vm.runtime).host.parent);

var vc = vm.sdkConnection.setting.sdkConnection;

Server.log("Hello, " + vm.displayName);

Server.log("VM ID: " + vm.id);

Server.log("VM Cluster: " + cluster.name);

Server.log("vCenter: " + vc.name);

Reply
0 Kudos
sbeaver
Leadership
Leadership
Jump to solution

not sure why the export is not working so lets go old school

Please create a new workflow.  Create an input named vm that is a VC:VirtualMachine type.  add a Scriptable Task.  In the Visual Binding area drag the in Parameter vm over to the in of the scriptable task. and in the scripting are add this code please

var vc = vm.sdkConnection.setting.sdkConnection

System.log(vc.toString())

You will get the Virtual Center name in a string form in the log

If you need the variable vc in a string format and not the object you can use the code this way

var vc = vm.sdkConnection.setting.sdkConnection.toString();

System.log(vc)

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
Reply
0 Kudos
sbeaver
Leadership
Leadership
Jump to solution

  1. var cluster = ((vm.runtime).host.parent); 
  2. var vc = vm.sdkConnection.setting.sdkConnection.toString(); 
  3. Server.log("Hello, " + vm.displayName); 
  4. Server.log("VM ID: " + vm.id); 
  5. Server.log("VM Cluster: " + cluster.name); 
  6. Server.log("vCenter: " + vc); 
Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
Reply
0 Kudos
anoopvb
Enthusiast
Enthusiast
Jump to solution

Hi @sbeaver,

That's pretty much what I have plus some additional information as you can see in the javascript i posted earlier.

The result of System.log("vCenter: " + vc.toString()) is

"vCenter: localhost"

Screen Shot 2015-03-26 at 12.17.33 PM.png

I guess something may be misconfigured on my esx host? or on my vcenter?

Reply
0 Kudos
sbeaver
Leadership
Leadership
Jump to solution

Can you ssh to the vCenter appliance and report the output of this command 

hostname

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
Reply
0 Kudos
anoopvb
Enthusiast
Enthusiast
Jump to solution

yup. First thing i did Smiley Happy

It's not a vcenter appliance. It's a VM in the environment running windows and vCenter Server 5.1.0,799731

not the latest and greatest but the hostname command returns with

"Serv-vc1"

Reply
0 Kudos
sbeaver
Leadership
Leadership
Jump to solution

What is that VM's display name in vCenter?

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
Reply
0 Kudos
ChristianWehner
VMware Employee
VMware Employee
Jump to solution

I think now you are one the right path, the display name of the vCenter server will be localhost, so the response of vm.sdkConnection.setting.sdkConnection is localhost.

Maybe this will help:

var sdkConnection = vm.sdkConnection;

var optionManager = sdkConnection.optionManager;

var vCenterInstanceName = optionManager.queryOptions( "VirtualCenter.InstanceName" ).shift().value;

var vCenterFqdn = optionManager.queryOptions( "VirtualCenter.FQDN" ).shift().value;

System.log( "vCenter Instance Name: " + vCenterInstanceName );

System.log( "vCenter FQDN: " + vCenterFqdn );

Where I think your instance name will show localhost.

But FQDN should be the thing you are searching.

Cheers

anoopvb
Enthusiast
Enthusiast
Jump to solution

here's what i see in the web client.

Screen Shot 2015-03-26 at 1.05.50 PM.png

In vcenter, it's listed as SERV-VC1.services.local

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Try the following ('vm' is the name of your virtual machine scripting object)

var dnsConfig = vm.summary.runtime.host.configManager.networkSystem.networkInfo.dnsConfig;

System.log("host name -> " + dnsConfig.hostName);

System.log("domain name -> " + dnsConfig.domainName);

anoopvb
Enthusiast
Enthusiast
Jump to solution

This did it!

Thank you very much. Where is the information you provided documented?

how did you know to look for VirtualCenter.InstanceName?

thanks!

Reply
0 Kudos
ChristianWehner
VMware Employee
VMware Employee
Jump to solution

Take a look into your vCenter Client and navigate to:

Administration --> vCenter Server Settings... --> Advanced Settings

There you can see vCenter settings and with the option manager you can read em off vCenter. Where it is documented? In my head, it's my practical knowledge 😉

One more thing you have to check out: https://<vcenterip>/mob this is the manages object browser where you can see the vCenter API and attributes and so on and where you can take a look by your own what is where provided 🙂

anoopvb
Enthusiast
Enthusiast
Jump to solution

ChristianWehner Thanks so much! I completely forgot about the mob!

That is very useful information. The Advanced Settings isn't nearly as nice as the mob though.

thanks again!

Reply
0 Kudos