I'm trying to write an Action in JavaScript that will fetch the IP address, prefix length, MAC address and Default Gateway IP address configured on a VM. With the exception of the Default Gateway IP address, I've been able to fetch all of the other information.
I've been trying to get the Default Gateway address using this line of code:
var gateway = vm.guest.ipStack.ipRouteConfig.ipRoute.gateway.ipAddress;
According to the API Explorer:
This produces the following error:
TypeError: Cannot read property "ipRoute" from undefined
Should the above work? Have I missed something?
Using PowerCLI outside of VMware Aria Orchestrator, I can get the Default Gateway IP address using:
$VM = Get-VM <VMName>
$VM.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute.Gateway.IpAddress
Hey,
This should solve your problem. 'vm' is a 'VC:VirtualMachine' object.
var a = vm.guest.net;
a.forEach(function (element) {
System.log("MAC: " + element.macAddress);
System.log("IP Address: " + element.ipConfig.ipAddress[0].ipAddress);
System.log("Prefix: " + element.ipConfig.ipAddress[0].prefixLength.toString());
});
var ipStack = vm.guest.ipStack;
ipStack.forEach(function (element) {
System.log("Gateway:" + element.ipRouteConfig.ipRoute[0].gateway.ipAddress)
});
PS. Of course, if you have more than one NIC or IP, you need to loop over 'ipAddress' / 'ipRoute'
Hey,
This should solve your problem. 'vm' is a 'VC:VirtualMachine' object.
var a = vm.guest.net;
a.forEach(function (element) {
System.log("MAC: " + element.macAddress);
System.log("IP Address: " + element.ipConfig.ipAddress[0].ipAddress);
System.log("Prefix: " + element.ipConfig.ipAddress[0].prefixLength.toString());
});
var ipStack = vm.guest.ipStack;
ipStack.forEach(function (element) {
System.log("Gateway:" + element.ipRouteConfig.ipRoute[0].gateway.ipAddress)
});
PS. Of course, if you have more than one NIC or IP, you need to loop over 'ipAddress' / 'ipRoute'
Thanks that worked perfectly 🙂