VMware Cloud Community
orian
Hot Shot
Hot Shot
Jump to solution

Add Network from VDS

Hi,

I try to add a network adapter to a new VM from Virtual Distributed Switch with the orchestrator.

However, in the end the network adapter is added but the status is disconnected.

When I add it manually, it works fine.

I use this code:

var vmConfigSpec = new VcVirtualMachineConfigSpec();   

var deviceConfigSpec = new VcVirtualDeviceConfigSpec();   

deviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.add; 

deviceConfigSpec.device = new VcVirtualVmxnet3(); 

deviceConfigSpec.device.key = -100; 

deviceConfigSpec.device.backing = new VcVirtualEthernetCardNetworkBackingInfo();  

deviceConfigSpec.device.backing.deviceName = adapterNetwork.name; 

deviceConfigSpec.device.connectable = new VcVirtualDeviceConnectInfo(); 

deviceConfigSpec.device.connectable.startConnected = true; 

deviceConfigSpec.device.connectable.allowGuestControl = true; 

deviceConfigSpec.device.connectable.connected = true; 

deviceConfigSpec.device.controllerKey = 100; 

deviceConfigSpec.device.addressType = "generated"; 

deviceConfigSpec.device.wakeOnLanEnabled = true; 

 

vmConfigSpec.deviceChange = [deviceConfigSpec];   

 

try {   

  task = newVM.reconfigVM_Task(vmConfigSpec);

} catch (ex) {   

  System.warn("Error while reconfiguring VM: " + ex);   

when I use the same code with a network not from VDS is works fine.

1 Solution

Accepted Solutions
filosmith
Enthusiast
Enthusiast
Jump to solution

Here's a snippet that should get you going:

spec.deviceChange[0].device.deviceInfo.summary = dvsUuid;

spec.deviceChange[0].device.backing = new VcVirtualEthernetCardDistributedVirtualPortBackingInfo();

spec.deviceChange[0].device.backing.port = new VcDistributedVirtualSwitchPortConnection();

spec.deviceChange[0].device.backing.port.switchUuid = dvsUuid;

spec.deviceChange[0].device.backing.port.portgroupKey = dpg.key;

spec.deviceChange[0].device.connectable = new VcVirtualDeviceConnectInfo();

spec.deviceChange[0].device.connectable.startConnected = true;

spec.deviceChange[0].device.connectable.allowGuestControl = true;

spec.deviceChange[0].device.connectable.connected = true;

View solution in original post

4 Replies
orian
Hot Shot
Hot Shot
Jump to solution

any idea?

0 Kudos
filosmith
Enthusiast
Enthusiast
Jump to solution

Here's a snippet that should get you going:

spec.deviceChange[0].device.deviceInfo.summary = dvsUuid;

spec.deviceChange[0].device.backing = new VcVirtualEthernetCardDistributedVirtualPortBackingInfo();

spec.deviceChange[0].device.backing.port = new VcDistributedVirtualSwitchPortConnection();

spec.deviceChange[0].device.backing.port.switchUuid = dvsUuid;

spec.deviceChange[0].device.backing.port.portgroupKey = dpg.key;

spec.deviceChange[0].device.connectable = new VcVirtualDeviceConnectInfo();

spec.deviceChange[0].device.connectable.startConnected = true;

spec.deviceChange[0].device.connectable.allowGuestControl = true;

spec.deviceChange[0].device.connectable.connected = true;

orian
Hot Shot
Hot Shot
Jump to solution

Ok, now when I hard coded the dvs.uuid and the dpg.key, it works fine.

How can I retrieve the switch.uuid if I have the dpg?

0 Kudos
orian
Hot Shot
Hot Shot
Jump to solution

dpg.config.distributedVirtualSwitch.uuid

0 Kudos