Good day,
I am attempting to retrieve the Network configuration of all vApp networks to a vm( Explicitly the Gateway, Mask, and Name). My code worked in the 1.5 plugin, so I started digging. I can drill down to the vclVAppNetworkConfiguration Object, and even read its name, however if I try and do anything beneath that object, or even try a .toXml on the VAppNetworkConfiguration object, I get an error. below is my code so far. Any ideas?
Input: vCloud:vm
var vApp = vm.parent;//vApp.updateInternalState()var vdc = vApp.parent;var Org = vdc.parent;// Creation of two empty arraysNetworkNames = new Array();NetworksOut = new Array();var NetworkConfig = vApp.getNetworkConfigSection();//System.log(NetworkConfig.toXml());NetworkConfigs = NetworkConfig.networkConfig.enumerate()for(var i in NetworkConfigs){try{Configs = NetworkConfigs[i];System.log( i+" :: "+Configs)System.log("NetworkName: "+Configs.networkName)System.log(Configs.toXml())//This returns "null"for(var j in Configs){try{System.log(j + ":: "+Configs[j])//This returns " Property named '__iterator__' not found on object : VclVAppNetworkConfiguration "}catch(ex){continue}}
Try this (untested code). It gets the network name and tries to get what is under a single or multiple ip scopes.
var networkConfigSection = vApp.getNetworkConfigSection();
var networkConfigs = networkConfigSection.networkConfig.enumerate();
for each(var networkConfig in networkConfigs){
System.log("NetworkName: "+networkConfig.networkName);
if (networkConfig.ipScope != null) {
System.log("gateway: "+networkConfig.ipScope.gateway);
System.log("netmask: "+networkConfig.ipScope.netmask);
}
var ipScopes = networkConfig.ipScopes;
if (ipScopes != null) {
var ipScopeArray = ipScopes.ipScope.enumerate();
for each(var ipScope in ipScopeArray){
System.log("gateway: "+ipScope.gateway);
System.log("netmask: "+ipScope.netmask);
}
}
}
Thanks Christophe,
This code retrievs the names of the Networks, but nothing else. The Server.log shows the following during run
2013-03-04 08:05:42.549-0700 WARN [DynamicWrapper] Property named 'ipScope' not found on object : VclVAppNetworkConfiguration2013-03-04 08:05:42.549-0700 WARN [DynamicWrapper] Property named 'ipScope' not found on object : VclVAppNetworkConfiguration2013-03-04 08:05:42.549-0700 WARN [DynamicWrapper] Property named 'ipScopes' not found on object : VclVAppNetworkConfiguration2013-03-04 08:05:42.549-0700 WARN [DynamicWrapper] Property named 'ipScopes' not found on object : VclVAppNetworkConfiguration
Are you sure the vApp has an ip scope with a gateway / netmask set ?
I cannot check but according to the following thread the code I wrote should be close enought : http://communities.vmware.com/thread/421824
all 5 networks attached to the vApp have a Gatewat / Mask associated with them. Some are VCNS devices, and some are external directly connected networks. From the vapp itself in the Native VCD interface, I can see the network specification of each of the networks( Greyed out)
Got it a different way :
var vAppNetworks = vApp.getVAppNetworks();
for each (var vAppNetwork in vAppNetworks) {
var configuration = vAppNetwork.configuration;
System.log(vAppNetwork.name);
var ipScopeArray = configuration.ipScopes.ipScope.enumerate();
for each(var ipScope in ipScopeArray){
System.log("gateway: "+ipScope.gateway);
System.log("netmask: "+ipScope.netmask);
}
}
That worked perfectly. Now my question is, Why couldnt we get to it the other way???
I am not sure why there are methods / properties to get this information from two different places. Maybe for legacy / compatibility but then it is creating some confusion. Maybe someone with more knowledge on the vCloud API will have the answer.
Christophe.