St0ked56
Contributor
Contributor

Get IP from vcloud:vm type

Jump to solution

Hi,

I am trying to retreive the IP from a NIC from a vcloud:VM type.  After deploying the VM I want to be able to send a confirmation email detailing certain information, with the IP being one.I have searched through the actions and tried multiple different ones and I can't seem to get the information I am looking for.  I am currently using the below script to try but receive this error "TypeError: Cannot read property "ipAddress" from null (Dynamic Script Module Name : getVMIp#4)

Script:

vm.updateInternalState();
var nicIP = null;
var networkConnectionSection = vm.getNetworkConnectionSection();
System.log("IP is: " + networkConnectionSection.networkConnection[0].ipAddressAllocationMode);
nicIP = networkConnectionSection.networkConnection[0].ipAddress;
return nicIP;
This is the getVmIp Action from "com.vmware.pso.library.com"
0 Kudos
1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee

I wrote this script but it seems to be the one for vCloud 1.0

Try this one:

vm.updateInternalState();
var networkConnectionSection = vm.getNetworkConnectionSection();
//System.log("IP is: " + networkConnectionSection.networkConnection.enumerate()[0].ipAddress);
return networkConnectionSection.networkConnection.enumerate()[0].ipAddress;

In vCloud 1.0 an array was returned, in vCloud 1.5 an object which is a list of objects requiring using the enumerate() method.

In both scripts I am assuming the IP is in the first network connection.

If this still does not work you can add:

System.log(networkConnectionSection.toXml());

Then you can then copy paste in an XML editor to check this VM network configuration and where the IP is located.

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

View solution in original post

0 Kudos
4 Replies
cdecanini_
VMware Employee
VMware Employee

I wrote this script but it seems to be the one for vCloud 1.0

Try this one:

vm.updateInternalState();
var networkConnectionSection = vm.getNetworkConnectionSection();
//System.log("IP is: " + networkConnectionSection.networkConnection.enumerate()[0].ipAddress);
return networkConnectionSection.networkConnection.enumerate()[0].ipAddress;

In vCloud 1.0 an array was returned, in vCloud 1.5 an object which is a list of objects requiring using the enumerate() method.

In both scripts I am assuming the IP is in the first network connection.

If this still does not work you can add:

System.log(networkConnectionSection.toXml());

Then you can then copy paste in an XML editor to check this VM network configuration and where the IP is located.

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

View solution in original post

0 Kudos
St0ked56
Contributor
Contributor

Thank you for the help.  This worked and I am now able to see the IP in the variable.  I have run into another small problem regarding the same issue however.  I want to store the IP into array/string.  My setup is:

Your script action:

Out variable = actionResultIP (This receives the correct IP)

My Scriptable task:

var i = IPCounter;
ipAddressArray[i] = actionResultIP;

Any idea why I can't pass the actionResultIP variable into the array?  I have also tried to just pass the string variable(actionResultIP) to another string variable (not an array) and this did not work either.

Thanks again for you help!

0 Kudos
cdecanini_
VMware Employee
VMware Employee

I am not sure how you created your array. I would write it this way:

var ipAddressArray = new Array();

ipAddressArray.push(actionResultIP);

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

THank you, that solved my problem!

0 Kudos