VMware Cloud Community
slahy
Enthusiast
Enthusiast

how to get object created by addDVPortgroup_Task

Hi,

I am trying to get the object created (dvportgroup object) by the addDVPortgroup_Task.

dvPortgroupCreationTask = dvSwitch.addDVPortgroup_Task(specArray);

Is there anyway of getting the port group object without searching the switch for the name of the new port group.

Is there any parameter of the this task that contains the object or the moref of the object.

The reason I am trying to do it this way is I have over 200 portgroups and growing and this operation happens several times a day. So the less time spent searching for port groups the better.

Thanks.

Sean

0 Kudos
3 Replies
marcseitz
Enthusiast
Enthusiast

Hi Sean,

I didn't try it, but you'll get back a VCTask Object.

So wait until the Task is finished and then try to go to the reference Object you'll get back:

dvPortgroupCreationTask = dvSwitch.addDVPortgroup_Task(specArray);

System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(dvPortgroupCreationTask,<progress>,<pollRate>)

myNewDvPortGroup = dvPortGroupCreationTask.reference;

This code is just an example - Didn't tested it!

Regards,

Mar

0 Kudos
slahy
Enthusiast
Enthusiast

HI Mar,

Thanks for the reply.

The dvPortGroupCreationTask.reference seems to return a VcManagedObjectReference to the task not the dvPortGroup. When I use the following code I get the following.

Value :  task-5595

Type : Task

dvPortgroupCreationTask = dvSwitch.addDVPortgroup_Task(specArray);

System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(dvPortgroupCreationTask,true,1) ;

myNewDvPortGroup = dvPortgroupCreationTask.reference; 

System.log("object value " + myNewDvPortGroup.value );

System.log("object type " + myNewDvPortGroup.type );

Sean

0 Kudos
marcseitz
Enthusiast
Enthusiast

Hey Sean,

sorry - my mistake!

That's the right one:

dvPortgroupCreationTask = dvSwitch.addDVPortgroup_Task(specArray);

System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(dvPortgroupCreationTask,true,1) ;

myNewDvPortGroup = dvPortgroupCreationTask.info.referece;

System.log( "New Portgroup: " + dvPortgroupCreationTask.info.refereceName);

I've tested this with a Task against a VCVirtualMachine Object - Was working fine!

Regards,

Marc

0 Kudos