In one of my previous posts I showed you the vRO action to find network card by its MAC address. Today is the time to create vRO workflow to remove the card with the specific MAC addressThis action I created because I really needed one time to create a workflow to delete a network interface from VM, as VM has more than one interface, the best way to have it unique is to do this with MAC address. Of course such workflow is not available by default in vRO so I had to create it. As it had to be developed quickly, so there is no data validation implemented. If anyone would like to reuse it, I strongly encourage you to do the implement data validation
Workflow will take 2 input values
- VM of type VC:VirtualMachine
- macAddress, type string
Basically it’s pretty easy. At the beginning I’m making use of an action I presented in previous port. Action returns a value of “any” type – which in fact is a “device” type or “null” if card is not found. Then I’m using a “Custom decision” and I check if the returned value is not “null”
So if the returned value is “null” I’m just displaying information that no network card was found with provided MAC address.
If value returned from action is not “null”, I have a scriptable task to remove device returned from the action.
The scriptable task will take 2 input values : networkCard of “Any” type, vm of “VC:VirtualMachine” type and it will return one value of type “VC:Task”
The code for the scriptable task is as follows
var managedObject = vm
var spec = new VcVirtualMachineConfigSpec();
System.log("Removing network for the virtual machine : " + vm.name)
System.log("Network card MAC address : " + networkCard.macAddress )
System.log("Network card VM device key : " + networkCard.key )
var deviceChange = new VcVirtualDeviceConfigSpec();
deviceChange.operation = VcVirtualDeviceConfigSpecOperation.remove;
deviceChange.device = networkCard
var arrDeviceChange = new Array()
spec.deviceChange = arrDeviceChange;
task = managedObject.reconfigVM_Task(spec);
So except displaying some information, the general code is to prepare a device configuration specification and finally create a virtual machine task to apply prepared configuration.
Last step in this workflow is built-in action to wait till the task returned from “Scriptable task” is finished.