So someone asked me if I could take a manually entered mac address and make it look like it was assigned by vCenter so that people would be less likely to mess with it.
Turns out that it is not that hard, the caveat though is that this is probably far from supported by vmware even though their API allows it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
var deviceChange = new Array(); var devices = VirtualMachine.config.hardware.device; for (var i in devices) { if (devices[i] instanceof VcVirtualE1000 || devices[i] instanceof VcVirtualVmxnet || devices[i] instanceof VcVirtualPCNet32 || devices[i] instanceof VcVirtualVmxnet2 || devices[i] instanceof VcVirtualVmxnet3) { if( devices[i].addressType != "assigned" ) { var message = "Flagging the manually assigned mac address (" + devices[i].macAddress + ") for nic (" + devices[i].key + ") as system generated."; VirtualMachine.sdkConnection.eventManager.logUserEvent(VirtualMachine, message); Server.log(message); var nicChange = new VcVirtualDeviceConfigSpec(); nicChange.operation = VcVirtualDeviceConfigSpecOperation.edit; nicChange.device = devices[i]; nicChange.device.addressType = "assigned"; deviceChange.push(nicChange); } } } // Create the machine spec var spec = new VcVirtualMachineConfigSpec(); spec.deviceChange = deviceChange; if( spec.deviceChange.length > 0 ) { reconfigTask = VirtualMachine.reconfigVM_Task(spec); } |