VMware Aria Automation Orchestrator

 View Only
  • 1.  Code to delete vNIC on VM during VM provisioning in Orchestrator

    Posted May 07, 2025 12:04 PM

    Hi,

    Does anyone have code to delete a vNIC on a VM during VM provisioning in Orchestrator. Our templates contain multiple vNICs to accommodate various builds. Some builds do not require the additional vNICs and would like them removed during the provisioning process in Orchestrator. 

    Thanks!

    Tom



  • 2.  RE: Code to delete vNIC on VM during VM provisioning in Orchestrator

    Posted May 07, 2025 05:27 PM

    Hi,

    I think I have something similar. If it's not urgent, give me some time. I will try to find it.



    ------------------------------
    If you find the answer helpful, please click on the RECOMMEND button.

    Please visit my blog to get more information: https://clouddepth.com
    ------------------------------



  • 3.  RE: Code to delete vNIC on VM during VM provisioning in Orchestrator

    Posted May 08, 2025 02:45 AM

    So,

    this is a minimum working code:

    var spec = new VcVirtualMachineConfigSpec();
    var deviceChange = new Array();
    deviceChange[0] = new VcVirtualDeviceConfigSpec();
    deviceChange[0].device = new VcVirtualVmxnet3();
    deviceChange[0].device.key = 4000;
    deviceChange[0].operation = VcVirtualDeviceConfigSpecOperation.remove;
    spec.deviceChange = deviceChange;
    spec.virtualNuma = new VcVirtualMachineVirtualNuma();
    vm.reconfigVM_Task(spec);

    A few comments:

    1. `vm` - is a VcVirtualMachine object.
    2. This code will work only if type of the NIC is VMXNET3.
    3. This code will work only if there is only one NIC.

    To make this code more generic, it is worth to cover:

    1. Convert this code into a function/s.
    2. All NIC types.
    3. Check if there are multiple NICs. If so, remove the required one by getting first proper deviceController ID and setting it into `deviceChange[0].device.controllerKey = XXX`. The same for `deviceChange[0].device.key`.

    If there is only one NIC:

    1. default `deviceChange[0].device.key` is 4000.
    2. default `device.controllerKey` is 100.

    PS. If `device.controllerKey` is not provided, it will always remove the first NIC.

    Please let me know if you need more details.



    ------------------------------
    If you find the answer helpful, please click on the RECOMMEND button.

    Please visit my blog to get more information: https://clouddepth.com
    ------------------------------



  • 4.  RE: Code to delete vNIC on VM during VM provisioning in Orchestrator

    Posted May 08, 2025 05:22 PM

    Thanks for the code and explanation. The NIC we need to delete is always 'Network adapter 2'.

    How do you go  about getting the `deviceChange[0].device.controllerKey' and  `deviceChange[0].device.key` for the Network adapter 2?

    Tom




  • 5.  RE: Code to delete vNIC on VM during VM provisioning in Orchestrator

    Posted May 08, 2025 05:22 PM

    Thanks for the code and explanation. How do you go about getting the `deviceChange[0].device.controllerKey' and  `deviceChange[0].device.key` for Network adapter 2? 

    Tom




  • 6.  RE: Code to delete vNIC on VM during VM provisioning in Orchestrator

    Posted May 09, 2025 03:56 AM

    Hi, Tom.

    You can take this example from my repo. It will loop over network devices and return them as an object. Therefore, you can check each NIC (by labels or any other property) and find one you want to remove.



    ------------------------------
    If you find the answer helpful, please click on the RECOMMEND button.

    Please visit my blog to get more information: https://clouddepth.com
    ------------------------------



  • 7.  RE: Code to delete vNIC on VM during VM provisioning in Orchestrator

    Posted May 09, 2025 10:53 AM

    Thanks for the additional code. It worked perfectly once the correct device.key was inputted. 

    Much appreciated! 

    Tom




  • 8.  RE: Code to delete vNIC on VM during VM provisioning in Orchestrator

    Posted May 09, 2025 10:55 AM

    Glad to hear. You're very welcome.



    ------------------------------
    If you find the answer helpful, please click on the RECOMMEND button.

    Please visit my blog to get more information: https://clouddepth.com
    ------------------------------