VMware Cloud Community
stizzly
Contributor
Contributor
Jump to solution

Change MAC of NIC from Auto to Manual

Hi,

I want to change the MAC address from "Auto" to "Manual", but with the generated MAC Address from the "Auto" step.

I saw some similar workflows, but these workflows always create a new NIC and because I am not the real Java Pro, I don't know, how to just change these settings.

Help would be awesome Smiley Happy.

Thanks in Advance

1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Here is a sample that changes MAC address type of a NIC labelled 'Network Adapter 2' from auto to manual. The input parameter is vm of type VC:VirtualMachine

var devices = vm.config.hardware.device;

for (var i in devices) {

  if (!System.getModule("com.vmware.library.vc.vm.network").isSupportedNic(devices[i])) {

     continue;

  }

  if (devices[i].deviceInfo.label != "Network adapter 2") {

     continue;

  }

  // NIC is found -> change its MAC address type

  var confSpec = new VcVirtualDeviceConfigSpec();

  confSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;

  confSpec.device = devices[i];

  confSpec.device.addressType = "manual"; // change 'manual to 'generated' if you want to change the type back to auto

  var spec = new VcVirtualMachineConfigSpec();

  spec.deviceChange = [confSpec];

  vm.reconfigVM_Task(spec);

}

View solution in original post

2 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Here is a sample that changes MAC address type of a NIC labelled 'Network Adapter 2' from auto to manual. The input parameter is vm of type VC:VirtualMachine

var devices = vm.config.hardware.device;

for (var i in devices) {

  if (!System.getModule("com.vmware.library.vc.vm.network").isSupportedNic(devices[i])) {

     continue;

  }

  if (devices[i].deviceInfo.label != "Network adapter 2") {

     continue;

  }

  // NIC is found -> change its MAC address type

  var confSpec = new VcVirtualDeviceConfigSpec();

  confSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;

  confSpec.device = devices[i];

  confSpec.device.addressType = "manual"; // change 'manual to 'generated' if you want to change the type back to auto

  var spec = new VcVirtualMachineConfigSpec();

  spec.deviceChange = [confSpec];

  vm.reconfigVM_Task(spec);

}

stizzly
Contributor
Contributor
Jump to solution

That's exactly what I wanted, thanks a lot!

Reply
0 Kudos