I have a virtualization host (could be either VSphere or SCVVM) that has four NICs, two 1 gbps and two 10 gbps. This machine hosts a VM on two vSwitches with unique names (such as vSwitch0 and vSwitch1), one is on a 1 gbps NIC and the other on a 10 gbps NIC.
This VM is generated automatically through a long powershell process that creates the imports vm definition & empty virtual disk, installs the OS, installs other software, etc.
My problem is that in the guest OS (Server 2012 R2) the network adapters are simply labeled 'Ethernet Adapter' and 'Ethernet Adapter 1'. I cannot tell which is on 'vSwitch0' or 'vSwitch1'. I need each adapter to have a very specific IP based upon which virtual switch it is connected to.
Any ideas? I need to somehow configure this in the powershell script that configures the guest OS.
Thanks in advance!
The easiest way I can think of to do this is to somehow extract the MAC address of each network adapter from the VM configuration and check it against the NICs within the VM.
You wouldn't necessarily need to set the MAC addresses - vSphere will automatically assign a MAC for you if you don't specify a custom one (the assignment is intelligent enough to know not to reassign already-used addresses, so you don't need to worry about conflicts). You can then query the VM's configuration after it has been created, and match this against the NICs as they appear in the OS. For example:
First, you query the VM configuration via vSphere:
00:56:3f:00:21:12
00:56:3f:12:32:4a
Then, you query the NICs present within the guest OS after creation:
00:56:3f:12:32:4a
and is therefore NIC B and is attached to vSwitch100:56:3f:00:21:12
and is therefore NIC A and is attached to vSwitch0You may be able to do this programatically, however I'm not proficient enough with the vSphere PowerShell CLI to know for sure.
The way I've dealt with this for my dual homed virtual machines is that I have a DHCP server on one network so I know the vNIC that gets a DHCP assigned ip address is connected to the network where the DHCP server is. The NIC that assigns itself an APIPA address is connected to the other network. It's crude but it works. You may not want to set up a DHCP server just for this purpose but in my case I use the DHCP server so I'm lucky in that I can use it to identify which network each vNIC is connected to.