Quantcast
Channel: VMware Communities : Discussion List - vRealize Orchestrator
Viewing all articles
Browse latest Browse all 6251

Remove Network adapter - Error

$
0
0

Hi,

 

I use the following code in order to remove all the network adapters connected to specific virtual machine.

Sometime the workflow finishes with no error, but most of the times I receive the following error in the vCenter: Invalid configuration for device '1'.

What can I change in my code?

 

var nicsToRemove = []; 

 

for each (var device in vm.config.hardware.device) {   

  if (device instanceof VcVirtualVmxnet   

   || device instanceof VcVirtualVmxnet2   

   || device instanceof VcVirtualVmxnet3 

   || device instanceof VcVirtualE1000   

   || device instanceof VcVirtualPCNet32   

   || device instanceof VcVirtualEthernetCard) {

    // Here you can add some custom logic to decide whether to remove the network adapter 

    // This sample code will remove all network adapters

      nicsToRemove.push(device);   

  } 

}

 

var vmConfigSpec = new VcVirtualMachineConfigSpec();

var deviceChanges = []; 

var deviceConfigSpec = new VcVirtualDeviceConfigSpec() ;  

 

System.log(vm.name);

 

for each (var nic in nicsToRemove) {

  deviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.remove;

  deviceConfigSpec.device = nic;

  System.log("The nic is: " + nic.connectable.status);

 

  vmConfigSpec.deviceChange = deviceChanges;

    if (nic.connectable.status == "ok"){

  deviceChanges.push(deviceConfigSpec);

  } 

}

 

try {   

  myTask = vm.reconfigVM_Task(vmConfigSpec);   

} catch (ex) {

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

}


Viewing all articles
Browse latest Browse all 6251

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>