BillStreet00
Enthusiast
Enthusiast

Cannot read property "distributedVirtualSwitch" from undefined

Our port groups all have name like LOC-10.10.1.0/24.  When I read them into vRO it becomes LOC-10.10.1.0%2f24.  I am able to fix that error but I still get an error that makes me think dvPortGroup is undefined.  I added a System.log command and verifed that dvPortGroup contains the correct string.  Anyone run into this error before?

Code

var tmpNic = nic.network.split('%2f');

dvPortGroup = tmpNic[0]+"/"+tmpNic[1];

var dvsPortConnection = new VcDistributedVirtualSwitchPortConnection();

var dvSwitch = VcPlugin.convertToVimManagedObject(dvPortGroup, dvPortGroup.config.distributedVirtualSwitch);

dvsPortConnection.switchUuid = dvSwitch.uuid;

dvsPortConnection.portgroupKey = dvPortGroup.key;

Error

[2017-11-21 08:25:29.238] [E] Error in (Workflow:id Nic / Scriptable task (item1)#70) TypeError: Cannot read property "distributedVirtualSwitch" from undefined

[2017-11-21 08:25:29.243] [E] Workflow execution stack:

***

item: 'id Nic/item1', state: 'failed', business state: 'null', exception: 'TypeError: Cannot read property "distributedVirtualSwitch" from undefined (Workflow:id Nic / Scriptable task (item1)#70)'

workflow: 'id Nic' (37c14e0c-3d03-4dd6-b8a3-dd37916f7cba)

|  'input': name=vm type=VC:VirtualMachine value=dunes://service.dunes.ch/CustomSDKObject?id='p10dcvcenterha%2Cid:vm-5898'&dunesName='VC:VirtualMachine'

|  'no outputs'

|  'no attributes'

*** End of execution stack.

0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee

On the second line of your code, dvPortGroup variable gets assigned some string value.

On the fourth line, you are using it in the expression dvPortGroup.config.distributedVirtualSwitch. So you are trying to read property config from a string variable (which is of course undefined as strings in general have no such property), and then you are trying to read the property distributedVirtualSwitch from this undefined value, hence you get the error.

0 Kudos
BillStreet00
Enthusiast
Enthusiast

I am pulling the value from vm.config.hardware.device then looking for device instance of VcVirtualE1000.  The property am using is nic.network but the value has %2f instead of slash notation hence splitting the name.  My goal is to record the IP information I gathered earlier and create a new vmxnet3 nic. I guess that leads me to two questions.  One, am I using the correct object if so how can I rename it?  Two, If I am not using the correct object can you point me in the direction I need to look to pull the information in?

Thanks

0 Kudos