Hello,
I'm trying to put the MAC Address of a virtual machine in a string. At the beginning, I was using this script :
strMACAddress = objVM.guest.net[0].macAddress;
But as specified in the title, the vmware tools aren't installed on the VM. I've found a similar post in vSphere Web Services SDK :
http://communities.vmware.com/thread/254204
In this post, it's specified to use the VcVirtualEthernetCard() scripting object. I'm new on Orchestrator and I don't understand how to link "myVcVirtualEthernetCard" to my Virtual Machine Object "objVM".
Example :
IN : objVM (VcVirtualMachine)
OUT : macAddress
var myVcVirtualEthernetCard = new VcVirtualEthernetCard();
var macAddress = myVcVirtualEthernetCard.macAddress;
Thank you for your help.
Regards,
Fred
Hi!
You can loop through the config.hardware.device-Array of the VM:
IN: vm (Vc:VirtualMachine)
OUT: macAddresses (Array/String)
//initialize macAddresses array (to make a push() possible later)
macAddresses = new Array();
var deviceArray = vm.config.hardware.device;
if (!deviceArray) throw "Error getting hardware config array of VM";
System.debug("deviceArray: " + deviceArray);
//loop through array, find NICs and retrieve there MACs
for (var i in deviceArray) {
var currentDevice = deviceArray.pop();
if (currentDevice) {
System.debug("currentDevice: " + currentDevice);
if (currentDevice instanceof VcVirtualE1000 ||
currentDevice instanceof VcVirtualPCNet32 ||
currentDevice instanceof VcVirtualVmxnet ||
currentDevice instanceof VcVirtualVmxnet2 ||
currentDevice instanceof VcVirtualVmxnet) {
System.debug("found network card on " + currentDevice);
macAddresses.push(currentDevice.macAddress) ;
}
}
}
Please let me know if it works for your, or if you need some more information 🙂
Regards,
Joerg
Hi!
You can loop through the config.hardware.device-Array of the VM:
IN: vm (Vc:VirtualMachine)
OUT: macAddresses (Array/String)
//initialize macAddresses array (to make a push() possible later)
macAddresses = new Array();
var deviceArray = vm.config.hardware.device;
if (!deviceArray) throw "Error getting hardware config array of VM";
System.debug("deviceArray: " + deviceArray);
//loop through array, find NICs and retrieve there MACs
for (var i in deviceArray) {
var currentDevice = deviceArray.pop();
if (currentDevice) {
System.debug("currentDevice: " + currentDevice);
if (currentDevice instanceof VcVirtualE1000 ||
currentDevice instanceof VcVirtualPCNet32 ||
currentDevice instanceof VcVirtualVmxnet ||
currentDevice instanceof VcVirtualVmxnet2 ||
currentDevice instanceof VcVirtualVmxnet) {
System.debug("found network card on " + currentDevice);
macAddresses.push(currentDevice.macAddress) ;
}
}
}
Please let me know if it works for your, or if you need some more information 🙂
Regards,
Joerg
Thank you very much Joerg !! It's exactly what I wanted.
Regards,
Fred
This really helped me out recently, thanks! One thing I had to change for my case was the second instance of this:
currentDevice instanceof VcVirtualVmxnet
currentDevice instanceof VcVirtualVmxnet3