VMware Cloud Community
mhhdaniel
Contributor
Contributor

Converting string type to VC:DistributedVirtualPortgroup type

I am having problems creating a wrapper to convert a string (property value passed from vRA) to a VC:DistributedVirtualPortgroup.

I am able to get all the current portgroups in an array but I'm not able to get the correct object based on the name property.

This is what I have currently

var dvPortgroupName = "vxw-dvs-38-virtualwire-113-sid-5003";

var dvPortgroups = VcPlugin.getAllDistributedVirtualPortgroups();

for each (pg in dvPortgroups){
if (pg.name == dvPortgroupName){
  System.log("dvPortgroupName found!");
} else {
  System.log("dvPortgroupName not found!");
}
}

I am able to get the results that I want if I try creating a wrapper using another object like 'datastore'

var datastoreName = "vsanDatastore";

var dataStores = VcPlugin.getAllDatastores();

for each (ds in dataStores){

if (ds.name == datastoreName){

  System.log("datastore name found!");

} else {

  System.log("datastore name not found!");

}

}

Any help or guidance would be greatly appreciated.

Loren E. Daniel Cloud Platform Specialist - Tx Dell EMC | CPSD Mobile +1-832-372-9280 Loren.Daniel@Dell.com Dell | VMware | Pivotal | EMC | Virtustream | RSA
Reply
0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee

Hi,

The name property of the distributed virtual portgroup object is actually its display name which includes both portgroup and switch name in the format portgroupname (switchname)

So in your case the name you'd want to compare against a portgroup name looking something like vxw-dvs-38-virtualwire-113-sid-5003 (xyz-switch)

What you can try is to change the if condition and instead of pg.name use pg.config.name . Note that this could be ambiguous in some cases eg. when you have 2 or more portgroups with the same name in different switches.

mhhdaniel
Contributor
Contributor

Thanks llian, that should work okay. The portgroups will always be created on the same dvs for this particular environment so I should not have any issues.

Loren E. Daniel Cloud Platform Specialist - Tx Dell EMC | CPSD Mobile +1-832-372-9280 Loren.Daniel@Dell.com Dell | VMware | Pivotal | EMC | Virtustream | RSA
Reply
0 Kudos