Retrieve the external IP of a vCenter Orchestrator server

Recently I had to understand what’s the external IP of the server that my vCO was deployed on. Since I did not had SSH access to the machine I wondered how I could do this. It turned out to be as simple as few lines of JavaScript in a vCO action. I used the HTTP REST plugin to make a get request to http://ipecho.net/plain and extract the response.

The code (with dynamically adding and removing REST hosts) :

var host = new RESTHost("IP echo");
host.url = "http://ipecho.net/";

host = RESTHostManager.addHost(host);

try {
var response = host.createRequest("GET", "plain").execute();

RESTHostManager.removeHost(host.id);

return response.contentAsString;
} catch (e) {
RESTHostManager.removeHost(host.id);

throw e;

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s