VMware Cloud Community
pabloramos
Enthusiast
Enthusiast
Jump to solution

matching on a portgroup

If provided the VC:ClusterComputeResource, does someone have existing code that could retrieve all available DistributedVirtual port groups? I thought about using the network_DistributedVirtualPortGroup attribute to return an array of DistributedVirtualPortGroup values and matching on vland ID. Can't seem to get it to work.

Reply
0 Kudos
1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

See if this helps: input is "cluster" (VC:ClusterComputeResource)

var dvPortGroups = cluster.network_DistributedVirtualPortgroup;

System.debug("DVPortgroups: "+dvPortGroups.length);

for each (pg in dvPortGroups){

    System.debug("PG Name: "+pg.name);

    System.debug(pg.config.defaultPortConfig.vlan);

    if(pg.config.defaultPortConfig.vlan instanceof VcVmwareDistributedVirtualSwitchVlanIdSpec){

        System.debug("VLAN: "+ pg.config.defaultPortConfig.vlan.vlanId);

    }

    System.debug("dvSwitch: "+pg.config.distributedVirtualSwitch.name);

}

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 vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

Reply
0 Kudos
2 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

See if this helps: input is "cluster" (VC:ClusterComputeResource)

var dvPortGroups = cluster.network_DistributedVirtualPortgroup;

System.debug("DVPortgroups: "+dvPortGroups.length);

for each (pg in dvPortGroups){

    System.debug("PG Name: "+pg.name);

    System.debug(pg.config.defaultPortConfig.vlan);

    if(pg.config.defaultPortConfig.vlan instanceof VcVmwareDistributedVirtualSwitchVlanIdSpec){

        System.debug("VLAN: "+ pg.config.defaultPortConfig.vlan.vlanId);

    }

    System.debug("dvSwitch: "+pg.config.distributedVirtualSwitch.name);

}

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 vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos
pabloramos
Enthusiast
Enthusiast
Jump to solution

thanks Burke, once again you were great help. I modified your code little to handle our specific environment. I pass in a number input for the vlanID and match on the dvPG.name to get me the value I need. I then place the value in an output parameter VC:DistributedVirtualPortgroup called networks to use in my subsequent cloning workflow.

var dvPortGroups = cluster.network_DistributedVirtualPortgroup; 

//System.debug("DVPortgroups: "+dvPortGroups.length); 

for each (pg in dvPortGroups){

   if (pg.name.match(vlanID)) {

          networks_str = pg.name;

          networks = pg;

   } 

System.log("This is the value for dvPG resource:" + networks);

Reply
0 Kudos