VMware Cloud Community
tough_siberian_
Enthusiast
Enthusiast
Jump to solution

How to get vCO server name (hostname).

Hello.

Does anybody know how to get hostname or IP address of the vCO server within a workflow running on that server? Is there any kind of property or method returning hostname of the local host?

Thank you.

1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Try this :

function getVcoHostname() {
    var answerUrl = workflow.getAnswerUrl().url;
    var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');
    return answerUrl.match(re)[1].toString().split(":")[0];
}

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter

View solution in original post

Reply
0 Kudos
10 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

I'm not aware of any off the top of my head... A quick look in the api explorer didn't show anything obvious either.. If I had to do this, I would use the "command" object and then use the "hostname" command to get the hostname, or use ipconfig or ifconfig depending on the OS to get the IP info.

See Joerg's great post here to learn more about running local commands:

http://www.vcoportal.de/2011/08/small-but-useful-command-line-tools-for-vco-workflows/

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Try this :

function getVcoHostname() {
    var answerUrl = workflow.getAnswerUrl().url;
    var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');
    return answerUrl.match(re)[1].toString().split(":")[0];
}

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
tmalaher
Contributor
Contributor
Jump to solution

In my case that returns an IP address, which I then use the System.resolveIpAddress() function on to actually get the hostname.

Reply
0 Kudos
M3VM
Enthusiast
Enthusiast
Jump to solution

This script is not working with 6.0.2.1 orchestrator

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

That's right, that code is no longer expected to work as it is using a method that was part of the webviews which is now deprecated.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Here's another way to get the info.. requires editing the hosts file:

1. Edit /etc/hosts on your Orchestrator server

2. Add the FQDN and hostname to the line that starts 127.0.0.1: For example:

127.0.0.1 vro.vcoteam.lab vro localhost

3. Use the following in your scriptable tasks/actions:

var myHostname = System.resolveIpAddress("127.0.0.1");

System.log("vRO Hostname: "+ myHostname);

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos
M3VM
Enthusiast
Enthusiast
Jump to solution

Thanks Burke.. but wanted the ip address of the vco server?

Reply
0 Kudos
hferch
Contributor
Contributor
Jump to solution

Hello,

I think you can use also

var command = new Command("hostname");

command,execute(true);

var vROHostname = command.output;

cheers

Harald

slahy
Enthusiast
Enthusiast
Jump to solution

Another way to get the IP

netInterface = Config.getNetworkInterfaces();
System.log(netInterface.getValidBindInterfaces());

That will give you a list of valid binding ip's which will inclust the ip of the vRO.

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

This topic has come up again while I was working with a client this week.

I want to add a note here that the Config object in the last reply is now no longer valid in vRO 7+ so we must find other work-arounds until vRO provides a more friendly way of getting this info.

One of the most simple ways would be to create a configuration element that had an attribute for each: IPAddress and HostName, then it would be quite easy to retrieve at any time in scripts.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos