VMware Cloud Community
ChrisRayDekraSE
Contributor
Contributor
Jump to solution

VMware Aria Orchestrator - Fetch Guest OS NIC Default Gateway IP

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:

  • The “VcVirtualMachine” object should have a property called guest which contains the “VcGuestInfo” object
  • The “VcGuestInfo” object should have a property called ipStack which contains a “VcGuestStackInfo” object
  • The “VcGuestStackInfo” object should have a property called ipRouteConfig which contains a “VcNetIpRouteConfigInfo” object
  • The “VcNetIpRouteConfigInfo” object should have a property called ipRoute which contains a “VcNetIpRouteConfigInfoIpRoute” object
  • The “VcNetIpRouteConfigInfoIpRoute” object should have a property called gateway which contains a VcNetIpRouteConfigInfoGateway object
  • The “VcNetIpRouteConfigInfoGateway” object should have a property called ipAddress which is the default gateway address I want to fetch

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

0 Kudos
1 Solution

Accepted Solutions
WhiteForEver
Enthusiast
Enthusiast
Jump to solution

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

 

Screenshot 2024-02-06 at 19.49.00.png

PS. Of course, if you have more than one NIC or IP, you need to loop over 'ipAddress' / 'ipRoute'



----------------------------------------------------------
Thank you for your feedback regarding my response.
If it has successfully resolved your issue, kindly mark it as RESOLVED

Take a look at my blog below.
https://www.clouddepth.com

View solution in original post

2 Replies
WhiteForEver
Enthusiast
Enthusiast
Jump to solution

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

 

Screenshot 2024-02-06 at 19.49.00.png

PS. Of course, if you have more than one NIC or IP, you need to loop over 'ipAddress' / 'ipRoute'



----------------------------------------------------------
Thank you for your feedback regarding my response.
If it has successfully resolved your issue, kindly mark it as RESOLVED

Take a look at my blog below.
https://www.clouddepth.com
ChrisRayDekraSE
Contributor
Contributor
Jump to solution

Thanks that worked perfectly 🙂

0 Kudos