DrewEinhorn
Contributor
Contributor

How do I retrieve mac address from vm?

Also

Need to support multiple nics and

set .virtualDev to vmxnet or e1000 as appropriate

0 Kudos
7 Replies
hrobinson
VMware Employee
VMware Employee

Here's a script that lists all of the network cards for a virtual machine including the macAddress.

(The script has been posted at http://communities.vmware.com/docs/DOC-1134 )

0 Kudos
Funtoosh
Enthusiast
Enthusiast

Thats is really cool but how do I list out all the VM which has static MAC and what would be their MAC address. I thought of using Enum - VirtualEthernetCardMacType but not sure where it would fit in your script.

0 Kudos
stumpr
Virtuoso
Virtuoso

How about something like this? I apologize for the rough snippet.

If someone knows of a smoother way to filter out the devices by a view filter, I'd love to hear it. I ended up using 'isa' to determine the superclass of the vmware device to determine which devices were VirtualEthernetDevices. This should work for determining other device types as well.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
beaunewcomb
Contributor
Contributor

This is exactly what I'm looking for too, but I get this error:

Can't use an undefined value as an ARRAY reference at get-macs.pl line 36.

0 Kudos
stumpr
Virtuoso
Virtuoso

I checked some of my samples, I have an updated version that I probably used when I ran into the problem you posted. I believe this error occurs when you have a VM defined but no devices assigned to it (no disk, no ethernet..just an empty shell.) This updated script check if the device array is defined. I wish the perl toolkit would return empty arrays instead of undefined values, just saves a lot of error checking in your script logic to avoid bomb outs.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
beaunewcomb
Contributor
Contributor

I figured that was the case.. I started stepping through and troubleshooting, but just stepped out for a coffee so didn't get to changing it yet :smileycool:

I still get the error though.. maybe we just don't have any static macs

EDIT: My error--- it works!

0 Kudos
vmkjbanks
Contributor
Contributor

This is GREAT! I spent hours trying to figure this out searching through the mob and the vi reference. It shows me exactly what i've been missing.

Thanks soooo much for your post.

0 Kudos