VMware Cloud Community
Subnet88
Enthusiast
Enthusiast

Unable to parse objects beneath vclVAppNetworkConfiguration VCD 5.1

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 arrays
NetworkNames =  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}
}

0 Kudos
7 Replies
cdecanini_
VMware Employee
VMware Employee

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

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
0 Kudos
Subnet88
Enthusiast
Enthusiast

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 : VclVAppNetworkConfiguration
2013-03-04 08:05:42.549-0700 WARN  [DynamicWrapper] Property named 'ipScope' not found on object : VclVAppNetworkConfiguration
2013-03-04 08:05:42.549-0700 WARN  [DynamicWrapper] Property named 'ipScopes' not found on object : VclVAppNetworkConfiguration
2013-03-04 08:05:42.549-0700 WARN  [DynamicWrapper] Property named 'ipScopes' not found on object : VclVAppNetworkConfiguration
0 Kudos
cdecanini_
VMware Employee
VMware Employee

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

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
0 Kudos
Subnet88
Enthusiast
Enthusiast

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)

0 Kudos
cdecanini_
VMware Employee
VMware Employee

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

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
0 Kudos
Subnet88
Enthusiast
Enthusiast

That worked perfectly. Now my question is, Why couldnt we get to it the other way???

0 Kudos
cdecanini_
VMware Employee
VMware Employee

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.

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
0 Kudos