adrahon / vagrant-kvm

This project is dead, please use vagrant-libvirt instead! A Vagrant 1.4+ plugin that adds a KVM provider to Vagrant, allowing Vagrant to control and provision KVM/QEMU VM.
MIT License
366 stars 60 forks source link

2 network interfaces instead of one #231

Closed roman-holovin closed 10 years ago

roman-holovin commented 10 years ago

I've launched box with static IP. 2 networks were created: vagrant and vagrant-33, but my ubuntu box have only one network interface, and have 192.168.123.xx ip, which is not that ip configured in Vagrantfile

vagrant 1.6.2, vagrant-kvm 0.2.0-dev

miurahr commented 10 years ago

vagrant-kvm 0.2.0-dev is designed to add NIC according to Vagrantfile definitions. It always create default NW and NIC for guest, vagrant and 192.168.123.xx ip. then it create private network for it.

It is an almost same behevior with vagrant and virtualbox. (A difference is that it is host only NIC for VirtualBox but in KVM it is NAT)

There are methods to add NIC to guest definition: https://github.com/adrahon/vagrant-kvm/blob/master/lib/vagrant-kvm/util/vm_definition.rb#L137 https://github.com/adrahon/vagrant-kvm/blob/master/lib/vagrant-kvm/util/vm_definition.rb#L169

And It launches such a driver functions https://github.com/adrahon/vagrant-kvm/blob/master/lib/vagrant-kvm/action/network.rb#L40

Because network action created network 'vagrant-33', add_nic() was also processed. https://github.com/adrahon/vagrant-kvm/blob/master/lib/vagrant-kvm/action/network.rb#L77 https://github.com/adrahon/vagrant-kvm/blob/master/lib/vagrant-kvm/driver/driver.rb#L488

For further debug, could you post debug log? That include machine domain definition XML.

Is it better that is disable default nic when configured with private network?

roman-holovin commented 10 years ago

Issue is that if I explicitly requested to have certain ip address, VM must be available at this ip address without any modifications in my internal box configs. Of course, I can ssh in box and add new adapter, make sure that it will get desired address, but as a user why I'm supposed to do such thing? I'm not sure who caused a problem, from one point of view, box running in vm with 2 nics, so there should be 2 nics available inside OS, but there is only one. From other side, why there are 2 nics in first place, if in Vagrantfile I requested my box to have a private network with static ip.

roman-holovin commented 10 years ago

Oops, missclick, reopened

adrahon commented 10 years ago

I agree with @dantix that the default behaviour should be to use the IP address that was specified in the Vagrant file and not add a NIC. It isn't simple, though, what if the user creates 3 Vagrant boxes with different networks? Do we create 3 networks with libvirt? Do we remove them when the box is destroyed? What if there's another VM using that network? etc.

Here is what I propose:

miurahr commented 10 years ago

No creating static IP is a bug, because it designed to create static IP.

If the user creates 3 vagrant boxes with different networks, vagrant-kvm create 3 different networks and 1 default network to communicate for provision. Each guest have 2 NIC, one is specified in Vagrantfile and other is random in default network (in design) Also when the box is destroyed, subnets are also destroyed.(in design) If another VM using same subnet, vagrant-kvm update the subnet and both VMs can communicate each other.

The report is that vagrant-kvm is designed to create 2 nic and to assign IP address but not creating nic and not assign address. This is simply a bug.

The default subnet is hard coded now. So we need to improve there.

The comment https://github.com/adrahon/vagrant-kvm/issues/231#issuecomment-43167022 pointed the code vagrant-kvm assigning private IP address for guest.

miurahr commented 10 years ago

I can reproduce it.

Here is a log. https://gist.github.com/miurahr/664b9d44ddb807e8bb18

vagrant debug log. https://gist.github.com/miurahr/664b9d44ddb807e8bb18#file-vagrant_up-log

Vagrant-KVM create NIC for domain. Here is a copy of /etc/libvirt/qemu/fedora20.xml https://gist.github.com/miurahr/664b9d44ddb807e8bb18#file-libvirt_domain_fedora20-xml

 <interface type='network'>
<mac address='08:00:27:73:3d:d7'/>
<source network='vagrant'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<interface type='network'>
<mac address='00:16:3e:13:8a:52'/>
<source network='vagrant-34'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x1'/>
</interface>

but guest does not recognize it. Only eth0 is created. https://gist.github.com/miurahr/664b9d44ddb807e8bb18#file-ifconfig_on_guest-log

I have checked guest dmesg log. https://gist.github.com/miurahr/664b9d44ddb807e8bb18#file-dmesg_in_fesora20_guest-log

It may be a problem as followings:

2nd network definition in XML is slot 0x0a and function 0x1 but it should be slot 0x0a and function 0x0.