virtualportal
Enthusiast
Enthusiast

Get VM external IP from vCloud

I am looking to get the External IP of a Specific VM in a vApp.

The VM is connected to a vApp Network which is routed. In the GUI I can see that by default every VM in the vApp gets an external address and can see it on the GUI.

I have also found the method externalIP on  the scripting class VclNatOneToOneVmRule, in the "Search API" function of vCO. I am just not sure how to ensure that I am specifying the correct VM and how to go about getting this information.

I currently have the following information avaialble to run the query:

vm id

Vcloud:vApp object

Vcloud:Nm object

I can probably get more but I am guessing i need to find the vApp network and then find the rules and filter on VMid or something. I couldnt find a scripting class for Vcloud:VappNetwork.

Any help would be greatly appreciated.

Thanks

0 Kudos
2 Replies
cdecanini_
VMware Employee
VMware Employee

Hi,

Try this:

vm.updateInternalState();
var externalIps = new Array();
var networkConnectionSection = vm.getNetworkConnectionSection();
var networkConnections = networkConnectionSection.networkConnection.enumerate();
for each (var networkConnection in networkConnections) {
    var externalIp = networkConnection.externalIpAddress;
    if (externalIp != null) {
        externalIps.push(externalIp);
    }
}
return externalIps;

Christophe.

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
efelton
Contributor
Contributor

Hello Christophe

Thank you for this code example.  I have used to to get the external IP address of a VM in a vApp.

Here is my final javascipt code that inside a larger workflow that clones a vApp and then returns the IP address of the VMs.

IPaddresses = [];

internalVAppChildren = internalVapp.getChildrenVms();

internalVAppChildrenNumber = internalVAppChildren.length;

System.log("Number of VMs in VApp: "  + internalVAppChildrenNumber);

for (var i=0; i < internalVAppChildren.length; i++) {

  System.log("i: "+ i);

  internalTheVM = internalVAppChildren[i];

  

  System.log("VM: " +internalTheVM);

  System.log("VM name: " +internalTheVM.name);

  System.log("VM description: " +internalTheVM.description);

  var networkConnectionSection = System.getModule("com.vmware.library.vCloud.operation").getNetworkConnectionSectionVM(internalTheVM); 

  System.log("networkConnectionSection: "+ networkConnectionSection);

  System.log("networkConnectionSection.length: "+ networkConnectionSection.length);

  var networkConnections = networkConnectionSection.networkConnection.enumerate(); 

  for each (var networkConnection in networkConnections) { 

  var externalIp = networkConnection.externalIpAddress; 

     if (externalIp != null) { 

  IPaddresses.push(externalIp);

  System.log("externalIp "+ externalIp);

    } 

  }//For each (var networkConnection in networkConnections)

}//for (var i=0; i < internalVAppChildren.length; i++)

0 Kudos