VMware Aria Automation Orchestrator

 View Only
Expand all | Collapse all

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

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

    Posted May 10, 2018 10:25 PM

    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



  • 2.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 10, 2018 10:57 PM

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



  • 3.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 11, 2018 08:04 AM

    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



  • 4.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 11, 2018 09:02 AM

    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



  • 5.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 11, 2018 09:23 AM

    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



  • 6.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 11, 2018 09:59 AM

    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



  • 7.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 11, 2018 10:12 AM

    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 :-D

    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



  • 8.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 11, 2018 10:18 AM

    Roll the dice one more time? :smileyhappy:

    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 :smileyhappy:



  • 9.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 11, 2018 10:39 AM

    Wow, there are always more roads that lead to Rome! :smileyhappy:

    Unfortunately it's the same here: localhost.

    No worries, thanks again...

    Ed



  • 10.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Broadcom Employee
    Posted May 12, 2018 10:52 AM

    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 :smileyhappy:



  • 11.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 14, 2018 09:12 AM

    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



  • 12.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 14, 2018 07:39 PM

    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 :smileyhappy:

    -Eoin



  • 13.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 15, 2018 07:23 AM

    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 ;-)



  • 14.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 15, 2018 12:57 AM

    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.



  • 15.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 15, 2018 07:25 AM

    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



  • 16.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 15, 2018 03:52 PM

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



  • 17.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 15, 2018 03:55 PM

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



  • 18.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted May 15, 2018 03:55 PM

    oops... I was logged in with my personal account!  :smileyhappy:



  • 19.  RE: Getting hostname/IP of current node in vRO cluster (using a workflow)

    Posted Jul 02, 2020 09:30 PM

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