Quantcast
Channel: VMware Communities : Discussion List - VMware {code}
Viewing all articles
Browse latest Browse all 2738

Clone VM from TPL, Change DVS Backing - Not allowed in current state

$
0
0

Hi all, having some issues with the cloning of a template and modifying the existing virtual network device on the way through. I am getting the error "The operation is not allowed in the current state"

I am using ApplyStorageDrsRecommendation_Task due to us using SDRS clusters - wondering if there is something specific here i need to do differently when not using the CloneVM task?

Basic code for changing the backing below;

The configSpec object is a VirtualMachineConfigSpec which is attached to the VirtualMachineCloneSpec.config

I am finding the "networkDevice" object by iterating the VirtualMachineConfigInfo.hardware.device - FYI getting this via (VirtualMachineConfigInfo)cb.getServiceUtil().GetDynamicProperty(vmRef, "config");, vmRef is found via _service.FindByInventoryPath which is the template path.

            VirtualDeviceConfigSpec[] devSpec = new VirtualDeviceConfigSpec[0];
            configSpec.deviceChange = new VirtualDeviceConfigSpec[1];
            configSpec.deviceChange[0] = new VirtualDeviceConfigSpec();
            configSpec.deviceChange[0].operation = VirtualDeviceConfigSpecOperation.edit;
            configSpec.deviceChange[0].device = networkDevice;
 
 
            VirtualEthernetCardDistributedVirtualPortBackingInfo nicBack = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
            nicBack.port = new DistributedVirtualSwitchPortConnection();
            nicBack.port.switchUuid = dvsUUID;
            nicBack.port.portgroupKey= phKey;
 
            configSpec.deviceChange[0].device.backing = nicBack;
 
            configSpec.deviceChange[0].device.connectable = new VirtualDeviceConnectInfo();
            configSpec.deviceChange[0].device.connectable.startConnected = true;
            configSpec.deviceChange[0].device.connectable.allowGuestControl = true;
            configSpec.deviceChange[0].device.connectable.connected = true;

           VirtualDeviceConfigSpec[] devSpec = new VirtualDeviceConfigSpec[0];

            configSpec.deviceChange = new VirtualDeviceConfigSpec[1];

            configSpec.deviceChange[0] = new VirtualDeviceConfigSpec();

            configSpec.deviceChange[0].operation = VirtualDeviceConfigSpecOperation.edit;

            configSpec.deviceChange[0].device = networkDevice;

            VirtualEthernetCardDistributedVirtualPortBackingInfo nicBack = new VirtualEthernetCardDistributedVirtualPortBackingInfo();

            nicBack.port = new DistributedVirtualSwitchPortConnection();

            nicBack.port.switchUuid = dvsUUID;

            nicBack.port.portgroupKey= pgKey;

 

            configSpec.deviceChange[0].device.backing = nicBack;

 

            configSpec.deviceChange[0].device.connectable = new VirtualDeviceConnectInfo();

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

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

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

 

Am i meant to be adding the device changes to something else such as the StoragePlacementResult?

I have also tried a simple remove of the NIC also which gives the same not allowed in current state error. 

Any help/direction/things to trial would be much appreciated!


Viewing all articles
Browse latest Browse all 2738

Trending Articles