VMware Cloud Community
EdSp
Enthusiast
Enthusiast

Getting hostname/IP of current node in vRO cluster (using a workflow)

Hi,

I am trying to get the hostname (fqdn) or IP of the current node in the vRO cluster that is running my workflow.

I looked for example at using a REST call to the vRO Control Center to use the api/cluster/status url, but I am not getting the expected response. Instead it looks like I get the html that seems to be for logging in...

Any hints appreciated,

Ed

Tags (2)
18 Replies
daphnissov
Immortal
Immortal

Interesting. What would your use case be for extracting this information?

Reply
0 Kudos
EdSp
Enthusiast
Enthusiast

Hi,

We are setting up SSH access between the vRO node(s) and other servers in the infrastructure. We keep track of the current SSH keys so that when certain servers are added, we can just pickup the SSH keys (that are stored in an element) and bring them to the new server.

Also, this is existing code, where the hostname (or IP) would previously have been passed in by a plug-in. This will no longer be the case, so we need to find an alternative way.

Thanks,
Ed

Reply
0 Kudos
eoinbyrne
Expert
Expert

A complete dirty hack but it will get you a value for the current node

Use this method to get an event URL for the current node

it will look like

https://<nodename or IP address of current node>.......

You can extract or parse out the hostname (or IP depending on config) from the returned value.

var eventURL = System.customEventUrl("fakeEvent", true);

You could then use either of the following to complete the IP/Hostname pair

var ipAddress = System.resolveHostName(hostname)

or

var hostname = System.resolveIpAddress(ipAddress)

depending on which value you got back from the first call

-HTH

Reply
0 Kudos
EdSp
Enthusiast
Enthusiast

Tried it, but gives back 0.0.0.0 as shown below:

[2018-05-11 05:19:25.934] [I] eventURL=https://0.0.0.0:8281/vmware-vmo-webcontrol/SendCustomEvent?EventName=fakeEvent

Thanks

Reply
0 Kudos
eoinbyrne
Expert
Expert

Interesting - I expected that to give the network IP or hostname of the node there since that method is intended to be used for external event triggers.... Maybe a config issue or a bug in vRO? Which version are you using btw?

OK, next option would be the Command script object?

vRO API Explorer by Dr Ruurd and Flores of ITQ

The class here will execute the given command string in a shell on the current node. You could use this to use the shell command 'hostname' to get the node name? You may need to modify the configuration of the vRO node (maybe.. can't remember but I think you need to modify a command whitelist for this to work - perhaps one of the VMware folks can confirm?)

Anyway, code looks like this (not tested this at all!)

var hostnameCommand = new Command("hostname");

hostnameCommand.execute(false);

var cmdOuput = hostnameCommand.output;

the value in "cmdOutput" there *should* be the result of 'hostname' in the shell ---> the name of the node

-HTH

EdSp
Enthusiast
Enthusiast

Thanks for this suggestion! However this config option is set to false in our solution and I can't just change that to true. This system is meant for customers :-}

Yikes! This is harder than I expected for such a seemingly innocent question 😄

I can find the node names by looking at all VC:VirtualMachines in the vRO inventory and doing a textual filter on the properties 'productVendor' and 'annotation', but that's not very robust and can't be a permanent solution...

Thanks again for your input!

Ed

Reply
0 Kudos
eoinbyrne
Expert
Expert

Roll the dice one more time? Smiley Happy

this one does work (at least on my test node here).

var f = new File("/tmp");

System.log(f.hostname);

The File object stores the name of the node on which a file is hosted.....

vRO API Explorer by Dr Ruurd and Flores of ITQ

On my test node here (running in workstation) I get this result.

[2018-05-11 11:14:01.233] [I] localhost

It might be worth a try on your setup just to see what it does in a properly named & configured node?

I'll be quiet after this, I promise Smiley Happy

Reply
0 Kudos
EdSp
Enthusiast
Enthusiast

Wow, there are always more roads that lead to Rome! Smiley Happy

Unfortunately it's the same here: localhost.

No worries, thanks again...

Ed

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

Check if the following works:

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

System.log("resolved address -> " + addr);

If the above doesn't work, and you don't mind getting your hands dirty, you can try to put up a small vRO plug-in to collect network interfaces' information using some Java code and expose it to scripting. Should be easier than it sounds Smiley Happy

EdSp
Enthusiast
Enthusiast

Hi Ilian,

Tried that, it gives back the vip name! :smileycry:

I also just found out that the Control Center cluster status REST call (when called from a workflow) does work in vRO 7.4 (not in 7.3), so maybe there is an opening...

Thanks!

Ed

Reply
0 Kudos
eoinbyrne
Expert
Expert

This approach works but requires updating the Rhino JS class shutter which is bit like the js-io-rights change needed for the Command processing in the previous suggestion. This works on my setup in which runs in Workstation (vApp on NAT network + client running on my laptop)

create the file below on the vApp filesystem

/etc/vco/app-server/rhino-shutter.txt

Put these lines into the file

java.net.*

java.io.*

java.lang.*

Edit this file

/etc/vco/app-server/vmo.properties

Add this line

com.vmware.scripting.rhino-class-shutter=rhino-shutter.txt

Bounce the app-server process

# service vco-server restart

Give the server a few minutes to become Active then start a client + execute the following in the JS script of a workflow

var baseAddress = (java.net.InetAddress).getLocalHost();

System.log(baseAddress.getHostAddress());

The IP of the server should be printed in the output

Right, finally leaving this alone, best of luck with all of it Smiley Happy

-Eoin

qc4vmware
Virtuoso
Virtuoso

I know this is crude and not dynamic in any way but over the years for a small amount of this sort of data that I can't seem to grab via a query I simply keep it in a configuration element labeled "Environment Variables" and write an action and/or workflow for retrieving what I need out of the config.

EdSp
Enthusiast
Enthusiast

Thanks Eoin, that is def an interesting to obtain the extra info! However, unfortunately we can't just change the config as this won't be an internal system.. I will keep this in my pocket though 😉

Reply
0 Kudos
EdSp
Enthusiast
Enthusiast

Yes, I think a configuration element for this kind of info is one way of doing this. It is practical, simple and straight-forward enough.

Thanks!

Ed

ectoplasm88
Contributor
Contributor

Cool... please mark my reply as helpful or solved.  Trying to level up here!

Reply
0 Kudos
EdSp
Enthusiast
Enthusiast

Sorry, but I don't see you (ectoplasm88) in the replies?

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso

oops... I was logged in with my personal account!  Smiley Happy

Reply
0 Kudos
kerya
Contributor
Contributor

I have similar or the same question. How to get uri of current server running workflow or even workflow run uri?

Reply
0 Kudos