vagrant-vsphere icon indicating copy to clipboard operation
vagrant-vsphere copied to clipboard

VM Network Mappings

Open ashxjain opened this issue 8 years ago • 4 comments

I want to deploy a VM on an ESXI server. VM has 3 network interfaces.

When the VM is deployed on ESXI server by Vagrant, How can i map those network interfaces to use the port-groups (networks) on that ESXI server? I'm unable to find any way to do it using Vagrant.

Because of this, Vagrant is unable to SSH into the VM, as the VM's network interfaces are mapped to some port-groups (junk).

test-vm-1: Warning: Authentication failure. Retrying...

ashxjain avatar Oct 20 '16 12:10 ashxjain

Hi,

I have the exact same question, also need this.

Otherwise, need a copy of each source template/vm for each port group.

voiprodrigo avatar Oct 27 '16 18:10 voiprodrigo

This functionality exists after all, with the "vlan" setting. Just set it to the desired network / port group name.

voiprodrigo avatar Oct 28 '16 16:10 voiprodrigo

Thank you @voiprodrigo ! You are right. But i wanted to configure multiple network mappings and not just for 1st NIC. Say if i have 2 NICs, i want NIC1 to be mapped to PortGroup1 and NIC2 to be mapped to PortGroup2.

I did the following changes to work in my setup:

In lib/vSphere/action/clone.rb:

        def create_network_device(label, summary, index)
          key = 4000 + index
          config_spec_operation = RbVmomi::VIM::VirtualDeviceConfigSpecOperation('edit')
          nic_backing_info = RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo(:deviceName => summary)
          connectable = RbVmomi::VIM::VirtualDeviceConnectInfo(
            :allowGuestControl => true,
            :connected => true,
            :startConnected => true)
          device = RbVmomi::VIM::VirtualVmxnet3(
            :backing => nic_backing_info,
            :deviceInfo => RbVmomi::VIM::Description(:label => label, :summary => summary),
            :key => key,
            :connectable => connectable)
          device_spec = RbVmomi::VIM::VirtualDeviceConfigSpec(
            :operation => config_spec_operation,
            :device => device)
          return device_spec
        end

        def add_custom_network(spec, vm_template, test_net1, test_net2)
          device_net1_spec = create_network_device("Network adapter 1", test_net1, 0)
          device_net2_spec = create_network_device("Network adapter 2", test_net2, 1)
          spec[:config][:deviceChange] = [device_net1_spec, device_net2_spec]
        end

ashxjain avatar Oct 29 '16 15:10 ashxjain

Have a look at my pull request #210

It adds comprehensive support for multiple nics and configuring them just the way you want.

I use it to configure virtual routers that have 10 nics and connect to a number of different port groups.

taliesins avatar Nov 17 '16 18:11 taliesins