From 60786e18b5bc6bfe20e091e9a98068d5bfbb5b18 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 16 Oct 2014 02:42:07 +0100 Subject: [PATCH 01/86] allow preexisting disk volumes via new option --- README.md | 1 + lib/vagrant-libvirt/action/create_domain.rb | 11 ++++++++++- lib/vagrant-libvirt/config.rb | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d311f0..0c32e00 100644 --- a/README.md +++ b/README.md @@ -282,6 +282,7 @@ You can create and attach additional disks to a VM via `libvirt.storage :file`. * `size` - Size of the disk image. If unspecified, defaults to 10G. * `type` - Type of disk image to create. Defaults to *qcow2*. * `cache` - Cache mode to use, e.g. `none`, `writeback`, `writethrough` (see the [libvirt documentation for possible values](http://libvirt.org/formatdomain.html#elementsDisks) or [here](https://www.suse.com/documentation/sles11/book_kvm/data/sect1_chapter_book_kvm.html) for a fuller explanation). Defaults to *default*. +* `allow_existing` - Set to true if you want to allow the VM to use a pre-existing disk. This is useful for sharing disks between VMs, e.g. in order to simulate shared SAN storage. The following example creates two additional disks. diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 123cb08..de76b8d 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -85,6 +85,13 @@ module VagrantPlugins rescue Fog::Errors::Error => e raise Errors::FogDomainVolumeCreateError, :error_message => e.message + rescue Libvirt::Error => e + if disk[:allow_existing] && + e.message =~ /storage vol.* (already exists|exists already)/ + disk[:preexisting] = true + else + raise + end end end @@ -111,7 +118,9 @@ module VagrantPlugins env[:ui].info(" -- Disks: #{_disks_print(@disks)}") end @disks.each do |disk| - env[:ui].info(" -- Disk(#{disk[:device]}): #{disk[:path]}") + msg = " -- Disk(#{disk[:device]}): #{disk[:path]}" + msg += " (preexisting)" if disk[:preexisting] + env[:ui].info(msg) end env[:ui].info(" -- Command line : #{@cmd_line}") diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 019d083..1d196b7 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -142,6 +142,7 @@ module VagrantPlugins :size => options[:size], :path => options[:path], :cache => options[:cache] || 'default', + :allow_existing => options[:allow_existing], } if storage_type == :file From 56cfb971a4fb435264a6aebb2140ef9415bd06ea Mon Sep 17 00:00:00 2001 From: dima Date: Fri, 10 Apr 2015 18:31:24 +0200 Subject: [PATCH 02/86] remove not useful link --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index cc0b11b..77d6e34 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,6 @@ started is to add Libvirt box and specify all the details manually within a `config.vm.provider` block. So first, add Libvirt box using any name you want. This is just an example of Libvirt CentOS 6.4 box available: -``` -vagrant box add centos64 http://kwok.cz/centos64.box -``` -or ``` vagrant box add centos64 http://citozin.com/centos64.box ``` From fa261e79b289a71ca53324aa5327c364df5804f9 Mon Sep 17 00:00:00 2001 From: dima Date: Mon, 13 Apr 2015 17:30:01 +0200 Subject: [PATCH 03/86] improve format --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7b7b3b6..62c3b0c 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ $ vagrant up --provider=libvirt Vagrant needs to know that we want to use Libvirt and not default VirtualBox. That's why there is `--provider=libvirt` option specified. Other way to tell Vagrant to use Libvirt provider is to setup environment variable + `export VAGRANT_DEFAULT_PROVIDER=libvirt`. ### How Project Is Created From c80841943c27c0de1163b61d4487ffab86b5a988 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilets Date: Tue, 14 Apr 2015 22:23:44 +0200 Subject: [PATCH 04/86] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62c3b0c..947b08c 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ starts with 'libvirt__' string. Here is a list of those options: be forwarded (NATed or routed). Used only when creating new network. By default, all physical interfaces are used. * `:mac` - MAC address for the interface. -* `model_type` - parameter specifies the model of the network adapter when you create a domain value by default virtio KVM believe possible values, see the documentation for libvirt +* `:model_type` - parameter specifies the model of the network adapter when you create a domain value by default virtio KVM believe possible values, see the documentation for libvirt When the option `:libvirt__dhcp_enabled` is to to 'false' it shouldn't matter whether the virtual network contains a DHCP server or not and vagrant-libvirt From 0e2c26a33fc54ebb73a718772496fcf058ee9f54 Mon Sep 17 00:00:00 2001 From: dima Date: Wed, 15 Apr 2015 09:45:29 +0200 Subject: [PATCH 05/86] cleaning,tests preparation --- Gemfile | 1 + lib/vagrant-libvirt/action/create_domain.rb | 36 +++++++++---------- spec/support/environment_helper.rb | 14 ++++++++ .../action/set_name_of_domain_spec.rb | 4 +-- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 1c69fb4..e4d5772 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ group :development do # gem dependency because we expect to be installed within the # Vagrant environment itself using `vagrant plugin`. gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git" + gem 'pry' end group :plugins do diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index acf5e18..620d66e 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -3,7 +3,6 @@ require 'log4r' module VagrantPlugins module ProviderLibvirt module Action - class CreateDomain include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate @@ -13,15 +12,17 @@ module VagrantPlugins end def _disk_name(name, disk) - return "#{name}-#{disk[:device]}.#{disk[:type]}" # disk name + "#{name}-#{disk[:device]}.#{disk[:type]}" # disk name end def _disks_print(disks) - return disks.collect{ |x| x[:device]+'('+x[:type]+','+x[:size]+')' }.join(', ') + disks.collect do |x| + x[:device] + '(' + x[:type] + ',' + x[:size] + ')' + end.join(', ') end def _cdroms_print(cdroms) - return cdroms.collect{ |x| x[:dev] }.join(', ') + cdroms.collect { |x| x[:dev] }.join(', ') end def call(env) @@ -35,7 +36,7 @@ module VagrantPlugins @machine_type = config.machine_type @disk_bus = config.disk_bus @nested = config.nested - @memory_size = config.memory.to_i*1024 + @memory_size = config.memory.to_i * 1024 @domain_volume_cache = config.volume_cache @kernel = config.kernel @cmd_line = config.cmd_line @@ -70,10 +71,9 @@ module VagrantPlugins @domain_volume_path = domain_volume.path # the default storage prefix is typically: /var/lib/libvirt/images/ - storage_prefix = File.dirname(@domain_volume_path)+'/' # steal + storage_prefix = File.dirname(@domain_volume_path) + '/' # steal @disks.each do |disk| - disk[:path] ||= _disk_name(@name, disk) # On volume creation, the element inside @@ -88,15 +88,15 @@ module VagrantPlugins # qemu-img create -f qcow2 5g begin domain_volume_disk = env[:libvirt_compute].volumes.create( - :name => disk[:name], - :format_type => disk[:type], - :path => disk[:absolute_path], - :capacity => disk[:size], + name: disk[:name], + format_type: disk[:type], + path: disk[:absolute_path], + capacity: disk[:size], #:allocation => ?, - :pool_name => @storage_pool_name) + pool_name: @storage_pool_name) rescue Fog::Errors::Error => e raise Errors::FogDomainVolumeCreateError, - :error_message => e.message + error_message: e.message end end @@ -105,7 +105,7 @@ module VagrantPlugins env[:ui].info(" -- Name: #{@name}") env[:ui].info(" -- Domain type: #{@domain_type}") env[:ui].info(" -- Cpus: #{@cpus}") - env[:ui].info(" -- Memory: #{@memory_size/1024}M") + env[:ui].info(" -- Memory: #{@memory_size / 1024}M") env[:ui].info(" -- Base box: #{env[:machine].box.name}") env[:ui].info(" -- Storage pool: #{@storage_pool_name}") env[:ui].info(" -- Image: #{@domain_volume_path}") @@ -115,7 +115,7 @@ module VagrantPlugins env[:ui].info(" -- Graphics Type: #{@graphics_type}") env[:ui].info(" -- Graphics Port: #{@graphics_port}") env[:ui].info(" -- Graphics IP: #{@graphics_ip}") - env[:ui].info(" -- Graphics Password: #{@graphics_passwd.empty? ? 'Not defined': 'Defined'}") + env[:ui].info(" -- Graphics Password: #{@graphics_passwd.empty? ? 'Not defined' : 'Defined'}") env[:ui].info(" -- Video Type: #{@video_type}") env[:ui].info(" -- Video VRAM: #{@video_vram}") env[:ui].info(" -- Keymap: #{@keymap}") @@ -140,10 +140,9 @@ module VagrantPlugins # existing volume? Use domain creation from template.. begin server = env[:libvirt_compute].servers.create( - :xml => to_xml('domain')) + xml: to_xml('domain')) rescue Fog::Errors::Error => e - raise Errors::FogCreateServerError, - :error_message => e.message + raise Errors::FogCreateServerError, error_message: e.message end # Immediately save the ID since it is created at this point. @@ -152,7 +151,6 @@ module VagrantPlugins @app.call(env) end end - end end end diff --git a/spec/support/environment_helper.rb b/spec/support/environment_helper.rb index f49db85..c6e73d1 100644 --- a/spec/support/environment_helper.rb +++ b/spec/support/environment_helper.rb @@ -11,6 +11,20 @@ class EnvironmentHelper self.send(value.to_sym) end + def cpus + 4 + end + + def memory + 1024 + end + + %w(cpus cpu_mode machine_type disk_bus nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms driver).each do |name| + define_method(name.to_sym) do + nil + end + end + def machine self end diff --git a/spec/vagrant-libvirt/action/set_name_of_domain_spec.rb b/spec/vagrant-libvirt/action/set_name_of_domain_spec.rb index 69d3319..838910a 100644 --- a/spec/vagrant-libvirt/action/set_name_of_domain_spec.rb +++ b/spec/vagrant-libvirt/action/set_name_of_domain_spec.rb @@ -10,12 +10,12 @@ describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env) first = dmn.build_domain_name(@env) second = dmn.build_domain_name(@env) - first.should_not eq(second) + first.should_not eq(second) end it "builds simple domain name" do @env.default_prefix= 'pre' dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env) - dmn.build_domain_name(@env).should eq('pre_') + dmn.build_domain_name(@env).should eq('pre_') end end From e8d1b94ad927b34f0bbe3654b6585b19e51335af Mon Sep 17 00:00:00 2001 From: Jim Salem Date: Wed, 15 Apr 2015 14:26:21 -0400 Subject: [PATCH 06/86] Improve doc for id_ssh_key_file. Do not prepend ~/.ssh/ if the pathname includes a directory --- README.md | 2 +- lib/vagrant-libvirt/config.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 947b08c..9e9981e 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ Although it should work without any configuration for most people, this provider * `connect_via_ssh` - If use ssh tunnel to connect to Libvirt. * `username` - Username and password to access Libvirt. * `password` - Password to access Libvirt. -* `id_ssh_key_file` - The id ssh key file name to access Libvirt (eg: id_dsa or id_rsa or ... in the user .ssh directory) +* `id_ssh_key_file` - If not nil, uses this ssh private key to access Libvirt. Default is $HOME/.ssh/id_rsa. Prepends $HOME/.ssh/ if no directory. * `socket` - Path to the libvirt unix socket (eg: /var/run/libvirt/libvirt-sock) * `uri` - For advanced usage. Directly specifies what libvirt connection URI vagrant-libvirt should use. Overrides all other connection configuration options. diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 70c6758..dbf0497 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -245,8 +245,10 @@ module VagrantPlugins if @id_ssh_key_file # set ssh key for access to libvirt host - home_dir = `echo ${HOME}`.chomp - uri << "\&keyfile=#{home_dir}/.ssh/"+@id_ssh_key_file + uri << "\&keyfile=" + # if no slash, prepend $HOME/.ssh/ + uri << "#{`echo ${HOME}`.chomp}/.ssh/" if @id_ssh_key_file !~ /\// + uri << @id_ssh_key_file end # set path to libvirt socket uri << "\&socket="+@socket if @socket From 807005afc37df70887b975c1c1a3f52ef69d3398 Mon Sep 17 00:00:00 2001 From: dima Date: Wed, 15 Apr 2015 21:48:29 +0200 Subject: [PATCH 07/86] more strict patern for full path --- lib/vagrant-libvirt/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index dbf0497..7412824 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -247,7 +247,7 @@ module VagrantPlugins # set ssh key for access to libvirt host uri << "\&keyfile=" # if no slash, prepend $HOME/.ssh/ - uri << "#{`echo ${HOME}`.chomp}/.ssh/" if @id_ssh_key_file !~ /\// + uri << "#{`echo ${HOME}`.chomp}/.ssh/" if @id_ssh_key_file !~ /\A\// uri << @id_ssh_key_file end # set path to libvirt socket From d154582c5d628d3921f62ffbbc5b6fe0f4666813 Mon Sep 17 00:00:00 2001 From: dima Date: Wed, 15 Apr 2015 21:58:12 +0200 Subject: [PATCH 08/86] 0.0.26 --- lib/vagrant-libvirt/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/version.rb b/lib/vagrant-libvirt/version.rb index b4a637d..26cc284 100644 --- a/lib/vagrant-libvirt/version.rb +++ b/lib/vagrant-libvirt/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module ProviderLibvirt - VERSION = '0.0.25' + VERSION = '0.0.26' end end From a941ddc962bb74ddf5115a89f4f8870e9c4aadda Mon Sep 17 00:00:00 2001 From: dima Date: Thu, 16 Apr 2015 09:12:19 +0200 Subject: [PATCH 09/86] remove volumes logic for shared volumes --- README.md | 4 ++-- lib/vagrant-libvirt/action/create_domain.rb | 4 ++-- lib/vagrant-libvirt/action/destroy_domain.rb | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2738e90..06d90fa 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ Although it should work without any configuration for most people, this provider * `connect_via_ssh` - If use ssh tunnel to connect to Libvirt. * `username` - Username and password to access Libvirt. * `password` - Password to access Libvirt. -* `id_ssh_key_file` - If not nil, uses this ssh private key to access Libvirt. Default is $HOME/.ssh/id_rsa. Prepends $HOME/.ssh/ if no directory. +* `id_ssh_key_file` - If not nil, uses this ssh private key to access Libvirt. Default is $HOME/.ssh/id_rsa. Prepends $HOME/.ssh/ if no directory. * `socket` - Path to the libvirt unix socket (eg: /var/run/libvirt/libvirt-sock) * `uri` - For advanced usage. Directly specifies what libvirt connection URI vagrant-libvirt should use. Overrides all other connection configuration options. @@ -298,7 +298,7 @@ You can create and attach additional disks to a VM via `libvirt.storage :file`. * `type` - Type of disk image to create. Defaults to *qcow2*. * `bus` - Type of bus to connect device to. Defaults to *virtio*. * `cache` - Cache mode to use, e.g. `none`, `writeback`, `writethrough` (see the [libvirt documentation for possible values](http://libvirt.org/formatdomain.html#elementsDisks) or [here](https://www.suse.com/documentation/sles11/book_kvm/data/sect1_chapter_book_kvm.html) for a fuller explanation). Defaults to *default*. -* `allow_existing` - Set to true if you want to allow the VM to use a pre-existing disk. This is useful for sharing disks between VMs, e.g. in order to simulate shared SAN storage. +* `allow_existing` - Set to true if you want to allow the VM to use a pre-existing disk. This is useful for sharing disks between VMs, e.g. in order to simulate shared SAN storage. Shared disks removed only manualy. The following example creates two additional disks. diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 52766d4..d25f889 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -132,8 +132,8 @@ module VagrantPlugins end @disks.each do |disk| - msg = " -- Disk(#{disk[:device]}): #{disk[:absolute_path]}") - msg += " (preexisting)" if disk[:preexisting] + msg = " -- Disk(#{disk[:device]}): #{disk[:absolute_path]}" + msg += " (shared. Remove only manualy)" if disk[:allow_existing] env[:ui].info(msg) end diff --git a/lib/vagrant-libvirt/action/destroy_domain.rb b/lib/vagrant-libvirt/action/destroy_domain.rb index c964056..0904874 100644 --- a/lib/vagrant-libvirt/action/destroy_domain.rb +++ b/lib/vagrant-libvirt/action/destroy_domain.rb @@ -28,7 +28,20 @@ module VagrantPlugins end domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s) - domain.destroy(destroy_volumes: true) + + + # if using default configuration of disks + domain.destroy(destroy_volumes: env[:machine].provider_config.disks.empty?) + + env[:machine].provider_config.disks.each do |disk| + next if disk[:allow_existing] # shared disks remove only manualy or ??? + diskname = libvirt_domain.name + "-" + disk[:device] + ".raw" + # diskname is uniq + env[:libvirt_compute].volumes.all.select{|x| x.name == diskname }.first.destroy + end + + #remove root storage + env[:libvirt_compute].volumes.all.select{|x| x.name == libvirt_domain.name + ".img" }.first.destroy @app.call(env) end From 5ee914a2ef850d11123d97690ecd9d617137c0ac Mon Sep 17 00:00:00 2001 From: dima Date: Thu, 16 Apr 2015 09:27:11 +0200 Subject: [PATCH 10/86] shared volumes creation --- README.md | 2 +- lib/vagrant-libvirt/action/create_domain.rb | 36 ++++++++++----------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 06d90fa..a566b0b 100644 --- a/README.md +++ b/README.md @@ -298,7 +298,7 @@ You can create and attach additional disks to a VM via `libvirt.storage :file`. * `type` - Type of disk image to create. Defaults to *qcow2*. * `bus` - Type of bus to connect device to. Defaults to *virtio*. * `cache` - Cache mode to use, e.g. `none`, `writeback`, `writethrough` (see the [libvirt documentation for possible values](http://libvirt.org/formatdomain.html#elementsDisks) or [here](https://www.suse.com/documentation/sles11/book_kvm/data/sect1_chapter_book_kvm.html) for a fuller explanation). Defaults to *default*. -* `allow_existing` - Set to true if you want to allow the VM to use a pre-existing disk. This is useful for sharing disks between VMs, e.g. in order to simulate shared SAN storage. Shared disks removed only manualy. +* `allow_existing` - Set to true if you want to allow the VM to use a pre-existing disk. This is useful for sharing disks between VMs, e.g. in order to simulate shared SAN storage. Shared disks removed only manualy.If not exists - will created. If exists - using existed. The following example creates two additional disks. diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index d25f889..428f524 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -84,26 +84,23 @@ module VagrantPlugins disk[:absolute_path] = storage_prefix + disk[:path] - # make the disk. equivalent to: - # qemu-img create -f qcow2 5g - begin - domain_volume_disk = env[:libvirt_compute].volumes.create( - name: disk[:name], - format_type: disk[:type], - path: disk[:absolute_path], - capacity: disk[:size], - #:allocation => ?, - pool_name: @storage_pool_name) - rescue Fog::Errors::Error => e - raise Errors::FogDomainVolumeCreateError, - error_message: e.message - rescue Libvirt::Error => e - if disk[:allow_existing] && - e.message =~ /storage vol.* (already exists|exists already)/ - disk[:preexisting] = true - else - raise + if env[:libvirt_compute].volumes.all.select {|x| x.name == disk[:name] }.empty? + # make the disk. equivalent to: + # qemu-img create -f qcow2 5g + begin + env[:libvirt_compute].volumes.create( + name: disk[:name], + format_type: disk[:type], + path: disk[:absolute_path], + capacity: disk[:size], + #:allocation => ?, + pool_name: @storage_pool_name) + rescue Fog::Errors::Error => e + raise Errors::FogDomainVolumeCreateError, + error_message: e.message end + else + disk[:preexisting] = true end end @@ -134,6 +131,7 @@ module VagrantPlugins @disks.each do |disk| msg = " -- Disk(#{disk[:device]}): #{disk[:absolute_path]}" msg += " (shared. Remove only manualy)" if disk[:allow_existing] + msg += " Not created - using existed." if disk[:preexisting] env[:ui].info(msg) end From 5c9a712d42196a99bca7129d0e17793ff9f908a7 Mon Sep 17 00:00:00 2001 From: dima Date: Fri, 17 Apr 2015 08:24:25 +0200 Subject: [PATCH 11/86] fix detroying order --- lib/vagrant-libvirt/action/destroy_domain.rb | 23 +++++++++++-------- .../action/set_name_of_domain.rb | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/vagrant-libvirt/action/destroy_domain.rb b/lib/vagrant-libvirt/action/destroy_domain.rb index 0904874..3ef7f9c 100644 --- a/lib/vagrant-libvirt/action/destroy_domain.rb +++ b/lib/vagrant-libvirt/action/destroy_domain.rb @@ -29,20 +29,23 @@ module VagrantPlugins domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s) + if env[:machine].provider_config.disks.empty? + # if using default configuration of disks + domain.destroy(destroy_volumes: true) + else + domain.destroy(destroy_volumes: false) - # if using default configuration of disks - domain.destroy(destroy_volumes: env[:machine].provider_config.disks.empty?) + env[:machine].provider_config.disks.each do |disk| + next if disk[:allow_existing] # shared disks remove only manualy or ??? + diskname = libvirt_domain.name + "-" + disk[:device] + ".raw" + # diskname is uniq + env[:libvirt_compute].volumes.all.select{|x| x.name == diskname }.first.destroy + end - env[:machine].provider_config.disks.each do |disk| - next if disk[:allow_existing] # shared disks remove only manualy or ??? - diskname = libvirt_domain.name + "-" + disk[:device] + ".raw" - # diskname is uniq - env[:libvirt_compute].volumes.all.select{|x| x.name == diskname }.first.destroy + #remove root storage + env[:libvirt_compute].volumes.all.select{|x| x.name == libvirt_domain.name + ".img" }.first.destroy end - #remove root storage - env[:libvirt_compute].volumes.all.select{|x| x.name == libvirt_domain.name + ".img" }.first.destroy - @app.call(env) end end diff --git a/lib/vagrant-libvirt/action/set_name_of_domain.rb b/lib/vagrant-libvirt/action/set_name_of_domain.rb index 9d91ea7..99bc330 100644 --- a/lib/vagrant-libvirt/action/set_name_of_domain.rb +++ b/lib/vagrant-libvirt/action/set_name_of_domain.rb @@ -43,7 +43,7 @@ module VagrantPlugins # @return [String] libvirt domain name def build_domain_name(env) config = env[:machine].provider_config - domain_name = + domain_name = if config.default_prefix.nil? env[:root_path].basename.to_s.dup else From 80f8c6b65c0fa9f39b4fca3bf81b9fd38e90833f Mon Sep 17 00:00:00 2001 From: Matt Jia Date: Fri, 17 Apr 2015 16:59:16 +1000 Subject: [PATCH 12/86] support dhcp bootp settings --- README.md | 4 ++++ lib/vagrant-libvirt/action/create_networks.rb | 2 ++ lib/vagrant-libvirt/templates/private_network.xml.erb | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 947b08c..58b91a8 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,10 @@ starts with 'libvirt__' string. Here is a list of those options: '255.255.255.0'. * `:libvirt__dhcp_enabled` - If DHCP will offer addresses, or not. Used only when creating new network. Default is true. +* `:libvirt__dhcp_bootp_file` - The file to be used for the boot image. + Used only when dhcp is enabled. +* `:libvirt__dhcp_bootp_server` - The server that runs the DHCP server. + Used only when dhcp is enabled.By default is the same host that runs the DHCP server. * `:libvirt__adapter` - Number specifiyng sequence number of interface. * `:libvirt__forward_mode` - Specify one of `veryisolated`, `none`, `nat` or `route` options. This option is used only when creating new network. Mode `none` will create diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index 7ef4643..9df39db 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -245,6 +245,8 @@ module VagrantPlugins stop_address = net.to_range.end & IPAddr.new('255.255.255.254') @network_dhcp_enabled = true + @network_dhcp_bootp_file = @options[:dhcp_bootp_file] + @network_dhcp_bootp_server = @options[:dhcp_bootp_server] @network_range_start = start_address @network_range_stop = stop_address else diff --git a/lib/vagrant-libvirt/templates/private_network.xml.erb b/lib/vagrant-libvirt/templates/private_network.xml.erb index e52bbe3..bfd3573 100644 --- a/lib/vagrant-libvirt/templates/private_network.xml.erb +++ b/lib/vagrant-libvirt/templates/private_network.xml.erb @@ -15,6 +15,13 @@ <% if @network_dhcp_enabled %> + <% if @network_dhcp_bootp_file %> + <% if @network_dhcp_bootp_server %> + + <% else %> + + <% end %> + <% end %> <% end %> From 749b431bc85a6a94dbda77e95e5e005b335953a7 Mon Sep 17 00:00:00 2001 From: Josef Stribny Date: Fri, 17 Apr 2015 14:56:31 +0200 Subject: [PATCH 13/86] Depend on new extracted fog-libvirt gem And depend on ruby-libvirt library through fog-libvirt. --- vagrant-libvirt.gemspec | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vagrant-libvirt.gemspec b/vagrant-libvirt.gemspec index 26a4adb..5b18192 100644 --- a/vagrant-libvirt.gemspec +++ b/vagrant-libvirt.gemspec @@ -20,10 +20,8 @@ Gem::Specification.new do |gem| gem.add_development_dependency "rspec-expectations", "~> 2.12.1" gem.add_development_dependency "rspec-mocks", "~> 2.12.1" - gem.add_runtime_dependency 'fog', '~> 1.15' - gem.add_runtime_dependency 'ruby-libvirt', '~> 0.4' + gem.add_runtime_dependency 'fog-libvirt', '~> 0.0.1' gem.add_runtime_dependency 'nokogiri', '~> 1.6.0' gem.add_development_dependency 'rake' end - From 7782113fae3534bd88788a0e2db4db0f70525e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Aar=C3=B8e=20Dam?= Date: Fri, 17 Apr 2015 16:13:21 +0200 Subject: [PATCH 14/86] Backout on box creation if image is in use. --- tools/create_box.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/create_box.sh b/tools/create_box.sh index 3a2f631..78ceaf9 100755 --- a/tools/create_box.sh +++ b/tools/create_box.sh @@ -3,7 +3,7 @@ error() { local msg="${1}" - echo "==> ${msg}" + echo "==> ERROR: ${msg}" exit 1 } @@ -70,6 +70,10 @@ if [[ -n $(backing "$IMG") ]]; then cp "$IMG" "$TMP_IMG" rebase "$TMP_IMG" else + if fuser -s "$IMG"; then + error "Image '$IMG_BASENAME' is used by another process" + fi + # move the image to get a speed-up and use less space on disk trap 'mv "$TMP_IMG" "$IMG"; rm -rf "$TMP_DIR"' EXIT mv "$IMG" "$TMP_IMG" From 46e5d7ba9dce7aac4b974380a6cc04f3c23b5e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Aar=C3=B8e=20Dam?= Date: Fri, 17 Apr 2015 16:47:38 +0200 Subject: [PATCH 15/86] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8af2f3f..ecd356e 100644 --- a/README.md +++ b/README.md @@ -390,12 +390,13 @@ The box is a tarball containing: * `Vagrantfile` that does default settings for the provider-specific configuration for this provider. ## Create Box -This script creates a vagrant-libvirt box from a qcow2 file: +To create a vagrant-libvirt box from a qcow2 image, run `create_box.sh` (located in the tools directory): -Usage: +```$ create_box.sh ubuntu14.qcow2``` -```create_box.sh ubuntu14.qcow2``` -Used Packer to create the qcow2 images, templates available at https://github.com/jakobadam/packer-qemu-templates +You can also create a box by using [Packer](https://packer.io). Packer templates for use with vagrant-libvirt are available at https://github.com/jakobadam/packer-qemu-templates. After cloning that project you can build a vagrant-libvirt box by running: + +``` ~/packer-qemu-templates/ubuntu$ packer build ubuntu-14.04-server-amd64-vagrant.json``` ## Development From 140a38350a1cccc303a38e28394bf7d5da593f66 Mon Sep 17 00:00:00 2001 From: dima Date: Sun, 19 Apr 2015 11:13:09 +0200 Subject: [PATCH 16/86] fedora21 image --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ecd356e..c9d61ae 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ a `config.vm.provider` block. So first, add Libvirt box using any name you want. This is just an example of Libvirt CentOS 6.4 box available: ``` +vagrant box add centos64 http://citozin.com/fedora21.box +# or vagrant box add centos64 http://citozin.com/centos64.box ``` From cc8aadc9de397441b7e2a10eecc76feb6143b4c7 Mon Sep 17 00:00:00 2001 From: Josef Stribny Date: Tue, 21 Apr 2015 09:04:53 +0200 Subject: [PATCH 17/86] Wait for libvirt to shutdown the domain Fixes #293 --- lib/vagrant-libvirt/action/read_state.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-libvirt/action/read_state.rb b/lib/vagrant-libvirt/action/read_state.rb index ad552a1..1848de4 100644 --- a/lib/vagrant-libvirt/action/read_state.rb +++ b/lib/vagrant-libvirt/action/read_state.rb @@ -27,10 +27,17 @@ module VagrantPlugins end # Find the machine begin + # Wait for libvirt to shutdown the domain + while libvirt.servers.get(machine.id).state.to_sym == :'shutting-down' do + @logger.info('Waiting on the machine to shut down...') + sleep 1 + end + server = libvirt.servers.get(machine.id) - if server.nil? || [:'shutting-down', :terminated].include?(server.state.to_sym) + + if server.nil? || server.state.to_sym == :terminated # The machine can't be found - @logger.info('Machine shutting down or terminated, assuming it got destroyed.') + @logger.info('Machine terminated, assuming it got destroyed.') machine.id = nil return :not_created end From 904e4b184fafd877316751ffc28b29e7a95b80bd Mon Sep 17 00:00:00 2001 From: dima Date: Fri, 1 May 2015 17:05:50 +0200 Subject: [PATCH 18/86] remove stupid code --- lib/vagrant-libvirt/action/handle_box_image.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/vagrant-libvirt/action/handle_box_image.rb b/lib/vagrant-libvirt/action/handle_box_image.rb index d1dc03c..45dacf0 100644 --- a/lib/vagrant-libvirt/action/handle_box_image.rb +++ b/lib/vagrant-libvirt/action/handle_box_image.rb @@ -123,11 +123,7 @@ module VagrantPlugins :error_message => e.message end - if progress == image_size - return true - else - return false - end + return progress == image_size end end From 20080839233a4847bcdf1a42e649d0f714f01149 Mon Sep 17 00:00:00 2001 From: dima Date: Fri, 1 May 2015 17:48:43 +0200 Subject: [PATCH 19/86] notification about box removing behaviour --- lib/vagrant-libvirt/action.rb | 8 ++++++++ .../action/remove_libvirt_image.rb | 20 +++++++++++++++++++ lib/vagrant-libvirt/plugin.rb | 6 +++++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 lib/vagrant-libvirt/action/remove_libvirt_image.rb diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index 98479a7..b2de400 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -8,6 +8,13 @@ module VagrantPlugins include Vagrant::Action::Builtin @logger = Log4r::Logger.new('vagrant_libvirt::action') + # remove image from libvirt storage pool + def self.remove_libvirt_image + Vagrant::Action::Builder.new.tap do |b| + b.use RemoveLibvirtImage + end + end + # This action is called to bring the box up from nothing. def self.action_up Vagrant::Action::Builder.new.tap do |b| @@ -331,6 +338,7 @@ module VagrantPlugins autoload :HaltDomain, action_root.join('halt_domain') autoload :HandleBoxImage, action_root.join('handle_box_image') autoload :HandleStoragePool, action_root.join('handle_storage_pool') + autoload :RemoveLibvirtImage, action_root.join('remove_libvirt_image') autoload :IsCreated, action_root.join('is_created') autoload :IsRunning, action_root.join('is_running') autoload :IsSuspended, action_root.join('is_suspended') diff --git a/lib/vagrant-libvirt/action/remove_libvirt_image.rb b/lib/vagrant-libvirt/action/remove_libvirt_image.rb new file mode 100644 index 0000000..554f0a7 --- /dev/null +++ b/lib/vagrant-libvirt/action/remove_libvirt_image.rb @@ -0,0 +1,20 @@ +require 'log4r' + +module VagrantPlugins + module ProviderLibvirt + module Action + class RemoveLibvirtImage + def initialize(app, env) + @logger = Log4r::Logger.new("vagrant_libvirt::action::remove_libvirt_image") + @app = app + end + + def call(env) + env[:ui].info("Vagrant-libvirt plugin removed box only from you LOCAL ~/.vagrant/boxes directory") + env[:ui].info("From libvirt storage pool you have to delete image manualy(virsh, virt-manager or by any other tool)") + @app.call(env) + end + end + end + end +end diff --git a/lib/vagrant-libvirt/plugin.rb b/lib/vagrant-libvirt/plugin.rb index 18e20ad..1dbb56c 100644 --- a/lib/vagrant-libvirt/plugin.rb +++ b/lib/vagrant-libvirt/plugin.rb @@ -32,6 +32,11 @@ module VagrantPlugins Provider end + action_hook(:remove_libvirt_image) do |hook| + hook.after Vagrant::Action::Builtin::BoxRemove, Action.remove_libvirt_image + end + + guest_capability('linux', 'mount_p9_shared_folder') do require_relative 'cap/mount_p9' Cap::MountP9 @@ -88,4 +93,3 @@ module VagrantPlugins end end end - From 4762bf213957ae061385171048064b55a07a0982 Mon Sep 17 00:00:00 2001 From: dima Date: Fri, 1 May 2015 17:50:46 +0200 Subject: [PATCH 20/86] rubocop recomends --- lib/vagrant-libvirt/action.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index b2de400..6910c74 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -34,7 +34,6 @@ module VagrantPlugins b2.use CreateNetworks b2.use CreateNetworkInterfaces - b2.use PrepareNFSValidIds b2.use SyncedFolderCleanup b2.use SyncedFolders @@ -45,9 +44,6 @@ module VagrantPlugins b2.use StartDomain b2.use WaitTillUp - - - b2.use ForwardPorts b2.use PrepareNFSSettings @@ -90,7 +86,6 @@ module VagrantPlugins b3.use SyncedFolderCleanup b3.use SyncedFolders - # Start it.. b3.use StartDomain @@ -98,11 +93,9 @@ module VagrantPlugins # so wait for dhcp lease and store IP into machines data_dir. b3.use WaitTillUp - b3.use ForwardPorts b3.use PrepareNFSSettings b3.use ShareFolders - end end end From 6fb57de11e316cfac44c175b7f5ac23c637e1413 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 1 May 2015 09:42:44 -0500 Subject: [PATCH 21/86] Fix retrieving VM IP address if there are multiple leases for the same VM If DHCP is used as the addressing mode of the VM it may receive various IP addresses over time. Thus dnsmasq can report all these addresses for a single machine, which gives us: addresses {:public=>["192.168.121.180\n192.168.121.184\n192.168.121.183\n192.168.121.182"], :private=>["192.168.121.180\n192.168.121.184\n192.168.121.183\n192.168.121.182"]} This causes the most problems when NFS is used as the shared folder mechanism, as the IP addresses pile up and a malformed /etc/exports is written. This in turn causes sequences of vagrant halt / vagrant up to receive read-only NFS exports due to the bad format: # VAGRANT-BEGIN: 1000 d943c68a-330b-4cb8-8711-53506a6c176e "/home/user/folder" 192.168.121.52 192.168.121.51(rw,no_subtree_check,all_squash,anonuid=1000,anongid=1000,fsid=3414715164) # VAGRANT-END: 1000 d943c68a-330b-4cb8-8711-53506a6c176e It appears that Vagrant expects that the value returned by read_ssh_info is just a single IP address, so pick the first IP address reported by dnsmasq. --- lib/vagrant-libvirt/action/read_ssh_info.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/action/read_ssh_info.rb b/lib/vagrant-libvirt/action/read_ssh_info.rb index 01e32a7..0bee747 100644 --- a/lib/vagrant-libvirt/action/read_ssh_info.rb +++ b/lib/vagrant-libvirt/action/read_ssh_info.rb @@ -34,7 +34,9 @@ module VagrantPlugins ip_address = nil domain.wait_for(2) { addresses.each_pair do |type, ip| - ip_address = ip[0] if ip[0] != nil + # Multiple leases are separated with a newline, return only + # the most recent address + ip_address = ip[0].split("\n").first if ip[0] != nil end ip_address != nil } From fc0a03bf0ea5df37bb3e90d9393230b2203d6c65 Mon Sep 17 00:00:00 2001 From: Yang Wei Date: Mon, 4 May 2015 19:44:27 +0800 Subject: [PATCH 22/86] Update README.md I ran into a trouble, as my box(ubuntu) was *not* installed zlib1g-dev package by default, so update README.md to hint guys to install this package for ubuntu/debian system. Signed-off-by: Yang Wei --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c9d61ae..1510938 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ missing development libraries for libxslt, libxml2 and libvirt. In Ubuntu, Debian, ... ``` -$ sudo apt-get install libxslt-dev libxml2-dev libvirt-dev +$ sudo apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ``` In RedHat, Centos, Fedora, ... From c5a6fd08f0751f0618546588fd878cef70bffb2d Mon Sep 17 00:00:00 2001 From: Nobuaki Sukegawa Date: Thu, 7 May 2015 00:52:32 +0900 Subject: [PATCH 23/86] Fix trivial bug where graphics_passwd could not be used with spice --- README.md | 2 +- lib/vagrant-libvirt/config.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1510938..ad83e54 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ end * `initrd` - To specify the initramfs/initrd to use for the guest. Equivalent to qemu `-initrd`. * `random_hostname` - To create a domain name with extra information on the end to prevent hostname conflicts. * `cmd_line` - Arguments passed on to the guest kernel initramfs or initrd to use. Equivalent to qemu `-append`. -* `graphics_type` - Sets the protocol used to expose the guest display. Defaults to `vnc`. Possible values are "sdl", "curses", "none", "gtk", or "vnc". +* `graphics_type` - Sets the protocol used to expose the guest display. Defaults to `vnc`. Possible values are "sdl", "curses", "none", "gtk", "vnc" or "spice". * `graphics_port` - Sets the port for the display protocol to bind to. Defaults to 5900. * `graphics_ip` - Sets the IP for the display protocol to bind to. Defaults to "127.0.0.0.1". * `graphics_passwd` - Sets the password for the display protocol. Working for vnc and spice. by default working without passsword. diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 61c42fb..94cf4f3 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -287,7 +287,7 @@ module VagrantPlugins @graphics_type = 'vnc' if @graphics_type == UNSET_VALUE @graphics_autoport = 'yes' if @graphics_port == UNSET_VALUE @graphics_autoport = 'no' if @graphics_port != UNSET_VALUE - if (@graphics_type != 'vnc' && @graphics_port != 'spice') || + if (@graphics_type != 'vnc' && @graphics_type != 'spice') || @graphics_passwd == UNSET_VALUE @graphics_passwd = nil end From ae37f17de8c599598dc8e57a57a44e2afa325f93 Mon Sep 17 00:00:00 2001 From: Felix Kaiser Date: Wed, 6 May 2015 19:51:26 +0200 Subject: [PATCH 24/86] Add :libvirt_host_ip and :libvirt_dhcp_start/stop This allows networks with gateways on addresses other than .1 (.254 is a popular choice). Resolves #357. --- README.md | 6 ++++++ lib/vagrant-libvirt/action/create_networks.rb | 18 +++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ad83e54..7f8f13e 100644 --- a/README.md +++ b/README.md @@ -240,8 +240,14 @@ starts with 'libvirt__' string. Here is a list of those options: network 'default' is used. * `:libvirt__netmask` - Used only together with `:ip` option. Default is '255.255.255.0'. +* `:libvirt__host_ip` - Adress to use for the host (not guest). + Default is first possible address (after network address). * `:libvirt__dhcp_enabled` - If DHCP will offer addresses, or not. Used only when creating new network. Default is true. +* `:libvirt__dhcp_start` - First address given out via DHCP. + Default is third address in range (after network name and gateway). +* `:libvirt__dhcp_stop` - Last address given out via DHCP. + Default is last possible address in range (before broadcast address). * `:libvirt__dhcp_bootp_file` - The file to be used for the boot image. Used only when dhcp is enabled. * `:libvirt__dhcp_bootp_server` - The server that runs the DHCP server. diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index 9df39db..90dd48e 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -121,7 +121,12 @@ module VagrantPlugins # Set IP address of network (actually bridge). It will be used as # gateway address for machines connected to this network. net = IPAddr.new(net_address) - @interface_network[:ip_address] = net.to_range.begin.succ + if @options[:host_ip].nil? + # Default to first address (after network name) + @interface_network[:ip_address] = net.to_range.begin.succ + else + @interface_network[:ip_address] = IPAddr.new @options[:host_ip] + end # Is there an available network matching to configured ip # address? @@ -235,14 +240,13 @@ module VagrantPlugins network_address << "#{@interface_network[:netmask]}" net = IPAddr.new(network_address) - # First is address of network, second is gateway. - # Start the range two - # addresses after network address. + # First is address of network, second is gateway (by default). + # So start the range two addresses after network address by default. # TODO: Detect if this IP is not set on the interface. - start_address = net.to_range.begin.succ.succ + start_address = @options[:dhcp_start] || net.to_range.begin.succ - # Stop address must not be broadcast. - stop_address = net.to_range.end & IPAddr.new('255.255.255.254') + # Default to last possible address. (Stop address must not be broadcast address.) + stop_address = @options[:dhcp_stop] || (net.to_range.end & IPAddr.new('255.255.255.254')) @network_dhcp_enabled = true @network_dhcp_bootp_file = @options[:dhcp_bootp_file] From 4cd1236e9ab4f2be75779d40927d3b44486e3dd8 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilets Date: Thu, 7 May 2015 12:38:32 +0200 Subject: [PATCH 25/86] simplify --- lib/vagrant-libvirt/action/create_networks.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index 90dd48e..1da5996 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -121,12 +121,8 @@ module VagrantPlugins # Set IP address of network (actually bridge). It will be used as # gateway address for machines connected to this network. net = IPAddr.new(net_address) - if @options[:host_ip].nil? - # Default to first address (after network name) - @interface_network[:ip_address] = net.to_range.begin.succ - else - @interface_network[:ip_address] = IPAddr.new @options[:host_ip] - end + # Default to first address (after network name) + @interface_network[:ip_address] = @options[:host_ip].nil? ? net.to_range.begin.succ : IPAddr.new @options[:host_ip] # Is there an available network matching to configured ip # address? From c80062dc384c49f73767a2d0436f0f5aaa04eee3 Mon Sep 17 00:00:00 2001 From: dima Date: Sun, 10 May 2015 19:35:20 +0200 Subject: [PATCH 26/86] typo --- lib/vagrant-libvirt/action/create_networks.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index 1da5996..a0d4e54 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -44,7 +44,8 @@ module VagrantPlugins # Get a list of all (active and inactive) libvirt networks. This # list is used throughout this class and should be easier to # process than libvirt API calls. - @available_networks = libvirt_networks(env[:libvirt_compute].client) + @available_networks = libvirt_networks( + env[:libvirt_compute].client) # Prepare a hash describing network for this specific interface. @interface_network = { @@ -56,7 +57,7 @@ module VagrantPlugins created: false, active: false, autostart: false, - libvirt_network: nil, + libvirt_network: nil } if @options[:ip] @@ -122,7 +123,7 @@ module VagrantPlugins # gateway address for machines connected to this network. net = IPAddr.new(net_address) # Default to first address (after network name) - @interface_network[:ip_address] = @options[:host_ip].nil? ? net.to_range.begin.succ : IPAddr.new @options[:host_ip] + @interface_network[:ip_address] = @options[:host_ip].nil? ? net.to_range.begin.succ : IPAddr.new(@options[:host_ip]) # Is there an available network matching to configured ip # address? From 88d9d9025d201332b0ba9920f6842cc1ac833a41 Mon Sep 17 00:00:00 2001 From: dima Date: Sun, 10 May 2015 22:17:44 +0200 Subject: [PATCH 27/86] 0.0.27 --- lib/vagrant-libvirt/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/version.rb b/lib/vagrant-libvirt/version.rb index 26cc284..5e13c62 100644 --- a/lib/vagrant-libvirt/version.rb +++ b/lib/vagrant-libvirt/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module ProviderLibvirt - VERSION = '0.0.26' + VERSION = '0.0.27' end end From c1da985934385abb45c1ea3c8bc16bfbb30df254 Mon Sep 17 00:00:00 2001 From: dima Date: Mon, 11 May 2015 19:11:28 +0200 Subject: [PATCH 28/86] fix deps --- lib/vagrant-libvirt/action/connect_libvirt.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/action/connect_libvirt.rb b/lib/vagrant-libvirt/action/connect_libvirt.rb index fd5d9d8..d34f6c5 100644 --- a/lib/vagrant-libvirt/action/connect_libvirt.rb +++ b/lib/vagrant-libvirt/action/connect_libvirt.rb @@ -1,4 +1,4 @@ -require 'fog' +require 'fog/libvirt' require 'log4r' module VagrantPlugins From 4a959d5dcf4a2c1df14a49c1a4ff983bfaf0ced0 Mon Sep 17 00:00:00 2001 From: dima Date: Mon, 11 May 2015 19:12:07 +0200 Subject: [PATCH 29/86] 0.0.28 --- lib/vagrant-libvirt/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/version.rb b/lib/vagrant-libvirt/version.rb index 5e13c62..6c4aad0 100644 --- a/lib/vagrant-libvirt/version.rb +++ b/lib/vagrant-libvirt/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module ProviderLibvirt - VERSION = '0.0.27' + VERSION = '0.0.28' end end From dbc857381b66e3e57a6a289e9eea32188f58c1df Mon Sep 17 00:00:00 2001 From: Dmitry Vasilets Date: Tue, 12 May 2015 09:38:17 +0200 Subject: [PATCH 30/86] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f8f13e..d940626 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ a `config.vm.provider` block. So first, add Libvirt box using any name you want. This is just an example of Libvirt CentOS 6.4 box available: ``` -vagrant box add centos64 http://citozin.com/fedora21.box +vagrant box add fedora21 http://citozin.com/fedora21.box # or vagrant box add centos64 http://citozin.com/centos64.box ``` From 182809e7213cefb985c4db0cfe76c3ef79e4ce24 Mon Sep 17 00:00:00 2001 From: dima Date: Wed, 13 May 2015 08:16:03 +0200 Subject: [PATCH 31/86] improve storage remove process. close #364 --- lib/vagrant-libvirt/action/destroy_domain.rb | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/vagrant-libvirt/action/destroy_domain.rb b/lib/vagrant-libvirt/action/destroy_domain.rb index 3ef7f9c..9948ab6 100644 --- a/lib/vagrant-libvirt/action/destroy_domain.rb +++ b/lib/vagrant-libvirt/action/destroy_domain.rb @@ -4,7 +4,7 @@ module VagrantPlugins module ProviderLibvirt module Action class DestroyDomain - def initialize(app, env) + def initialize(app, _env) @logger = Log4r::Logger.new('vagrant_libvirt::action::destroy_domain') @app = app end @@ -17,7 +17,8 @@ module VagrantPlugins # Fog libvirt currently doesn't support snapshots. Use # ruby-libvirt client directly. Note this is racy, see # http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotListNames - libvirt_domain = env[:libvirt_compute].client.lookup_domain_by_uuid(env[:machine].id) + libvirt_domain = env[:libvirt_compute].client.lookup_domain_by_uuid( + env[:machine].id) libvirt_domain.list_snapshots.each do |name| @logger.info("Deleting snapshot '#{name}'") begin @@ -36,14 +37,21 @@ module VagrantPlugins domain.destroy(destroy_volumes: false) env[:machine].provider_config.disks.each do |disk| - next if disk[:allow_existing] # shared disks remove only manualy or ??? - diskname = libvirt_domain.name + "-" + disk[:device] + ".raw" + # shared disks remove only manualy or ??? + next if disk[:allow_existing] + diskname = libvirt_domain.name + '-' + disk[:device] + '.' + disk[:type].to_s # diskname is uniq - env[:libvirt_compute].volumes.all.select{|x| x.name == diskname }.first.destroy + libvirt_disk = env[:libvirt_compute].volumes.all.select do |x| + x.name == diskname + end.first + libvirt_disk.destroy if libvirt_disk end - #remove root storage - env[:libvirt_compute].volumes.all.select{|x| x.name == libvirt_domain.name + ".img" }.first.destroy + # remove root storage + root_disk = env[:libvirt_compute].volumes.all.select do |x| + x.name == libvirt_domain.name + '.img' + end.first + root_disk.destroy if root_disk end @app.call(env) From c55119641183e4ee91d364580ace0e8ad8168c2d Mon Sep 17 00:00:00 2001 From: dima Date: Thu, 14 May 2015 10:06:55 +0200 Subject: [PATCH 32/86] fix for custom path --- lib/vagrant-libvirt/action/destroy_domain.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/action/destroy_domain.rb b/lib/vagrant-libvirt/action/destroy_domain.rb index 9948ab6..6d13d6a 100644 --- a/lib/vagrant-libvirt/action/destroy_domain.rb +++ b/lib/vagrant-libvirt/action/destroy_domain.rb @@ -44,7 +44,16 @@ module VagrantPlugins libvirt_disk = env[:libvirt_compute].volumes.all.select do |x| x.name == diskname end.first - libvirt_disk.destroy if libvirt_disk + if libvirt_disk + libvirt_disk.destroy + elsif disk[:path] + poolname = env[:machine].provider_config.storage_pool_name + libvirt_disk = env[:libvirt_compute].volumes.all.select do |x| + # FIXME can remove pool/target.img and pool/123/target.img + x.path =~ /\/#{disk[:path]}$/ && x.pool_name == poolname + end.first + libvirt_disk.destroy if libvirt_disk + end end # remove root storage From 311bdc5f23e6d8d2f4f10236fa094b7960b2fe9d Mon Sep 17 00:00:00 2001 From: dima Date: Fri, 15 May 2015 12:38:50 +0200 Subject: [PATCH 33/86] add linker trick for installation as gem --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index d940626..410df3d 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,13 @@ In RedHat, Centos, Fedora, ... # yum install libxslt-devel libxml2-devel libvirt-devel ``` +If have problem with installation - check your linker. It should be ld.gold: +``` +sudo alternatives --set ld /usr/bin/ld.gold +# OR +sudo ln -fs /usr/bin/ld.gold /usr/bin/ld +``` + ## Vagrant Project Preparation ### Add Box From a2ec37159ca45f2ab8efce636f39c9166f7c09c0 Mon Sep 17 00:00:00 2001 From: Patrick Truebe Date: Fri, 15 May 2015 15:29:20 +0200 Subject: [PATCH 34/86] Fixed wrong target spec in 9p-fs template --- lib/vagrant-libvirt/cap/synced_folder.rb | 3 ++- lib/vagrant-libvirt/templates/filesystem.xml.erb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-libvirt/cap/synced_folder.rb b/lib/vagrant-libvirt/cap/synced_folder.rb index 90e7133..a3ba6ca 100644 --- a/lib/vagrant-libvirt/cap/synced_folder.rb +++ b/lib/vagrant-libvirt/cap/synced_folder.rb @@ -43,7 +43,8 @@ module VagrantPlugins begin # loop through folders folders.each do |id, folder_opts| - folder_opts.merge!({ :accessmode => "passthrough", + folder_opts.merge!({ :target => id, + :accessmode => "passthrough", :readonly => nil }) { |_k, ov, _nv| ov } machine.ui.info "================\nMachine id: #{machine.id}\nShould be mounting folders\n #{id}, opts: #{folder_opts}" diff --git a/lib/vagrant-libvirt/templates/filesystem.xml.erb b/lib/vagrant-libvirt/templates/filesystem.xml.erb index 469cae6..d0a35c9 100644 --- a/lib/vagrant-libvirt/templates/filesystem.xml.erb +++ b/lib/vagrant-libvirt/templates/filesystem.xml.erb @@ -1,8 +1,8 @@ - + <% unless readonly.nil? %> <% end %> - \ No newline at end of file + From 834c6b74a9f05aec193bd1c55c36e5718d71e1ba Mon Sep 17 00:00:00 2001 From: Yucong Sun Date: Sat, 16 May 2015 16:41:10 +0800 Subject: [PATCH 35/86] Remove extra StartDomain/WaitTillUp Possibly a merge error introduced by https://github.com/pradels/vagrant-libvirt/commit/8d4f16a3f8d9e8c7b5fd2c4de8af6f47a1eea64c --- lib/vagrant-libvirt/action.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index 6910c74..7c3d47e 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -41,9 +41,6 @@ module VagrantPlugins b2.use StartDomain b2.use WaitTillUp - b2.use StartDomain - b2.use WaitTillUp - b2.use ForwardPorts b2.use PrepareNFSSettings From 9fcd9f587348efaa5741530cc5f0cb5e26f75fcf Mon Sep 17 00:00:00 2001 From: dima Date: Sat, 16 May 2015 12:05:01 +0200 Subject: [PATCH 36/86] clean file --- lib/vagrant-libvirt/cap/synced_folder.rb | 68 ++++++++++-------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/lib/vagrant-libvirt/cap/synced_folder.rb b/lib/vagrant-libvirt/cap/synced_folder.rb index a3ba6ca..95e4ef7 100644 --- a/lib/vagrant-libvirt/cap/synced_folder.rb +++ b/lib/vagrant-libvirt/cap/synced_folder.rb @@ -1,75 +1,65 @@ -require "log4r" +require 'log4r' require 'ostruct' require 'nokogiri' - -require "vagrant/util/subprocess" -require "vagrant/errors" -require "vagrant-libvirt/errors" +require 'vagrant/util/subprocess' +require 'vagrant/errors' +require 'vagrant-libvirt/errors' # require_relative "helper" module VagrantPlugins module SyncedFolder9p - class SyncedFolder < Vagrant.plugin("2", :synced_folder) + class SyncedFolder < Vagrant.plugin('2', :synced_folder) include Vagrant::Util include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate def initialize(*args) super - - @logger = Log4r::Logger.new("vagrant_libvirt::synced_folders::9p") + @logger = Log4r::Logger.new('vagrant_libvirt::synced_folders::9p') end - def usable?(machine, raise_error=false) + def usable?(machine, raise_error = false) # bail now if not using libvirt since checking version would throw error return false unless machine.provider_name == :libvirt # support in device attach/detach introduced in 1.2.2 # version number format is major * 1,000,000 + minor * 1,000 + release libvirt_version = ProviderLibvirt.libvirt_connection.client.libversion - if libvirt_version >= 1002002 - return true - else - return false - end + libvirt_version >= 1_002_002 end - def prepare(machine, folders, opts) - - raise Vagrant::Errors::Error("No libvirt connection") if ProviderLibvirt.libvirt_connection.nil? - + def prepare(machine, folders, _opts) + raise Vagrant::Errors::Error('No libvirt connection') if ProviderLibvirt.libvirt_connection.nil? @conn = ProviderLibvirt.libvirt_connection.client begin # loop through folders folders.each do |id, folder_opts| - folder_opts.merge!({ :target => id, - :accessmode => "passthrough", - :readonly => nil }) { |_k, ov, _nv| ov } + folder_opts.merge!({ target: id, + accessmode: 'passthrough', + readonly: nil }) { |_k, ov, _nv| ov } machine.ui.info "================\nMachine id: #{machine.id}\nShould be mounting folders\n #{id}, opts: #{folder_opts}" - - xml = to_xml('filesystem', folder_opts ) + xml = to_xml('filesystem', folder_opts) # puts "<<<<< XML:\n #{xml}\n >>>>>" @conn.lookup_domain_by_uuid(machine.id).attach_device(xml, 0) - - end + end rescue => e machine.ui.error("could not attach device because: #{e}") - raise VagrantPlugins::ProviderLibvirt::Errors::AttachDeviceError,:error_message => e.message + raise VagrantPlugins::ProviderLibvirt::Errors::AttachDeviceError, + error_message: e.message end end - # TODO once up, mount folders def enable(machine, folders, _opts) # Go through each folder and mount - machine.ui.info("mounting p9 share in guest") + machine.ui.info('mounting p9 share in guest') # Only mount folders that have a guest path specified. mount_folders = {} folders.each do |id, opts| mount_folders[id] = opts.dup if opts[:guestpath] # merge common options if not given - mount_folders[id].merge!(:version => '9p2000.L') { |_k, ov, _nv| ov } + mount_folders[id].merge!(version: '9p2000.L') { |_k, ov, _nv| ov } end # Mount the actual folder machine.guest.capability( @@ -77,27 +67,25 @@ module VagrantPlugins end def cleanup(machine, _opts) - - raise Vagrant::Errors::Error("No libvirt connection") if ProviderLibvirt.libvirt_connection.nil? - + if ProviderLibvirt.libvirt_connection.nil? + raise Vagrant::Errors::Error('No libvirt connection') + end @conn = ProviderLibvirt.libvirt_connection.client - begin - if machine.id && machine.id != "" + if machine.id && machine.id != '' dom = @conn.lookup_domain_by_uuid(machine.id) - Nokogiri::XML(dom.xml_desc).xpath('/domain/devices/filesystem').each do |xml| + Nokogiri::XML(dom.xml_desc).xpath( + '/domain/devices/filesystem').each do |xml| dom.detach_device(xml.to_s) - - machine.ui.info "Cleaned up shared folders" + machine.ui.info 'Cleaned up shared folders' end end rescue => e machine.ui.error("could not detach device because: #{e}") - raise VagrantPlugins::ProviderLibvirt::Errors::DetachDeviceError,:error_message => e.message + raise VagrantPlugins::ProviderLibvirt::Errors::DetachDeviceError, + error_message: e.message end - end - end end end From 08037d1941a394fc178a080a78cac177568bdc91 Mon Sep 17 00:00:00 2001 From: dima Date: Sat, 16 May 2015 17:35:00 +0200 Subject: [PATCH 37/86] port tools/create_box.sh to package action. close #11 --- lib/vagrant-libvirt/action.rb | 7 +- lib/vagrant-libvirt/action/destroy_domain.rb | 6 +- lib/vagrant-libvirt/action/package_domain.rb | 79 ++++++++++++++++++++ 3 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 lib/vagrant-libvirt/action/package_domain.rb diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index 7c3d47e..4c4f9cf 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -144,8 +144,10 @@ module VagrantPlugins # not implemented and looks like not require def self.action_package - lambda do |env| - raise Errors::PackageNotSupported + Vagrant::Action::Builder.new.tap do |b| + b.use ConfigValidate + b.use ConnectLibvirt + b.use PackageDomain end end @@ -317,6 +319,7 @@ module VagrantPlugins action_root = Pathname.new(File.expand_path('../action', __FILE__)) autoload :ConnectLibvirt, action_root.join('connect_libvirt') + autoload :PackageDomain, action_root.join('package_domain') autoload :CreateDomain, action_root.join('create_domain') autoload :CreateDomainVolume, action_root.join('create_domain_volume') autoload :CreateNetworkInterfaces, action_root.join('create_network_interfaces') diff --git a/lib/vagrant-libvirt/action/destroy_domain.rb b/lib/vagrant-libvirt/action/destroy_domain.rb index 6d13d6a..e4610be 100644 --- a/lib/vagrant-libvirt/action/destroy_domain.rb +++ b/lib/vagrant-libvirt/action/destroy_domain.rb @@ -41,14 +41,14 @@ module VagrantPlugins next if disk[:allow_existing] diskname = libvirt_domain.name + '-' + disk[:device] + '.' + disk[:type].to_s # diskname is uniq - libvirt_disk = env[:libvirt_compute].volumes.all.select do |x| + libvirt_disk = domain.volumes.select do |x| x.name == diskname end.first if libvirt_disk libvirt_disk.destroy elsif disk[:path] poolname = env[:machine].provider_config.storage_pool_name - libvirt_disk = env[:libvirt_compute].volumes.all.select do |x| + libvirt_disk = domain.volumes.select do |x| # FIXME can remove pool/target.img and pool/123/target.img x.path =~ /\/#{disk[:path]}$/ && x.pool_name == poolname end.first @@ -57,7 +57,7 @@ module VagrantPlugins end # remove root storage - root_disk = env[:libvirt_compute].volumes.all.select do |x| + root_disk = domain.volumes.select do |x| x.name == libvirt_domain.name + '.img' end.first root_disk.destroy if root_disk diff --git a/lib/vagrant-libvirt/action/package_domain.rb b/lib/vagrant-libvirt/action/package_domain.rb new file mode 100644 index 0000000..d1b58b8 --- /dev/null +++ b/lib/vagrant-libvirt/action/package_domain.rb @@ -0,0 +1,79 @@ +require 'log4r' + +module VagrantPlugins + module ProviderLibvirt + module Action + # Action for create new box for libvirt provider + class PackageDomain + def initialize(app, env) + @logger = Log4r::Logger.new('vagrant_libvirt::action::package_domain') + @app = app + env['package.files'] ||= {} + env['package.output'] ||= 'package.box' + end + + def call(env) + env[:ui].info(I18n.t('vagrant_libvirt.package_domain')) + libvirt_domain = env[:libvirt_compute].client.lookup_domain_by_uuid( + env[:machine].id) + domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s) + root_disk = domain.volumes.select do |x| + x.name == libvirt_domain.name + '.img' + end.first + boxname = env['package.output'] + raise "#{boxname}: Already exists" if File.exists?(boxname) + @tmp_dir = Dir.pwd + '/_tmp_package' + @tmp_img = @tmp_dir + '/box.img' + Dir.mkdir(@tmp_dir) + if File.readable?(root_disk.path) + backing = `qemu-img info "#{root_disk.path}" | grep 'backing file:' | cut -d ':' -f2`.chomp + else + env[:ui].error("Require set read access to #{root_disk.path}. sudo chmod a+r #{root_disk.path}") + FileUtils.rm_rf(@tmp_dir) + raise 'Have no access' + end + env[:ui].info('Image has backing image, copying image and rebasing ...') + FileUtils.cp(root_disk.path, @tmp_img) + `qemu-img rebase -p -b "" #{@tmp_img}` + Dir.chdir(@tmp_dir) + img_size = `qemu-img info #{@tmp_img} | grep 'virtual size' | awk '{print $3;}' | tr -d 'G'`.chomp + File.write(@tmp_dir + '/metadata.json', metadata_content(img_size)) + File.write(@tmp_dir + '/Vagrantfile',vagrantfile_content) + assebmle_box(boxname) + FileUtils.mv(@tmp_dir + '/' + boxname, '../' + boxname) + env[:ui].info('Box created') + env[:ui].info('You can now add the box:') + env[:ui].info("vagrant box add #{boxname} --name any_comfortable_name") + @app.call(env) + end + + def assebmle_box(boxname) + `tar cvzf "#{boxname}" --totals ./metadata.json ./Vagrantfile ./box.img` + end + + def vagrantfile_content + <<-EOF + Vagrant.configure("2") do |config| + config.vm.provider :libvirt do |libvirt| + libvirt.driver = "kvm" + libvirt.host = "" + libvirt.connect_via_ssh = false + libvirt.storage_pool_name = "default" + end + end + EOF + end + + def metadata_content(filesize) + <<-EOF + { + "provider": "libvirt", + "format": "qcow2", + "virtual_size": #{filesize} + } + EOF + end + end + end + end +end From 4af0163c5eef4dd0a897d65601517136f768e3c9 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilets Date: Sun, 17 May 2015 10:11:40 +0200 Subject: [PATCH 38/86] update readme with example accessmode 9p --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 410df3d..35dd317 100644 --- a/README.md +++ b/README.md @@ -375,6 +375,10 @@ You can change the synced folder type for */vagrant* by explicity configuring it an setting the type, e.g. config.vm.synced_folder './', '/vagrant', type: 'rsync' + + or + + ```config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "mapped"``` ## Customized Graphics From 78c525b3643825643deefd72003aab47af4a1414 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilets Date: Sun, 17 May 2015 10:12:42 +0200 Subject: [PATCH 39/86] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 35dd317..3ab1e85 100644 --- a/README.md +++ b/README.md @@ -378,7 +378,7 @@ it an setting the type, e.g. or - ```config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "mapped"``` + config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "mapped" ## Customized Graphics From c7f37649ecd82b6f728cc9f9d294e492dcc54a62 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilets Date: Sun, 17 May 2015 10:34:58 +0200 Subject: [PATCH 40/86] example for 9p --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ab1e85..a893324 100644 --- a/README.md +++ b/README.md @@ -378,7 +378,7 @@ it an setting the type, e.g. or - config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "mapped" + config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "squash", owner: "vagrant" ## Customized Graphics From 0a23a986b36f3c552a653ec22912c1aa7e45afa5 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 17 May 2015 18:37:13 +0800 Subject: [PATCH 41/86] Set private key for proxy_command --- lib/vagrant-libvirt/action/read_ssh_info.rb | 4 ++-- lib/vagrant-libvirt/config.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-libvirt/action/read_ssh_info.rb b/lib/vagrant-libvirt/action/read_ssh_info.rb index 0bee747..d7d8612 100644 --- a/lib/vagrant-libvirt/action/read_ssh_info.rb +++ b/lib/vagrant-libvirt/action/read_ssh_info.rb @@ -48,8 +48,8 @@ module VagrantPlugins :forward_agent => machine.config.ssh.forward_agent, :forward_x11 => machine.config.ssh.forward_x11, } - - ssh_info[:proxy_command] = "ssh '#{machine.provider_config.host}' -l '#{machine.provider_config.username}' nc %h %p" if machine.provider_config.connect_via_ssh + + ssh_info[:proxy_command] = "ssh '#{machine.provider_config.host}' -l '#{machine.provider_config.username}' -i '#{machine.provider_config.id_ssh_key_file}' nc %h %p" if machine.provider_config.connect_via_ssh ssh_info end diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 94cf4f3..c2543dc 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -248,7 +248,7 @@ module VagrantPlugins # set ssh key for access to libvirt host uri << "\&keyfile=" # if no slash, prepend $HOME/.ssh/ - uri << "#{`echo ${HOME}`.chomp}/.ssh/" if @id_ssh_key_file !~ /\A\// + @id_ssh_key_file.prepend("#{`echo ${HOME}`.chomp}/.ssh/") if @id_ssh_key_file !~ /\A\// uri << @id_ssh_key_file end # set path to libvirt socket From 91c768158a8e28e94434dd73413e14a6f3585e19 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 17 May 2015 19:02:41 +0800 Subject: [PATCH 42/86] Ensure VM booted and network configured before creating synced folders --- lib/vagrant-libvirt/action.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index 4c4f9cf..1618641 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -31,20 +31,18 @@ module VagrantPlugins b2.use CreateDomain b2.use Provision - b2.use CreateNetworks - b2.use CreateNetworkInterfaces - b2.use PrepareNFSValidIds b2.use SyncedFolderCleanup b2.use SyncedFolders + b2.use PrepareNFSSettings + b2.use ShareFolders + b2.use CreateNetworks + b2.use CreateNetworkInterfaces b2.use StartDomain b2.use WaitTillUp b2.use ForwardPorts - - b2.use PrepareNFSSettings - b2.use ShareFolders b2.use SetHostname # b2.use SyncFolders else From 0deb63911be98f5b44dfedc5f343e82faf273206 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 17 May 2015 19:08:40 +0800 Subject: [PATCH 43/86] Mounting nfs remotely through bridged public network, fixes #366 --- .../action/prepare_nfs_settings.rb | 66 ++++++++++++------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb index ebb9c54..1935660 100644 --- a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +++ b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb @@ -1,10 +1,13 @@ require 'nokogiri' +require 'socket' +require 'timeout' + module VagrantPlugins module ProviderLibvirt module Action class PrepareNFSSettings include Vagrant::Action::Builtin::MixinSyncedFolders - + def initialize(app,env) @app = app @logger = Log4r::Logger.new("vagrant::action::vm::nfs") @@ -16,8 +19,8 @@ module VagrantPlugins if using_nfs? @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP") - env[:nfs_host_ip] = read_host_ip(env[:machine],env) - env[:nfs_machine_ip] = env[:machine].ssh_info[:host] + env[:nfs_host_ip] = read_host_ip(env[:machine]) + env[:nfs_machine_ip] = read_machine_ip(env[:machine]) @logger.info("host IP: #{env[:nfs_host_ip]} machine IP: #{env[:nfs_machine_ip]}") @@ -32,37 +35,54 @@ module VagrantPlugins !!synced_folders(@machine)[:nfs] end - # Returns the IP address of the first host only network adapter + # Returns the IP address of the host # # @param [Machine] machine # @return [String] - def read_host_ip(machine,env) - nets = env[:libvirt_compute].list_networks - if nets.size == 1 - net = nets.first - else - domain = env[:libvirt_compute].servers.get(machine.id.to_s) - xml=Nokogiri::XML(domain.to_xml) - networkname = xml.xpath('/domain/devices/interface/source').first.attributes['network'].value.to_s - @logger.info("Using network named #{networkname}") - net = env[:libvirt_compute].list_networks.find {|netw| netw[:name] == networkname} + def read_host_ip(machine) + UDPSocket.open do |s| + s.connect(machine.ssh_info[:host], 1) + s.addr.last end - # FIXME better implement by libvirt xml parsing - `ip addr show | grep -A 2 #{net[:bridge_name]} | grep -i 'inet ' | tr -s ' ' | cut -d' ' -f3 | cut -d'/' -f 1`.chomp end - # Returns the IP address of the guest by looking at the first - # enabled host only network. + # Returns the IP address of the guest # + # @param [Machine] machine # @return [String] def read_machine_ip(machine) - machine.config.vm.networks.each do |type, options| - if type == :private_network && options[:ip].is_a?(String) - return options[:ip] - end + # check host only ip + ssh_host = machine.ssh_info[:host] + return ssh_host if ping(ssh_host) + + # check other ips + command = "LANG=en ifconfig |grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }'" + result = "" + machine.communicate.execute(command) do |type, data| + result << data if type == :stdout end - nil + ips = result.chomp.split("\n") + @logger.info("guest IPs: #{ips.join(', ')}") + ips.each do |ip| + next if ip == ssh_host + return ip if ping(ip) + end + end + + private + + # Check if we can open a connection to the host + def ping(host, timeout = 3) + timeout(timeout) do + s = TCPSocket.new(host, 'echo') + s.close + end + true + rescue Errno::ECONNREFUSED + true + rescue Timeout::Error, StandardError + false end end end From 6ffad6104f4b396ec327299582dad6b4e8c69aa6 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 17 May 2015 19:59:17 +0800 Subject: [PATCH 44/86] Replace ifconfig with ip addr --- lib/vagrant-libvirt/action/prepare_nfs_settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb index 1935660..0f9b796 100644 --- a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +++ b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb @@ -56,7 +56,7 @@ module VagrantPlugins return ssh_host if ping(ssh_host) # check other ips - command = "LANG=en ifconfig |grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }'" + command = "ip addr show | grep -i 'inet ' | grep -v '127.0.0.1' | tr -s ' ' | cut -d' ' -f3 | cut -d'/' -f 1" result = "" machine.communicate.execute(command) do |type, data| result << data if type == :stdout From 9ad2389a928d1e62b590b550294cf7810a51156c Mon Sep 17 00:00:00 2001 From: dima Date: Sun, 17 May 2015 16:39:05 +0200 Subject: [PATCH 45/86] remove temp dir after package creation --- lib/vagrant-libvirt/action/package_domain.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/vagrant-libvirt/action/package_domain.rb b/lib/vagrant-libvirt/action/package_domain.rb index d1b58b8..5b89bf9 100644 --- a/lib/vagrant-libvirt/action/package_domain.rb +++ b/lib/vagrant-libvirt/action/package_domain.rb @@ -41,6 +41,7 @@ module VagrantPlugins File.write(@tmp_dir + '/Vagrantfile',vagrantfile_content) assebmle_box(boxname) FileUtils.mv(@tmp_dir + '/' + boxname, '../' + boxname) + FileUtils.rm_rf(@tmp_dir) env[:ui].info('Box created') env[:ui].info('You can now add the box:') env[:ui].info("vagrant box add #{boxname} --name any_comfortable_name") From 4de1560027653b5f331a5838d41805974a35146d Mon Sep 17 00:00:00 2001 From: dima Date: Sun, 17 May 2015 19:47:07 +0200 Subject: [PATCH 46/86] improve package process --- README.md | 10 +++++----- lib/vagrant-libvirt/action/package_domain.rb | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a893324..a3dbded 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ welcome and can help a lot :-) ## Features * Control local Libvirt hypervisors. -* Vagrant `up`, `destroy`, `suspend`, `resume`, `halt`, `ssh`, `reload` and `provision` commands. +* Vagrant `up`, `destroy`, `suspend`, `resume`, `halt`, `ssh`, `reload`, `package` and `provision` commands. * Upload box image (qcow2 format) to Libvirt storage pool. * Create volume as COW diff image for domains. * Create private networks. @@ -51,7 +51,7 @@ $ sudo apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev In RedHat, Centos, Fedora, ... ``` -# yum install libxslt-devel libxml2-devel libvirt-devel +# yum install libxslt-devel libxml2-devel libvirt-devel libguestfs-tools-c ``` If have problem with installation - check your linker. It should be ld.gold: @@ -375,9 +375,9 @@ You can change the synced folder type for */vagrant* by explicity configuring it an setting the type, e.g. config.vm.synced_folder './', '/vagrant', type: 'rsync' - - or - + + or + config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "squash", owner: "vagrant" ## Customized Graphics diff --git a/lib/vagrant-libvirt/action/package_domain.rb b/lib/vagrant-libvirt/action/package_domain.rb index 5b89bf9..c9ce42a 100644 --- a/lib/vagrant-libvirt/action/package_domain.rb +++ b/lib/vagrant-libvirt/action/package_domain.rb @@ -35,6 +35,9 @@ module VagrantPlugins env[:ui].info('Image has backing image, copying image and rebasing ...') FileUtils.cp(root_disk.path, @tmp_img) `qemu-img rebase -p -b "" #{@tmp_img}` + # remove hw association with interface + # working for centos with lvs default disks + `virt-sysprep --no-logfile -a #{@tmp_img} ` Dir.chdir(@tmp_dir) img_size = `qemu-img info #{@tmp_img} | grep 'virtual size' | awk '{print $3;}' | tr -d 'G'`.chomp File.write(@tmp_dir + '/metadata.json', metadata_content(img_size)) From d4b013a66dd605c49804c07006254092729a2931 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Mon, 18 May 2015 11:46:04 +0800 Subject: [PATCH 47/86] Add note for remote nfs synced folders --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a3dbded..0e0cd49 100644 --- a/README.md +++ b/README.md @@ -380,6 +380,8 @@ it an setting the type, e.g. config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "squash", owner: "vagrant" +**NOTE:** for remote libvirt, nfs synced folders requires a bridged public network interface and you must connect to libvirt via ssh. + ## Customized Graphics vagrant-libvirt supports customizing the display and video settings of the @@ -459,4 +461,3 @@ IMPORTANT NOTE: bundle is crucial. You need to use bundled vagrant. 3. Commit your changes (`git commit -am 'Add some feature'`). 4. Push to the branch (`git push origin my-new-feature`). 5. Create new Pull Request. - From 298a45d3d83b830e93320794cbe514e0c4d4460e Mon Sep 17 00:00:00 2001 From: Christian Kampka Date: Sun, 17 May 2015 21:20:22 +0200 Subject: [PATCH 48/86] Add ability to specify the machine architecture via the domain arguments --- README.md | 2 +- lib/vagrant-libvirt/action/create_domain.rb | 1 + lib/vagrant-libvirt/config.rb | 3 +++ lib/vagrant-libvirt/templates/domain.xml.erb | 18 +++++++++++++----- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a3dbded..23fd89b 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,7 @@ end * `keymap` - Set keymap for vm. default: en-us * `video_vram` - Used by some graphics card types to vary the amount of RAM dedicated to video. Defaults to 9216. * `machine` - Sets machine type. Equivalent to qemu `-machine`. Use `qemu-system-x86_64 -machine help` to get a list of supported machines. +* `machine_arch` - Sets machine architecture. This helps libvirt to determine the correct emulator type. Possible values depend on your version of qemu. For possible values, see which emulator executable `qemu-system-*` your system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`, `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`, `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`, `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`, `xtensa`, `xtensaeb`. Specific domain settings can be set for each domain separately in multi-VM @@ -459,4 +460,3 @@ IMPORTANT NOTE: bundle is crucial. You need to use bundled vagrant. 3. Commit your changes (`git commit -am 'Add some feature'`). 4. Push to the branch (`git push origin my-new-feature`). 5. Create new Pull Request. - diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 428f524..740cc46 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -34,6 +34,7 @@ module VagrantPlugins @cpus = config.cpus.to_i @cpu_mode = config.cpu_mode @machine_type = config.machine_type + @machine_arch = config.machine_arch @disk_bus = config.disk_bus @nested = config.nested @memory_size = config.memory.to_i * 1024 diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index c2543dc..c52eca2 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -56,6 +56,7 @@ module VagrantPlugins attr_accessor :cpus attr_accessor :cpu_mode attr_accessor :machine_type + attr_accessor :machine_arch attr_accessor :disk_bus attr_accessor :nic_model_type attr_accessor :nested @@ -95,6 +96,7 @@ module VagrantPlugins @cpus = UNSET_VALUE @cpu_mode = UNSET_VALUE @machine_type = UNSET_VALUE + @machine_arch = UNSET_VALUE @disk_bus = UNSET_VALUE @nic_model_type = UNSET_VALUE @nested = UNSET_VALUE @@ -277,6 +279,7 @@ module VagrantPlugins @cpus = 1 if @cpus == UNSET_VALUE @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE @machine_type = nil if @machine_type == UNSET_VALUE + @machine_arch = nil if @machine_arch == UNSET_VALUE @disk_bus = 'virtio' if @disk_bus == UNSET_VALUE @nic_model_type = 'virtio' if @nic_model_type == UNSET_VALUE @nested = false if @nested == UNSET_VALUE diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 3f06c78..1d01a89 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -14,11 +14,19 @@ <% end %> - <% if @machine_type %> - hvm - <% else %> - hvm - <% end %> + <% if @machine_type %> + <% if @machine_arch %> + hvm + <% else %> + hvm + <% end %> + <% else %> + <% if @machine_arch %> + hvm + <% else %> + hvm + <% end %> + <% end %> <%= @kernel %> <%= @initrd %> From 98e4b3b0bec0f9be507ecff69b28b6803b1ecab3 Mon Sep 17 00:00:00 2001 From: dima Date: Mon, 18 May 2015 07:48:39 +0200 Subject: [PATCH 49/86] typo --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2cbba7..09a07fc 100644 --- a/README.md +++ b/README.md @@ -381,7 +381,8 @@ it an setting the type, e.g. config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "squash", owner: "vagrant" -**NOTE:** for remote libvirt, nfs synced folders requires a bridged public network interface and you must connect to libvirt via ssh. +**SECURITY NOTE:** for remote libvirt, nfs synced folders requires a bridged public network interface and you must connect to libvirt via ssh. + ## Customized Graphics From fa004ab25126e4c6c9a653c9b92ac7e027cb0406 Mon Sep 17 00:00:00 2001 From: dima Date: Mon, 18 May 2015 09:30:29 +0200 Subject: [PATCH 50/86] require only read for create image --- tools/create_box.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/create_box.sh b/tools/create_box.sh index 78ceaf9..9f35409 100755 --- a/tools/create_box.sh +++ b/tools/create_box.sh @@ -60,7 +60,7 @@ TMP_IMG="$TMP_DIR/box.img" mkdir -p "$TMP_DIR" -[[ ! -w "$IMG" ]] && error "'$IMG': Permission denied" +[[ ! -r "$IMG" ]] && error "'$IMG': Permission denied" # We move / copy (when the image has master) the image to the tempdir # ensure that it's moved back / removed again From b6babcdade6a49beae44eae6a7abafae33735243 Mon Sep 17 00:00:00 2001 From: dima Date: Fri, 22 May 2015 06:44:40 +0200 Subject: [PATCH 51/86] 0.0.29 --- lib/vagrant-libvirt/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/version.rb b/lib/vagrant-libvirt/version.rb index 6c4aad0..dadbc6f 100644 --- a/lib/vagrant-libvirt/version.rb +++ b/lib/vagrant-libvirt/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module ProviderLibvirt - VERSION = '0.0.28' + VERSION = '0.0.29' end end From c5a6107ead6e00c8fb51c42b7bc426c612eca337 Mon Sep 17 00:00:00 2001 From: Romuald du Song Date: Sat, 23 May 2015 15:44:27 +0200 Subject: [PATCH 52/86] change repo ref to https --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index e4d5772..c93c514 100644 --- a/Gemfile +++ b/Gemfile @@ -7,11 +7,11 @@ group :development do # We depend on Vagrant for development, but we don't add it as a # gem dependency because we expect to be installed within the # Vagrant environment itself using `vagrant plugin`. - gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git" + gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant.git' gem 'pry' end group :plugins do - gem "vagrant-libvirt", :path => '.' + gem 'vagrant-libvirt', :path => '.' end From 2e01a54fc35337b4a94e7286c5281d4ca10d9e81 Mon Sep 17 00:00:00 2001 From: Romuald du Song Date: Sat, 23 May 2015 21:49:51 +0200 Subject: [PATCH 53/86] add step to remove stale volume on destroy action --- lib/vagrant-libvirt/action.rb | 11 ++++- .../action/remove_stale_volume.rb | 49 +++++++++++++++++++ locales/en.yml | 2 + 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 lib/vagrant-libvirt/action/remove_stale_volume.rb diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index 1618641..48f1605 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -156,7 +156,14 @@ module VagrantPlugins b.use ConfigValidate b.use Call, IsCreated do |env, b2| if !env[:result] - b2.use MessageNotCreated + # Try to remove stale volumes anyway + b2.use ConnectLibvirt + b2.use SetNameOfDomain + b2.use RemoveStaleVolume + if !env[:result] + b2.use MessageNotCreated + end + next end @@ -338,6 +345,8 @@ module VagrantPlugins autoload :MessageNotRunning, action_root.join('message_not_running') autoload :MessageNotSuspended, action_root.join('message_not_suspended') + autoload :RemoveStaleVolume, action_root.join('remove_stale_volume') + autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings') autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids') autoload :PruneNFSExports, action_root.join('prune_nfs_exports') diff --git a/lib/vagrant-libvirt/action/remove_stale_volume.rb b/lib/vagrant-libvirt/action/remove_stale_volume.rb new file mode 100644 index 0000000..5b3c876 --- /dev/null +++ b/lib/vagrant-libvirt/action/remove_stale_volume.rb @@ -0,0 +1,49 @@ +require 'log4r' +#require 'log4r/yamlconfigurator' + +module VagrantPlugins + module ProviderLibvirt + module Action + class RemoveStaleVolume + def initialize(app, _env) + +# log4r_config= YAML.load_file(File.join(File.dirname(__FILE__),"log4r.yaml")) +# log_cfg = Log4r::YamlConfigurator +# log_cfg.decode_yaml( log4r_config['log4r_config'] ) + + @logger = Log4r::Logger.new('vagrant_libvirt::action::remove_stale_volume') + @app = app + end + + def call(env) + # Remove stale server volume + env[:ui].info(I18n.t('vagrant_libvirt.remove_stale_volume')) + + config = env[:machine].provider_config + # Check for storage pool, where box image should be created + fog_pool = ProviderLibvirt::Util::Collection.find_matching( + env[:libvirt_compute].pools.all, config.storage_pool_name) + @logger.debug("**** Pool #{fog_pool.name}") + + # This is name of newly created image for vm. + name = "#{env[:domain_name]}.img" + @logger.debug("**** Volume name #{name}") + + # remove root storage + box_volume = ProviderLibvirt::Util::Collection.find_matching( + env[:libvirt_compute].volumes.all, name) + if box_volume && box_volume.pool_name == fog_pool.name + @logger.info("Deleting volume #{box_volume.key}") + box_volume.destroy + env[:result] = box_volume + else + env[:result] = nil + end + + # Continue the middleware chain. + @app.call(env) + end + end + end + end +end diff --git a/locales/en.yml b/locales/en.yml index 38da9bf..7118fd9 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -44,6 +44,8 @@ en: Rsyncing folder: %{hostpath} => %{guestpath} ready: |- Machine is booted and ready for use! + remove_stale_volume: |- + Remove stale volume... errors: package_not_supported: Not support package for libvirt. Create box manualy. From ba619e04bb007a48d9f6656eeb1f331aa8392ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ne=C4=8Das?= Date: Wed, 27 May 2015 12:51:31 +0200 Subject: [PATCH 54/86] Don't raise an error when ip address is not found when calling ssh_info Vagrant defines that, when the ssh info is not available, the method should return nil, instead of raising exception: https://github.com/mitchellh/vagrant/blob/v1.7.2/lib/vagrant/plugin/v2/provider.rb#L52-L75 Also, as per https://github.com/mitchellh/vagrant/blob/efd1d5e11bfc5a72c7a1d1eae294b4751d841544/plugins/providers/virtualbox/provider.rb#L60 , not getting into waiting for the ssh info when the machine is not running. The motivation for this patch is the ansible integration issues when raising the errors and waiting for the ssh info. See also: https://github.com/mitchellh/vagrant/pull/5743 --- lib/vagrant-libvirt/action/read_ssh_info.rb | 25 ++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/vagrant-libvirt/action/read_ssh_info.rb b/lib/vagrant-libvirt/action/read_ssh_info.rb index d7d8612..3d7ea9d 100644 --- a/lib/vagrant-libvirt/action/read_ssh_info.rb +++ b/lib/vagrant-libvirt/action/read_ssh_info.rb @@ -20,6 +20,7 @@ module VagrantPlugins def read_ssh_info(libvirt, machine) return nil if machine.id.nil? + return nil if machine.state.id != :running # Find the machine domain = libvirt.servers.get(machine.id) @@ -32,15 +33,23 @@ module VagrantPlugins # Get IP address from dnsmasq lease file. ip_address = nil - domain.wait_for(2) { - addresses.each_pair do |type, ip| - # Multiple leases are separated with a newline, return only - # the most recent address - ip_address = ip[0].split("\n").first if ip[0] != nil + begin + domain.wait_for(2) do + addresses.each_pair do |type, ip| + # Multiple leases are separated with a newline, return only + # the most recent address + ip_address = ip[0].split("\n").first if ip[0] != nil + end + ip_address != nil end - ip_address != nil - } - raise Errors::NoIpAddressError if not ip_address + rescue Fog::Errors::TimeoutError + @logger.info("Timeout at waiting for an ip address for machine %s" % machine.name) + end + + if not ip_address + @logger.info("No lease found for machine %s" % machine.name) + return nil + end ssh_info = { :host => ip_address, From 6c0d15288e905a3ed254c6ac1c527cb39191f662 Mon Sep 17 00:00:00 2001 From: Brad Wadsworth Date: Fri, 29 May 2015 16:32:20 -0500 Subject: [PATCH 55/86] added boot_order option --- lib/vagrant-libvirt/action/create_domain.rb | 8 ++++++++ lib/vagrant-libvirt/config.rb | 17 +++++++++++++++++ lib/vagrant-libvirt/templates/domain.xml.erb | 4 +++- spec/support/environment_helper.rb | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 740cc46..f0e1de4 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -54,6 +54,9 @@ module VagrantPlugins @video_type = config.video_type @video_vram = config.video_vram @keymap = config.keymap + + # Boot order + @boot_order = config.boot_order # Storage @storage_pool_name = config.storage_pool_name @@ -124,6 +127,10 @@ module VagrantPlugins env[:ui].info(" -- Video Type: #{@video_type}") env[:ui].info(" -- Video VRAM: #{@video_vram}") env[:ui].info(" -- Keymap: #{@keymap}") + + @boot_order.each do |device| + env[:ui].info(" -- Boot device: #{device}") + end if @disks.length > 0 env[:ui].info(" -- Disks: #{_disks_print(@disks)}") @@ -150,6 +157,7 @@ module VagrantPlugins # Is there a way to tell fog to create new domain with already # existing volume? Use domain creation from template.. begin + print to_xml('domain') server = env[:libvirt_compute].servers.create( xml: to_xml('domain')) rescue Fog::Errors::Error => e diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index c52eca2..58e80cc 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -55,6 +55,7 @@ module VagrantPlugins attr_accessor :memory attr_accessor :cpus attr_accessor :cpu_mode + attr_accessor :boot_order attr_accessor :machine_type attr_accessor :machine_arch attr_accessor :disk_bus @@ -113,10 +114,23 @@ module VagrantPlugins @video_vram = UNSET_VALUE @keymap = UNSET_VALUE + # Boot order + @boot_order = [] # Storage @disks = [] @cdroms = [] end + + def _handle_boot_order(options={}) + boot_order = { + :dev => options[:dev] + } + @boot_order << boot_order # append + end + + def boot(options={}) + _handle_boot_order(options) + end def _get_device(disks) # skip existing devices and also the first one (vda) @@ -299,6 +313,9 @@ module VagrantPlugins @video_type = 'cirrus' if @video_type == UNSET_VALUE @video_vram = 9216 if @video_vram == UNSET_VALUE @keymap = 'en-us' if @keymap == UNSET_VALUE + + # Boot order + @boot_order = [] if @boot_order == UNSET_VALUE # Storage @disks = [] if @disks == UNSET_VALUE diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 1d01a89..3685e30 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -27,7 +27,9 @@ hvm <% end %> <% end %> - + <% @boot_order.each do |b| %> + + <% end %> <%= @kernel %> <%= @initrd %> <%= @cmd_line %> diff --git a/spec/support/environment_helper.rb b/spec/support/environment_helper.rb index c6e73d1..ddfa43b 100644 --- a/spec/support/environment_helper.rb +++ b/spec/support/environment_helper.rb @@ -19,7 +19,7 @@ class EnvironmentHelper 1024 end - %w(cpus cpu_mode machine_type disk_bus nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms driver).each do |name| + %w(cpus cpu_mode boot_order machine_type disk_bus nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms driver).each do |name| define_method(name.to_sym) do nil end From ba9050984ecde310ef9bcb8a36faf09156e272e7 Mon Sep 17 00:00:00 2001 From: coding Date: Mon, 1 Jun 2015 11:51:42 +0800 Subject: [PATCH 56/86] Make NFS correctly detect host/guest addresses. The logic is that we first gather all usable guest addresses, then use routing information (through a udp socket) to figure out host IP for use to connect to guest. --- lib/vagrant-libvirt/action/prepare_nfs_settings.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb index 0f9b796..b74268a 100644 --- a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +++ b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb @@ -19,8 +19,8 @@ module VagrantPlugins if using_nfs? @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP") - env[:nfs_host_ip] = read_host_ip(env[:machine]) env[:nfs_machine_ip] = read_machine_ip(env[:machine]) + env[:nfs_host_ip] = read_host_ip(env[:nfs_machine_ip]) @logger.info("host IP: #{env[:nfs_host_ip]} machine IP: #{env[:nfs_machine_ip]}") @@ -39,9 +39,9 @@ module VagrantPlugins # # @param [Machine] machine # @return [String] - def read_host_ip(machine) + def read_host_ip(ip) UDPSocket.open do |s| - s.connect(machine.ssh_info[:host], 1) + s.connect(ip, 1) s.addr.last end end From 23d0a5b012c2e0a316e74e7621c5131037469553 Mon Sep 17 00:00:00 2001 From: Brad Wadsworth Date: Mon, 1 Jun 2015 10:19:06 -0500 Subject: [PATCH 57/86] changes to boot order option --- README.md | 1 + lib/vagrant-libvirt/action/create_domain.rb | 1 - lib/vagrant-libvirt/config.rb | 11 ++--------- lib/vagrant-libvirt/templates/domain.xml.erb | 5 ++++- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 09a07fc..c90427a 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,7 @@ end * `video_vram` - Used by some graphics card types to vary the amount of RAM dedicated to video. Defaults to 9216. * `machine` - Sets machine type. Equivalent to qemu `-machine`. Use `qemu-system-x86_64 -machine help` to get a list of supported machines. * `machine_arch` - Sets machine architecture. This helps libvirt to determine the correct emulator type. Possible values depend on your version of qemu. For possible values, see which emulator executable `qemu-system-*` your system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`, `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`, `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`, `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`, `xtensa`, `xtensaeb`. +* `boot` - Change the boot order and enables the boot menu. Defaults to 'hd' with boot menu disabled. Specific domain settings can be set for each domain separately in multi-VM diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index f0e1de4..8909971 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -157,7 +157,6 @@ module VagrantPlugins # Is there a way to tell fog to create new domain with already # existing volume? Use domain creation from template.. begin - print to_xml('domain') server = env[:libvirt_compute].servers.create( xml: to_xml('domain')) rescue Fog::Errors::Error => e diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 58e80cc..bc446d6 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -121,15 +121,8 @@ module VagrantPlugins @cdroms = [] end - def _handle_boot_order(options={}) - boot_order = { - :dev => options[:dev] - } - @boot_order << boot_order # append - end - - def boot(options={}) - _handle_boot_order(options) + def boot(device) + @boot_order << device # append end def _get_device(disks) diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 3685e30..fb9e443 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -28,8 +28,11 @@ <% end %> <% end %> <% @boot_order.each do |b| %> - + <% end %> + <% if @boot_order.count >= 1 %> + + <% end %> <%= @kernel %> <%= @initrd %> <%= @cmd_line %> From 0b2ebc102b4317c94c004487a3dfe85dc70a37ac Mon Sep 17 00:00:00 2001 From: Brad Wadsworth Date: Mon, 1 Jun 2015 10:26:31 -0500 Subject: [PATCH 58/86] edited domain.xml.erb --- lib/vagrant-libvirt/templates/domain.xml.erb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index fb9e443..a617b63 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -27,11 +27,13 @@ hvm <% end %> <% end %> - <% @boot_order.each do |b| %> - - <% end %> <% if @boot_order.count >= 1 %> + <% @boot_order.each do |b| %> + + <% end %> + <% else %> + <% end %> <%= @kernel %> <%= @initrd %> From 56818642e567ade160515074fb68f59c5bd392d1 Mon Sep 17 00:00:00 2001 From: Brad Wadsworth Date: Tue, 2 Jun 2015 20:31:21 -0500 Subject: [PATCH 59/86] fixed indent and added example --- README.md | 19 ++++++++++++++++++- lib/vagrant-libvirt/templates/domain.xml.erb | 6 +++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c90427a..dc550cb 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ end * `video_vram` - Used by some graphics card types to vary the amount of RAM dedicated to video. Defaults to 9216. * `machine` - Sets machine type. Equivalent to qemu `-machine`. Use `qemu-system-x86_64 -machine help` to get a list of supported machines. * `machine_arch` - Sets machine architecture. This helps libvirt to determine the correct emulator type. Possible values depend on your version of qemu. For possible values, see which emulator executable `qemu-system-*` your system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`, `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`, `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`, `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`, `xtensa`, `xtensaeb`. -* `boot` - Change the boot order and enables the boot menu. Defaults to 'hd' with boot menu disabled. +* `boot` - Change the boot order and enables the boot menu. Possible options are "hd" or "network. Defaults to "hd" with boot menu disabled. Specific domain settings can be set for each domain separately in multi-VM @@ -192,6 +192,23 @@ Vagrant.configure("2") do |config| # ... ``` +The following example shows part of a Vagrantfile that enables the VM to +boot from a network interface first and a hard disk second. This could be +used to run VMs that are meant to be a PXE booted machines. + +```ruby +Vagrant.configure("2") do |config| + config.vm.define :pxeclient do |pxeclient| + pxeclient.vm.box = "centos64" + pxeclient.vm.provider :libvirt do |domain| + domain.boot 'network' + domain.boot 'hd' + end + end + + # ... +``` + ## Networks Networking features in the form of `config.vm.network` support private networks diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index a617b63..e1264fb 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -29,11 +29,11 @@ <% end %> <% if @boot_order.count >= 1 %> <% @boot_order.each do |b| %> - + <% end %> - + <% else %> - + <% end %> <%= @kernel %> <%= @initrd %> From 0851b5d80412ecd3584d7ebc0d9bf332fdfaf425 Mon Sep 17 00:00:00 2001 From: Brad Wadsworth Date: Tue, 2 Jun 2015 20:33:37 -0500 Subject: [PATCH 60/86] fixed grammar --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dc550cb..6e8bd19 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ end * `video_vram` - Used by some graphics card types to vary the amount of RAM dedicated to video. Defaults to 9216. * `machine` - Sets machine type. Equivalent to qemu `-machine`. Use `qemu-system-x86_64 -machine help` to get a list of supported machines. * `machine_arch` - Sets machine architecture. This helps libvirt to determine the correct emulator type. Possible values depend on your version of qemu. For possible values, see which emulator executable `qemu-system-*` your system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`, `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`, `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`, `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`, `xtensa`, `xtensaeb`. -* `boot` - Change the boot order and enables the boot menu. Possible options are "hd" or "network. Defaults to "hd" with boot menu disabled. +* `boot` - Change the boot order and enables the boot menu. Possible options are "hd" or "network". Defaults to "hd" with boot menu disabled. Specific domain settings can be set for each domain separately in multi-VM From d12405ed82e893a0ddbbf481312c1c1d703a9219 Mon Sep 17 00:00:00 2001 From: dima Date: Thu, 4 Jun 2015 22:46:55 +0200 Subject: [PATCH 61/86] 0.0.30 --- lib/vagrant-libvirt/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/version.rb b/lib/vagrant-libvirt/version.rb index dadbc6f..e29adef 100644 --- a/lib/vagrant-libvirt/version.rb +++ b/lib/vagrant-libvirt/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module ProviderLibvirt - VERSION = '0.0.29' + VERSION = '0.0.30' end end From ac7563e6c389f8d12c07f51fa69984d77e58ba50 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Mon, 8 Jun 2015 14:52:40 +0100 Subject: [PATCH 62/86] Fixes #387: Break from mutex synchronize before calling next action Exit the synchronize block before performing calling the next item in the middleware chain otherwise the mutex lock applies to the entire provision sequence from that point onwards until the entire chain has returned to the same point. Executing a return statement inside a block does not exit the block automatically. Instead only when the statement returned has been processed is the wrapping block exited. Since the return call is actually calling the next action in the chain, this change ensures that the mutex is not held for subsequent actions and thus allows vagrant to perform remaining actions in parallel. Without this all provisioning of machines will always occur serially instead of parallel when requested. --- lib/vagrant-libvirt/action/handle_box_image.rb | 5 ++++- lib/vagrant-libvirt/action/handle_storage_pool.rb | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/vagrant-libvirt/action/handle_box_image.rb b/lib/vagrant-libvirt/action/handle_box_image.rb index 45dacf0..b08ed17 100644 --- a/lib/vagrant-libvirt/action/handle_box_image.rb +++ b/lib/vagrant-libvirt/action/handle_box_image.rb @@ -37,9 +37,12 @@ module VagrantPlugins env[:box_volume_name] = env[:machine].box.name.to_s.dup.gsub("/", "-VAGRANTSLASH-") env[:box_volume_name] << "_vagrant_box_image_#{env[:machine].box.version.to_s rescue ''}.img" + # while inside the synchronize block take care not to call the next + # action in the chain, as must exit this block first to prevent + # locking all subsequent actions as well. @@lock.synchronize do # Don't continue if image already exists in storage pool. - return @app.call(env) if ProviderLibvirt::Util::Collection.find_matching( + break if ProviderLibvirt::Util::Collection.find_matching( env[:libvirt_compute].volumes.all, env[:box_volume_name]) # Box is not available as a storage pool volume. Create and upload diff --git a/lib/vagrant-libvirt/action/handle_storage_pool.rb b/lib/vagrant-libvirt/action/handle_storage_pool.rb index e405638..f567687 100644 --- a/lib/vagrant-libvirt/action/handle_storage_pool.rb +++ b/lib/vagrant-libvirt/action/handle_storage_pool.rb @@ -14,14 +14,16 @@ module VagrantPlugins end def call(env) - @@lock.synchronize do - # Get config options. - config = env[:machine].provider_config + # Get config options. + config = env[:machine].provider_config + # while inside the synchronize block take care not to call the next + # action in the chain, as must exit this block first to prevent + # locking all subsequent actions as well. + @@lock.synchronize do # Check for storage pool, where box image should be created - fog_pool = ProviderLibvirt::Util::Collection.find_matching( + break if ProviderLibvirt::Util::Collection.find_matching( env[:libvirt_compute].pools.all, config.storage_pool_name) - return @app.call(env) if fog_pool @logger.info("No storage pool '#{config.storage_pool_name}' is available.") From bc517934c293f7e34508be3f0ae3cbe6d2e23bb2 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Tue, 9 Jun 2015 18:07:45 +0100 Subject: [PATCH 63/86] Use storage pool to identify correct volume Compare storage pool on the found volumes to avoid selecting a disk from a different and unreachable to the domain storage pool. Users may move between storage pools by configuring the driver which will mean that it is possible to find the same image name in multiple storage pools and incorrectly perform operations based on the one not associated with the currently specified pool. When using persistent images to attach to storage this will cause domain creation to fail since although the image was found in one of the storage pools, it may not be connected since it does not exist in the storage pool requested for the VM. --- lib/vagrant-libvirt/action/create_domain.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 8909971..e267c1e 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -68,9 +68,10 @@ module VagrantPlugins @os_type = 'hvm' - # Get path to domain image. + # Get path to domain image from the storage pool selected. domain_volume = ProviderLibvirt::Util::Collection.find_matching( - env[:libvirt_compute].volumes.all, "#{@name}.img") + env[:libvirt_compute].volumes.all.select { |x| x.pool_name == @storage_pool_name }, + "#{@name}.img") raise Errors::DomainVolumeExists if domain_volume.nil? @domain_volume_path = domain_volume.path @@ -88,7 +89,8 @@ module VagrantPlugins disk[:absolute_path] = storage_prefix + disk[:path] - if env[:libvirt_compute].volumes.all.select {|x| x.name == disk[:name] }.empty? + if env[:libvirt_compute].volumes.select { + |x| x.name == disk[:name] and x.pool_name == @storage_pool_name}.empty? # make the disk. equivalent to: # qemu-img create -f qcow2 5g begin From 9b5801be50b528605c987a81f5959901badb65e8 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilets Date: Tue, 9 Jun 2015 22:29:11 +0200 Subject: [PATCH 64/86] simplify --- lib/vagrant-libvirt/action/create_domain.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index e267c1e..8a87a38 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -17,7 +17,7 @@ module VagrantPlugins def _disks_print(disks) disks.collect do |x| - x[:device] + '(' + x[:type] + ',' + x[:size] + ')' + "#{x[:device]}(#{x[:type]},#{x[:size]})" end.join(', ') end @@ -69,9 +69,11 @@ module VagrantPlugins @os_type = 'hvm' # Get path to domain image from the storage pool selected. + actual_volumes = env[:libvirt_compute].volumes.all.select do |x| + x.pool_name == @storage_pool_name + end domain_volume = ProviderLibvirt::Util::Collection.find_matching( - env[:libvirt_compute].volumes.all.select { |x| x.pool_name == @storage_pool_name }, - "#{@name}.img") + actual_volumes,"#{@name}.img") raise Errors::DomainVolumeExists if domain_volume.nil? @domain_volume_path = domain_volume.path From 07c6fff1ac5c3c590f03a0c7ac31c5dde46d814a Mon Sep 17 00:00:00 2001 From: Alex Blackie Date: Thu, 18 Jun 2015 10:34:20 -0700 Subject: [PATCH 65/86] Do not remove `.ssh` on package `virt-sysprep` will, by default, remove all `.ssh` directories from all users' home directories. Since we need to have the default Vagrant insecure keypair in the `authorized_keys`, this causes problems later when trying to use the packaged box, as Vagrant is unable to log in. `virt-sysprep` has the ability to disable options via the `--operations` argument; the `ssh-userdir` option should be disabled. --- lib/vagrant-libvirt/action/package_domain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/action/package_domain.rb b/lib/vagrant-libvirt/action/package_domain.rb index c9ce42a..8c6c8b0 100644 --- a/lib/vagrant-libvirt/action/package_domain.rb +++ b/lib/vagrant-libvirt/action/package_domain.rb @@ -37,7 +37,7 @@ module VagrantPlugins `qemu-img rebase -p -b "" #{@tmp_img}` # remove hw association with interface # working for centos with lvs default disks - `virt-sysprep --no-logfile -a #{@tmp_img} ` + `virt-sysprep --no-logfile --operations defaults,-ssh-userdir -a #{@tmp_img} ` Dir.chdir(@tmp_dir) img_size = `qemu-img info #{@tmp_img} | grep 'virtual size' | awk '{print $3;}' | tr -d 'G'`.chomp File.write(@tmp_dir + '/metadata.json', metadata_content(img_size)) From d4c72212ebdc9f904b8ad5fdd7e94d437207db8a Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Fri, 26 Jun 2015 14:55:41 +0100 Subject: [PATCH 66/86] Support volume size resize configuration Allow control of the volume size to be increased from the box default virtual_size value so that it is possible to use a box configured with a minimal initial disk size and create virtual guests with larger disk sizes. Warn the user and ignore sizes that are less than the box size, and inform them that a manual filesystem resize will be needed to take advantage of the additional available disk space. fixes: #37 --- README.md | 1 + lib/vagrant-libvirt/action/create_domain.rb | 2 +- .../action/create_domain_volume.rb | 4 ++-- lib/vagrant-libvirt/action/handle_box_image.rb | 17 +++++++++++++++++ lib/vagrant-libvirt/config.rb | 3 +++ locales/en.yml | 8 ++++++++ 6 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6e8bd19..7ea26e3 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,7 @@ end * `video_vram` - Used by some graphics card types to vary the amount of RAM dedicated to video. Defaults to 9216. * `machine` - Sets machine type. Equivalent to qemu `-machine`. Use `qemu-system-x86_64 -machine help` to get a list of supported machines. * `machine_arch` - Sets machine architecture. This helps libvirt to determine the correct emulator type. Possible values depend on your version of qemu. For possible values, see which emulator executable `qemu-system-*` your system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`, `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`, `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`, `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`, `xtensa`, `xtensaeb`. +* `machine_virtual_size` - Sets the disk size for the machine overriding the default specified in the box. Allows boxes to defined with a minimal size disk by default and to be grown to a larger size at creation time. Will ignore sizes smaller than the size specified by the box metadata. Note that currently there is no support for automatically resizing the filesystem to take advantage of the larger disk. * `boot` - Change the boot order and enables the boot menu. Possible options are "hd" or "network". Defaults to "hd" with boot menu disabled. diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 8a87a38..92f2041 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -120,7 +120,7 @@ module VagrantPlugins env[:ui].info(" -- Memory: #{@memory_size / 1024}M") env[:ui].info(" -- Base box: #{env[:machine].box.name}") env[:ui].info(" -- Storage pool: #{@storage_pool_name}") - env[:ui].info(" -- Image: #{@domain_volume_path}") + env[:ui].info(" -- Image: #{@domain_volume_path} (#{env[:box_virtual_size]}G)") env[:ui].info(" -- Volume Cache: #{@domain_volume_cache}") env[:ui].info(" -- Kernel: #{@kernel}") env[:ui].info(" -- Initrd: #{@initrd}") diff --git a/lib/vagrant-libvirt/action/create_domain_volume.rb b/lib/vagrant-libvirt/action/create_domain_volume.rb index 2d536b6..04ff9c8 100644 --- a/lib/vagrant-libvirt/action/create_domain_volume.rb +++ b/lib/vagrant-libvirt/action/create_domain_volume.rb @@ -34,8 +34,8 @@ module VagrantPlugins env[:libvirt_compute].volumes.all, env[:box_volume_name]) @backing_file = box_volume.path - # Virtual size of image. Same as box image size. - @capacity = env[:machine].box.metadata['virtual_size'] #G + # Virtual size of image. Take value worked out by HandleBoxImage + @capacity = env[:box_virtual_size] #G # Create new volume from xml template. Fog currently doesn't support # volume snapshots directly. diff --git a/lib/vagrant-libvirt/action/handle_box_image.rb b/lib/vagrant-libvirt/action/handle_box_image.rb index b08ed17..2cf87ac 100644 --- a/lib/vagrant-libvirt/action/handle_box_image.rb +++ b/lib/vagrant-libvirt/action/handle_box_image.rb @@ -37,6 +37,23 @@ module VagrantPlugins env[:box_volume_name] = env[:machine].box.name.to_s.dup.gsub("/", "-VAGRANTSLASH-") env[:box_volume_name] << "_vagrant_box_image_#{env[:machine].box.version.to_s rescue ''}.img" + # Override box_virtual_size + if config.machine_virtual_size + if config.machine_virtual_size < box_virtual_size + # Warn that a virtual size less than the box metadata size + # is not supported and will be ignored + env[:ui].warn I18n.t( + 'vagrant_libvirt.warnings.ignoring_virtual_size_too_small', + requested: config.machine_virtual_size, minimum: box_virtual_size + ) + else + env[:ui].info I18n.t('vagrant_libvirt.manual_resize_required') + box_virtual_size = config.machine_virtual_size + end + end + # save for use by later actions + env[:box_virtual_size] = box_virtual_size + # while inside the synchronize block take care not to call the next # action in the chain, as must exit this block first to prevent # locking all subsequent actions as well. diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index bc446d6..665a849 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -58,6 +58,7 @@ module VagrantPlugins attr_accessor :boot_order attr_accessor :machine_type attr_accessor :machine_arch + attr_accessor :machine_virtual_size attr_accessor :disk_bus attr_accessor :nic_model_type attr_accessor :nested @@ -98,6 +99,7 @@ module VagrantPlugins @cpu_mode = UNSET_VALUE @machine_type = UNSET_VALUE @machine_arch = UNSET_VALUE + @machine_virtual_size = UNSET_VALUE @disk_bus = UNSET_VALUE @nic_model_type = UNSET_VALUE @nested = UNSET_VALUE @@ -287,6 +289,7 @@ module VagrantPlugins @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE @machine_type = nil if @machine_type == UNSET_VALUE @machine_arch = nil if @machine_arch == UNSET_VALUE + @machine_virtual_size = nil if @machine_virtual_size == UNSET_VALUE @disk_bus = 'virtio' if @disk_bus == UNSET_VALUE @nic_model_type = 'virtio' if @nic_model_type == UNSET_VALUE @nested = false if @nested == UNSET_VALUE diff --git a/locales/en.yml b/locales/en.yml index 7118fd9..0644cfc 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -12,6 +12,9 @@ en: Checking if volume is available. creating_domain: |- Creating domain with the following settings... + manual_resize_required: |- + Created volume larger than box defaults, will require manual resizing of + filesystems to utilize. uploading_volume: |- Uploading base box image as volume into libvirt storage... creating_domain_volume: |- @@ -47,6 +50,11 @@ en: remove_stale_volume: |- Remove stale volume... + warnings: + ignoring_virtual_size_too_small: |- + Ignoring requested virtual disk size of '%{requested}' as it is below + the minimum box image size of '%{box_virtual_size}'. + errors: package_not_supported: Not support package for libvirt. Create box manualy. fog_error: |- From cd0322ccafdd10d2635b9433c6aeaf0f2053ab9c Mon Sep 17 00:00:00 2001 From: Alexis Lee Date: Mon, 29 Jun 2015 17:14:13 +0100 Subject: [PATCH 67/86] Specify units for machine_virtual_size --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ea26e3..e04d35c 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ end * `video_vram` - Used by some graphics card types to vary the amount of RAM dedicated to video. Defaults to 9216. * `machine` - Sets machine type. Equivalent to qemu `-machine`. Use `qemu-system-x86_64 -machine help` to get a list of supported machines. * `machine_arch` - Sets machine architecture. This helps libvirt to determine the correct emulator type. Possible values depend on your version of qemu. For possible values, see which emulator executable `qemu-system-*` your system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`, `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`, `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`, `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`, `xtensa`, `xtensaeb`. -* `machine_virtual_size` - Sets the disk size for the machine overriding the default specified in the box. Allows boxes to defined with a minimal size disk by default and to be grown to a larger size at creation time. Will ignore sizes smaller than the size specified by the box metadata. Note that currently there is no support for automatically resizing the filesystem to take advantage of the larger disk. +* `machine_virtual_size` - Sets the disk size in GB for the machine overriding the default specified in the box. Allows boxes to defined with a minimal size disk by default and to be grown to a larger size at creation time. Will ignore sizes smaller than the size specified by the box metadata. Note that currently there is no support for automatically resizing the filesystem to take advantage of the larger disk. * `boot` - Change the boot order and enables the boot menu. Possible options are "hd" or "network". Defaults to "hd" with boot menu disabled. From ee7afab369dc7e80128ff35a2ff11f6eab23d368 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 30 Jun 2015 16:24:30 -0500 Subject: [PATCH 68/86] Read MAC address from libvirt and pass up to Vagrant Configuring networks based solely on slot numbers doesn't work very well, since there's no way to guarantee that the interface Vagrant finds is the same one that vagrant-libvirt created at that index. For example, Vagrant's Fedora configure_networks action does this: machine.communicate.sudo("ls /sys/class/net | grep -v lo") do |_, result| interface_names = result.split("\n") end interface_names = networks.map do |network| "#{interface_names[network[:interface]]}" end which means that if your image has 'docker' pre-installed, then interface_names[0] = "docker0" and hilarity ensues, with the first non-management network being assigned to the vagrant-libvirt management interface. Since interface names are very unreliable (they can be renamed by udev at will or when hardware changes) the only way to ensure that the interface vagrant-libvirt attaches to the domain maps to the correct one inside the VM is by MAC address. Pull the MAC address out of the libvirt config once the interface has been attached and pass that up to Vagrant so we have a chance of doing the right thing. --- .../action/create_network_interfaces.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb index 35886ad..cbe7562 100644 --- a/lib/vagrant-libvirt/action/create_network_interfaces.rb +++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb @@ -96,6 +96,21 @@ module VagrantPlugins raise Errors::AttachDeviceError, :error_message => e.message end + + # Re-read the network configuration and grab the MAC address + if !@mac + xml = Nokogiri::XML(domain.xml_desc) + if iface_configuration[:iface_type] == :public_network + if @type == 'direct' + @mac = xml.xpath("/domain/devices/interface[source[@dev='#{@device}']]/mac/@address") + else + @mac = xml.xpath("/domain/devices/interface[source[@bridge='#{@device}']]/mac/@address") + end + else + @mac = xml.xpath("/domain/devices/interface[source[@network='#{@network_name}']]/mac/@address") + end + iface_configuration[:mac] = @mac.to_s + end end # Continue the middleware chain. @@ -116,7 +131,7 @@ module VagrantPlugins network = { :interface => slot_number, :use_dhcp_assigned_default_route => options[:use_dhcp_assigned_default_route], - #:mac => ..., + :mac_address => options[:mac], } if options[:ip] From 789fa369c829a2d3b6ceabe261ecc77f333f9fd5 Mon Sep 17 00:00:00 2001 From: stanley karunditu Date: Sat, 11 Jul 2015 10:49:00 -0400 Subject: [PATCH 69/86] add libvirt interface tcp tunnel support. Useful when configuring Virtualized Switch topologies using Switch VMs like Cumulus Linux. vagrant network interface auto_config is disabled in the code. This may be re-enabled in a future update, once it is better understood how to auto configure these types of links. All guestOS ports, for now, that are connected to a tcp tunnel are in a link down state. TCP tunnels allow guest OSes to exchange STP and LLDP information as if they are directly connected to each other. This is not possible with the default virtual switch network mode. Reference: https://libvirt.org/formatdomain.html#elementsNICSTCP --- README.md | 37 ++++++++++++++++++- .../action/create_network_interfaces.rb | 18 ++++++++- lib/vagrant-libvirt/action/create_networks.rb | 3 +- lib/vagrant-libvirt/errors.rb | 4 ++ .../templates/tcp_tunnel_interface.xml.erb | 7 ++++ locales/en.yml | 2 + 6 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 lib/vagrant-libvirt/templates/tcp_tunnel_interface.xml.erb diff --git a/README.md b/README.md index e04d35c..d3f65b6 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,11 @@ Vagrant.configure("2") do |config| ## Networks Networking features in the form of `config.vm.network` support private networks -concept. +concept. It supports both the virtual network switch routing types and the point to +point Guest OS to Guest OS setting using TCP tunnel interfaces. + +http://wiki.libvirt.org/page/VirtualNetworking +https://libvirt.org/formatdomain.html#elementsNICSTCP Public Network interfaces are currently implemented using the macvtap driver. The macvtap driver is only available with the Linux Kernel version >= 2.6.24. See the following libvirt @@ -221,14 +225,33 @@ documentation for the details of the macvtap usage. http://www.libvirt.org/formatdomain.html#elementsNICSDirect + An examples of network interface definitions: ```ruby - # Private network + # Private network using virtual network switching config.vm.define :test_vm1 do |test_vm1| test_vm1.vm.network :private_network, :ip => "10.20.30.40" end + # Private network. Point to Point between 2 Guest OS using a TCP tunnel + # Guest 1 + config.vm.define :test_vm1 do |test_vm1| + test_vm1.vm.network :private_network, + :libvirt__tcp_tunnel_type => 'server', + # default is 127.0.0.1 if omitted + # :libvirt__tcp_tunnel_ip => '127.0.0.1', + :libvirt__tcp_tunnel_port => '11111' + + # Guest 2 + config.vm.define :test_vm1 do |test_vm1| + test_vm1.vm.network :private_network, + :libvirt__tcp_tunnel_type => 'client', + # default is 127.0.0.1 if omitted + # :libvirt__tcp_tunnel_ip => '127.0.0.1', + :libvirt__tcp_tunnel_port => '11111' + + # Public Network config.vm.define :test_vm1 do |test_vm1| test_vm1.vm.network :public_network, @@ -290,9 +313,19 @@ starts with 'libvirt__' string. Here is a list of those options: * `:libvirt__forward_device` - Name of interface/device, where network should be forwarded (NATed or routed). Used only when creating new network. By default, all physical interfaces are used. +* `:libvirt_tcp_tunnel_type` - Set it to "server" or "client" to enable TCP + tunnel interface configuration. This configuration type uses TCP tunnels to + generate point to point connections between Guests. Useful for Switch VMs like + Cumulus Linux. No virtual switch setting like "libvirt__network_name" applies with TCP + tunnel interfaces and will be ignored if configured. +* `:libvirt_tcp_tunnel_ip` - Sets the source IP of the TCP Tunnel interface. By + default this is `127.0.0.1` +* `:libvirt_tcp_tunnel_port` - Sets the TCP Tunnel interface port that either + the client will connect to, or the server will listen on. * `:mac` - MAC address for the interface. * `:model_type` - parameter specifies the model of the network adapter when you create a domain value by default virtio KVM believe possible values, see the documentation for libvirt + When the option `:libvirt__dhcp_enabled` is to to 'false' it shouldn't matter whether the virtual network contains a DHCP server or not and vagrant-libvirt should not fail on it. The only situation where vagrant-libvirt should fail diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb index cbe7562..bd9df2a 100644 --- a/lib/vagrant-libvirt/action/create_network_interfaces.rb +++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb @@ -36,7 +36,6 @@ module VagrantPlugins adapters = [] # Vagrant gives you adapter 0 by default - # Assign interfaces to slots. configured_networks(env, @logger).each do |options| @@ -70,7 +69,6 @@ module VagrantPlugins @mac = iface_configuration.fetch(:mac, false) @model_type = iface_configuration.fetch(:model_type, @nic_model_type) template_name = 'interface' - # Configuration for public interfaces which use the macvtap driver if iface_configuration[:iface_type] == :public_network @device = iface_configuration.fetch(:dev, 'eth0') @@ -80,8 +78,18 @@ module VagrantPlugins template_name = 'public_interface' @logger.info("Setting up public interface using device #{@device} in mode #{@mode}") @ovs = iface_configuration.fetch(:ovs, false) + # configuration for tcp tunnel interfaces (p2p conn btwn guest OSes) + elsif iface_configuration.fetch(:tcp_tunnel_type, nil) + @tcp_tunnel_port = iface_configuration.fetch(:tcp_tunnel_port, nil) + raise Errors::TcpTunnelPortNotDefined if @tcp_tunnel_port.nil? + @tcp_tunnel_ip = iface_configuration.fetch(:tcp_tunnel_address, '127.0.0.1') + @type = iface_configuration.fetch(:tcp_tunnel_type) + @model_type = iface_configuration.fetch(:model_type, @nic_model_type) + template_name = 'tcp_tunnel_interface' + @logger.info("Setting up #{@type} tunnel interface using #{@tcp_tunnel_ip} port #{@tcp_tunnel_port}") end + message = "Creating network interface eth#{@iface_number}" message << " connected to network #{@network_name}." if @mac @@ -144,6 +152,9 @@ module VagrantPlugins network[:type] = :dhcp end + # do not run configure_networks for tcp tunnel interfaces + next if options.fetch(:tcp_tunnel_type, nil) + networks_to_configure << network end @@ -163,6 +174,9 @@ module VagrantPlugins # Return network name according to interface options. def interface_network(libvirt_client, options) + # no need to get interface network for tcp tunnel config + return 'tcp_tunnel' if options.fetch(:tcp_tunnel_type, nil) + if options[:network_name] @logger.debug "Found network by name" return options[:network_name] diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index a0d4e54..883c83f 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -35,7 +35,8 @@ module VagrantPlugins # available, create it if possible. Otherwise raise an error. configured_networks(env, @logger).each do |options| # Only need to create private networks - next if options[:iface_type] != :private_network + next if options[:iface_type] != :private_network or + options.fetch(:tcp_tunnel_type, nil) @logger.debug "Searching for network with options #{options}" # should fix other methods so this doesn't have to be instance var diff --git a/lib/vagrant-libvirt/errors.rb b/lib/vagrant-libvirt/errors.rb index 870c647..863a4f0 100644 --- a/lib/vagrant-libvirt/errors.rb +++ b/lib/vagrant-libvirt/errors.rb @@ -106,6 +106,10 @@ module VagrantPlugins error_key(:activate_network_error) end + class TcpTunnelPortNotDefined < VagrantLibvirtError + error_key(:tcp_tunnel_port_not_defined) + end + # Other exceptions class InterfaceSlotNotAvailable < VagrantLibvirtError error_key(:interface_slot_not_available) diff --git a/lib/vagrant-libvirt/templates/tcp_tunnel_interface.xml.erb b/lib/vagrant-libvirt/templates/tcp_tunnel_interface.xml.erb new file mode 100644 index 0000000..379b740 --- /dev/null +++ b/lib/vagrant-libvirt/templates/tcp_tunnel_interface.xml.erb @@ -0,0 +1,7 @@ + + <% if @mac %> + + <% end %> + + + diff --git a/locales/en.yml b/locales/en.yml index 0644cfc..1ab8e78 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -135,6 +135,8 @@ en: Error while removing network %{network_name}. %{error_message}. delete_snapshot_error: |- Error while deleting snapshot: %{error_message}. + tcp_tunnel_port_not_defined: |- + TCP tunnel port not defined. states: short_paused: |- From 555470efe32015f8f1e2366267e927bbf660a87f Mon Sep 17 00:00:00 2001 From: stanley karunditu Date: Sat, 11 Jul 2015 10:53:23 -0400 Subject: [PATCH 70/86] update README. should say 'test_vm2' instead of 'test_vm1' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3f65b6..09b4801 100644 --- a/README.md +++ b/README.md @@ -244,7 +244,7 @@ An examples of network interface definitions: :libvirt__tcp_tunnel_port => '11111' # Guest 2 - config.vm.define :test_vm1 do |test_vm1| + config.vm.define :test_vm2 do |test_vm2| test_vm1.vm.network :private_network, :libvirt__tcp_tunnel_type => 'client', # default is 127.0.0.1 if omitted From a5cd2024ed8288e7bb43e57a0643e42ee0e2a3bc Mon Sep 17 00:00:00 2001 From: stanley karunditu Date: Sat, 11 Jul 2015 10:55:21 -0400 Subject: [PATCH 71/86] update README. fix mention of test_vm1. should be test_vm2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09b4801..7a15724 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ An examples of network interface definitions: # Guest 2 config.vm.define :test_vm2 do |test_vm2| - test_vm1.vm.network :private_network, + test_vm2.vm.network :private_network, :libvirt__tcp_tunnel_type => 'client', # default is 127.0.0.1 if omitted # :libvirt__tcp_tunnel_ip => '127.0.0.1', From 389c2d444de27f22da7987c9109493b26d7402d7 Mon Sep 17 00:00:00 2001 From: stanley karunditu Date: Mon, 13 Jul 2015 06:37:51 -0400 Subject: [PATCH 72/86] set nic adapter limit as a provider variable. default remains 8 like it was hard coded before. only use case for changing this is if using virtualized switch VMs that have support for many interfaces. --- README.md | 1 + .../action/create_network_interfaces.rb | 3 ++- lib/vagrant-libvirt/config.rb | 12 ++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7a15724..5ee2e53 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,7 @@ end * `machine_arch` - Sets machine architecture. This helps libvirt to determine the correct emulator type. Possible values depend on your version of qemu. For possible values, see which emulator executable `qemu-system-*` your system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`, `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`, `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`, `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`, `xtensa`, `xtensaeb`. * `machine_virtual_size` - Sets the disk size in GB for the machine overriding the default specified in the box. Allows boxes to defined with a minimal size disk by default and to be grown to a larger size at creation time. Will ignore sizes smaller than the size specified by the box metadata. Note that currently there is no support for automatically resizing the filesystem to take advantage of the larger disk. * `boot` - Change the boot order and enables the boot menu. Possible options are "hd" or "network". Defaults to "hd" with boot menu disabled. +* `nic_adapter_count` - Defaults to '8'. Only use case for increasing this count is for VMs that virtualize switches such as Cumulus Linux. Max value for Cumulus Linux VMs is 33. Specific domain settings can be set for each domain separately in multi-VM diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb index bd9df2a..cea9d87 100644 --- a/lib/vagrant-libvirt/action/create_network_interfaces.rb +++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb @@ -19,6 +19,7 @@ module VagrantPlugins @management_network_name = env[:machine].provider_config.management_network_name config = env[:machine].provider_config @nic_model_type = config.nic_model_type + @nic_adapter_count = config.nic_adapter_count @app = app end @@ -165,7 +166,7 @@ module VagrantPlugins private - def find_empty(array, start=0, stop=8) + def find_empty(array, start=0, stop=@nic_adapter_count) (start..stop).each do |i| return i if !array[i] end diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 665a849..8618711 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -75,6 +75,11 @@ module VagrantPlugins attr_accessor :video_vram attr_accessor :keymap + # Sets the max number of NICs that can be created + # Default set to 8. Don't change the default unless you know + # what are doing + attr_accessor :nic_adapter_count + # Storage attr_accessor :disks attr_accessor :cdroms @@ -116,13 +121,15 @@ module VagrantPlugins @video_vram = UNSET_VALUE @keymap = UNSET_VALUE + @nic_adapter_count = UNSET_VALUE + # Boot order @boot_order = [] # Storage @disks = [] @cdroms = [] end - + def boot(device) @boot_order << device # append end @@ -309,7 +316,8 @@ module VagrantPlugins @video_type = 'cirrus' if @video_type == UNSET_VALUE @video_vram = 9216 if @video_vram == UNSET_VALUE @keymap = 'en-us' if @keymap == UNSET_VALUE - + @nic_adapter_count = 8 if @nic_adapter_count == UNSET_VALUE + # Boot order @boot_order = [] if @boot_order == UNSET_VALUE From 8d06588e8faa88b95c8f8981a505b5f985dc244f Mon Sep 17 00:00:00 2001 From: Graham Hayes Date: Mon, 13 Jul 2015 14:29:14 +0100 Subject: [PATCH 73/86] Limit p9 tag to 31 bytes Libvirt p9 file system passthrough requires the tag be less than 31 bytes. Using the mount point as the tag can easily exceed this. Fixes #323 --- lib/vagrant-libvirt/cap/mount_p9.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/cap/mount_p9.rb b/lib/vagrant-libvirt/cap/mount_p9.rb index 274edb1..586c6ea 100644 --- a/lib/vagrant-libvirt/cap/mount_p9.rb +++ b/lib/vagrant-libvirt/cap/mount_p9.rb @@ -1,3 +1,4 @@ +require "digest/md5" require "vagrant/util/retryable" module VagrantPlugins @@ -16,7 +17,7 @@ module VagrantPlugins machine.communicate.sudo("mkdir -p #{expanded_guest_path}") # Mount - mount_tag = name.dup + mount_tag = Digest::MD5.new.update(name).to_s[0,31] mount_opts="-o trans=virtio" mount_opts += ",access=#{opts[:owner]}" if opts[:owner] From 81688f0fd9c3ddc57279e6674e331ce0a222e6d6 Mon Sep 17 00:00:00 2001 From: Joe Julian Date: Mon, 13 Jul 2015 15:52:26 -0700 Subject: [PATCH 74/86] Allow veryisolated networks With veryisolated networks, there is no ip address assigned thus matching the network name and ip address fails. This allows the null ip address to match a named network when that forward_mode is set. --- lib/vagrant-libvirt/action/create_networks.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index 883c83f..6c86afe 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -116,13 +116,16 @@ module VagrantPlugins # @available_networks should be filled before calling this function. def handle_ip_option(env) return if !@options[:ip] + net_address = nil + if @options[:forward_mode] != 'veryisolated' + net_address = network_address(@options[:ip], @options[:netmask]) + # Set IP address of network (actually bridge). It will be used as + # gateway address for machines connected to this network. + net = IPAddr.new(net_address) + end - net_address = network_address(@options[:ip], @options[:netmask]) @interface_network[:network_address] = net_address - # Set IP address of network (actually bridge). It will be used as - # gateway address for machines connected to this network. - net = IPAddr.new(net_address) # Default to first address (after network name) @interface_network[:ip_address] = @options[:host_ip].nil? ? net.to_range.begin.succ : IPAddr.new(@options[:host_ip]) From eeb4712c7231cebdc19c69583a4730e11eddeed4 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Tue, 14 Jul 2015 17:17:50 +0100 Subject: [PATCH 75/86] Allow read actions to be called by other machines Disable action locks on read actions so that Vagrant may return ssh configuration information while other actions are being run on the machine. Vagrant locks each machine when an action is being performed on it, to ensure that it cannot be modified by multiple actions at the same time. However certain read operations such as retrieving the ssh infomation may be called either by other machines when executing in parallel or if the user executes 'vagrant ssh ', during a provision step. When this occurs Vagrant will throw an error telling the user that multiple actions may not be executed in parallel and they must wait until the existing action is finished or see if vagrant/ruby must be terminated. Example issue is that the ansible provisioner builds an inventory file where for each machine executing it will query the ssh_info of all other active machines. When run serially, this will work as expected, however in parallel it will only succeed if all the actions associated with ssh_info are complete before any machine begins executing ansible itself. Fixes #420 --- lib/vagrant-libvirt/provider.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-libvirt/provider.rb b/lib/vagrant-libvirt/provider.rb index 9420dc2..e1053fa 100644 --- a/lib/vagrant-libvirt/provider.rb +++ b/lib/vagrant-libvirt/provider.rb @@ -45,7 +45,7 @@ module VagrantPlugins # :username => "mitchellh", # :private_key_path => "/path/to/my/key" #} - env = @machine.action('read_ssh_info') + env = @machine.action('read_ssh_info', :lock => false) env[:machine_ssh_info] end @@ -67,7 +67,7 @@ module VagrantPlugins # Run a custom action we define called "read_state" which does # what it says. It puts the state in the `:machine_state_id` # key in the environment. - env = @machine.action('read_state') + env = @machine.action('read_state', :lock => false) state_id = env[:machine_state_id] From 6d8c45542e35a94ae316a715c6d733213c26fed4 Mon Sep 17 00:00:00 2001 From: Joe Julian Date: Fri, 17 Jul 2015 15:31:17 -0700 Subject: [PATCH 76/86] Select the network by name --- lib/vagrant-libvirt/action/create_networks.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index 6c86afe..da3b3c9 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -140,6 +140,13 @@ module VagrantPlugins break end end + # if network is veryisolated, search by name instead + if @options[:libvirt__forward_mode] == "veryisolated" + if lookup_network_by_name(@options[:network_name]) + @interface_network = lookup_network_by_name(@options[:network_name]) + @logger.debug @interface_network + end + end if @interface_network[:created] verify_dhcp From 546c98c0a2a97c5cbcd4d7ea58e23343b8472029 Mon Sep 17 00:00:00 2001 From: Joe Julian Date: Fri, 17 Jul 2015 17:07:18 -0700 Subject: [PATCH 77/86] Allow veryisolated networks without IP * Moved network lookup by IP to `lookup_network_by_ip` * Lookup by name only if lookup by ip fails *and* forward_mode is `veryisolated`. This will preserve existing functionality. * Added network creation ability to `handle_network_name_option` ** Network **must** be veryisolated to be created by name ** Network **must not** have an ip address to be used in the `handle_network_name_option` path. Minor changes: * corrected inverted autostart logic * screen formatting Fixes #402 --- lib/vagrant-libvirt/action/create_networks.rb | 90 +++++++++++++------ 1 file changed, 62 insertions(+), 28 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index da3b3c9..2dd333a 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -67,10 +67,10 @@ module VagrantPlugins # because cannot have name without ip # https://github.com/mitchellh/vagrant/commit/cf2f6da4dbcb4f57c9cdb3b94dcd0bba62c5f5fd elsif @options[:network_name] - handle_network_name_option + handle_network_name_option(env) end - autostart_network if !@interface_network[:autostart] + autostart_network if @interface_network[:autostart] activate_network if !@interface_network[:active] end end @@ -80,11 +80,25 @@ module VagrantPlugins private + def lookup_network_by_ip(ip) + @logger.debug "looking up network with ip == #{ip}" + @available_networks.each do |network| + if network[:network_address] == ip + @logger.debug "found existing network by ip: #{network}" + return network + end + end + nil + end + # Return hash of network for specified name, or nil if not found. def lookup_network_by_name(network_name) @logger.debug "looking up network named #{network_name}" @available_networks.each do |network| - return network if network[:name] == network_name + if network[:name] == network_name + @logger.debug "found existing network by name: #{network}" + return network + end end nil end @@ -127,31 +141,27 @@ module VagrantPlugins @interface_network[:network_address] = net_address # Default to first address (after network name) - @interface_network[:ip_address] = @options[:host_ip].nil? ? net.to_range.begin.succ : IPAddr.new(@options[:host_ip]) - + @interface_network[:ip_address] = @options[:host_ip].nil? ? \ + net.to_range.begin.succ : \ + IPAddr.new(@options[:host_ip]) + # Is there an available network matching to configured ip # address? - @available_networks.each do |available_network| - if available_network[:network_address] == \ - @interface_network[:network_address] - @interface_network = available_network - @logger.debug "found existing network by ip, values are" - @logger.debug @interface_network - break - end + if net_address + network = lookup_network_by_ip(net_address) + @interface_network = network if network end + # if network is veryisolated, search by name instead - if @options[:libvirt__forward_mode] == "veryisolated" - if lookup_network_by_name(@options[:network_name]) - @interface_network = lookup_network_by_name(@options[:network_name]) - @logger.debug @interface_network - end + if !@interface_network and @options[:libvirt__forward_mode] == "veryisolated" + network = lookup_network_by_name(@options[:network_name]) + @interface_network = network if network end if @interface_network[:created] verify_dhcp end - + if @options[:network_name] @logger.debug "Checking that network name does not clash with ip" if @interface_network[:created] @@ -170,13 +180,13 @@ module VagrantPlugins ip_address: @options[:ip], network_name: @options[:network_name] end - + # Network with 'name' doesn't exist. Set it as name for new # network. @interface_network[:name] = @options[:network_name] end end - + # Do we need to create new network? if !@interface_network[:created] @@ -219,15 +229,39 @@ module VagrantPlugins # Handle network_name option, if ip was not specified. Variables # @options and @available_networks should be filled before calling this # function. - def handle_network_name_option - return if @options[:ip] || !@options[:network_name] + def handle_network_name_option(env) + return if @options[:ip] || \ + !@options[:network_name] || \ + !@options[:libvirt__forward_mode] == "veryisolated" - @interface_network = lookup_network_by_name(@options[:network_name]) - if !@interface_network + network = lookup_network_by_name(@options[:network_name]) + @interface_network = network if network + + # if this interface has a network address, something's wrong. + if @interface_network[:network_address] raise Errors::NetworkNotAvailableError, network_name: @options[:network_name] - else - verify_dhcp + end + + # Do we need to create new network? + if !@interface_network[:created] + @interface_network[:name] = @options[:network_name] + + # Generate a unique name for network bridge. + count = 0 + while @interface_network[:bridge_name].nil? + @logger.debug "generating name for bridge" + bridge_name = 'virbr' + bridge_name << count.to_s + count += 1 + + next if lookup_bridge_by_name(bridge_name) + + @interface_network[:bridge_name] = bridge_name + end + + # Create a private network. + create_private_network(env) end end @@ -246,7 +280,7 @@ module VagrantPlugins # Find out DHCP addresses pool range. network_address = "#{@interface_network[:network_address]}/" network_address << "#{@interface_network[:netmask]}" - net = IPAddr.new(network_address) + net = @interface_network[:network_address] ? IPAddr.new(network_address) : nil # First is address of network, second is gateway (by default). # So start the range two addresses after network address by default. From 9b7c9def3c54b75653346532ded9c5aece96ad33 Mon Sep 17 00:00:00 2001 From: Joe Julian Date: Fri, 17 Jul 2015 17:17:37 -0700 Subject: [PATCH 78/86] Removed comment Vagrant only requires an ip **if** `type` is set **and** is not `dhcp`. The only other type, currently, is `nfs`. Obviously nfs requires an IP so under that circumstance or if `type` is set to anything but dhcp, vagrant will error if an ip is not assigned. If `type` is `nil`, it is deleted from the hash. --- lib/vagrant-libvirt/action/create_networks.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index 2dd333a..45bf77e 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -63,9 +63,6 @@ module VagrantPlugins if @options[:ip] handle_ip_option(env) - # in vagrant 1.2.3 and later it is not possible to take this branch - # because cannot have name without ip - # https://github.com/mitchellh/vagrant/commit/cf2f6da4dbcb4f57c9cdb3b94dcd0bba62c5f5fd elsif @options[:network_name] handle_network_name_option(env) end From fc24db479f1c4797faed4f86a6672bfa7237f9ef Mon Sep 17 00:00:00 2001 From: Joe Julian Date: Mon, 20 Jul 2015 13:01:34 -0700 Subject: [PATCH 79/86] Make lookup_network_by_name the default for veryisolated networks --- lib/vagrant-libvirt/action/create_networks.rb | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index 45bf77e..b8cb08d 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -133,27 +133,27 @@ module VagrantPlugins # Set IP address of network (actually bridge). It will be used as # gateway address for machines connected to this network. net = IPAddr.new(net_address) + + # Default to first address (after network name) + @interface_network[:ip_address] = @options[:host_ip].nil? ? \ + net.to_range.begin.succ : \ + IPAddr.new(@options[:host_ip]) end @interface_network[:network_address] = net_address - # Default to first address (after network name) - @interface_network[:ip_address] = @options[:host_ip].nil? ? \ - net.to_range.begin.succ : \ - IPAddr.new(@options[:host_ip]) - - # Is there an available network matching to configured ip - # address? - if net_address - network = lookup_network_by_ip(net_address) - @interface_network = network if network - end - - # if network is veryisolated, search by name instead - if !@interface_network and @options[:libvirt__forward_mode] == "veryisolated" + # if network is veryisolated, search by name + if @options[:libvirt__forward_mode] == "veryisolated" + network = lookup_network_by_name(@options[:network_name]) + elsif net_address + # otherwise, search by ip (if set) + network = lookup_network_by_ip(net_address) + else + # leaving this here to mimic prior behavior. If we get + # here, something's probably broken. network = lookup_network_by_name(@options[:network_name]) - @interface_network = network if network end + @interface_network = network if network if @interface_network[:created] verify_dhcp From 4dd13bf2194db1f2ef7628975d6acff330711da4 Mon Sep 17 00:00:00 2001 From: Graham Hayes Date: Mon, 20 Jul 2015 14:11:50 +0100 Subject: [PATCH 80/86] Really Limit p9 tag to 31 bytes Libvirt p9 file system passthrough requires the tag be less than 31 bytes. Using the mount point as the tag can easily exceed this. In KVM passthough the "target" attribuite in the XML is acutally the mount tag. Fixed the mounting script to use the same MD5 to mount the right filesystem Fixes #323 --- lib/vagrant-libvirt/cap/mount_p9.rb | 2 +- lib/vagrant-libvirt/cap/synced_folder.rb | 6 ++++++ lib/vagrant-libvirt/templates/filesystem.xml.erb | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-libvirt/cap/mount_p9.rb b/lib/vagrant-libvirt/cap/mount_p9.rb index 586c6ea..b788809 100644 --- a/lib/vagrant-libvirt/cap/mount_p9.rb +++ b/lib/vagrant-libvirt/cap/mount_p9.rb @@ -17,7 +17,7 @@ module VagrantPlugins machine.communicate.sudo("mkdir -p #{expanded_guest_path}") # Mount - mount_tag = Digest::MD5.new.update(name).to_s[0,31] + mount_tag = Digest::MD5.new.update(opts[:hostpath]).to_s[0,31] mount_opts="-o trans=virtio" mount_opts += ",access=#{opts[:owner]}" if opts[:owner] diff --git a/lib/vagrant-libvirt/cap/synced_folder.rb b/lib/vagrant-libvirt/cap/synced_folder.rb index 95e4ef7..9d3ca8d 100644 --- a/lib/vagrant-libvirt/cap/synced_folder.rb +++ b/lib/vagrant-libvirt/cap/synced_folder.rb @@ -1,6 +1,7 @@ require 'log4r' require 'ostruct' require 'nokogiri' +require "digest/md5" require 'vagrant/util/subprocess' require 'vagrant/errors' @@ -38,7 +39,12 @@ module VagrantPlugins folder_opts.merge!({ target: id, accessmode: 'passthrough', readonly: nil }) { |_k, ov, _nv| ov } + + mount_tag = Digest::MD5.new.update(folder_opts[:hostpath]).to_s[0,31] + folder_opts[:mount_tag] = mount_tag + machine.ui.info "================\nMachine id: #{machine.id}\nShould be mounting folders\n #{id}, opts: #{folder_opts}" + xml = to_xml('filesystem', folder_opts) # puts "<<<<< XML:\n #{xml}\n >>>>>" @conn.lookup_domain_by_uuid(machine.id).attach_device(xml, 0) diff --git a/lib/vagrant-libvirt/templates/filesystem.xml.erb b/lib/vagrant-libvirt/templates/filesystem.xml.erb index d0a35c9..a9824e4 100644 --- a/lib/vagrant-libvirt/templates/filesystem.xml.erb +++ b/lib/vagrant-libvirt/templates/filesystem.xml.erb @@ -1,7 +1,7 @@ - + <% unless readonly.nil? %> <% end %> From d90da43f8583098bdc738ce2ebb72899d0f0cae3 Mon Sep 17 00:00:00 2001 From: Andus Lim Date: Tue, 23 Jun 2015 09:58:21 +0800 Subject: [PATCH 81/86] Ensure IP is a string and not an array before connecting via UDP socket. --- lib/vagrant-libvirt/action/prepare_nfs_settings.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb index b74268a..9bc24a1 100644 --- a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +++ b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb @@ -41,8 +41,13 @@ module VagrantPlugins # @return [String] def read_host_ip(ip) UDPSocket.open do |s| - s.connect(ip, 1) - s.addr.last + @logger.info("!!!! ALL IPs #{ip} #{ip.kind_of?(Array)}" ) + if ip.kind_of?(Array) + s.connect(ip[0], 1) + else + s.connect(ip, 1) + end + s.addr.last end end From dc2f5cb4aa17da3a301b38171b9ada14ad6f7a41 Mon Sep 17 00:00:00 2001 From: Gerben Meijer Date: Fri, 24 Jul 2015 15:25:47 +0200 Subject: [PATCH 82/86] Use per device boot order when boot_order is set This allows for network boot with any of the NICs that are defined instead of only from the primary NIC. --- .../action/create_network_interfaces.rb | 1 + lib/vagrant-libvirt/templates/domain.xml.erb | 10 +++++----- lib/vagrant-libvirt/templates/interface.xml.erb | 5 +++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb index cea9d87..88ab821 100644 --- a/lib/vagrant-libvirt/action/create_network_interfaces.rb +++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb @@ -20,6 +20,7 @@ module VagrantPlugins config = env[:machine].provider_config @nic_model_type = config.nic_model_type @nic_adapter_count = config.nic_adapter_count + @boot_order = config.boot_order @app = app end diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index e1264fb..22a57a9 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -28,12 +28,7 @@ <% end %> <% end %> <% if @boot_order.count >= 1 %> - <% @boot_order.each do |b| %> - - <% end %> - <% else %> - <% end %> <%= @kernel %> <%= @initrd %> @@ -51,6 +46,11 @@ <%# we need to ensure a unique target dev -%> + <% if @boot_order[0] == 'hd' %> + + <% elsif @boot_order.count >= 1 %> + + <% end %> <%# additional disks -%> <% @disks.each do |d| -%> diff --git a/lib/vagrant-libvirt/templates/interface.xml.erb b/lib/vagrant-libvirt/templates/interface.xml.erb index 34ceccd..7086a7f 100644 --- a/lib/vagrant-libvirt/templates/interface.xml.erb +++ b/lib/vagrant-libvirt/templates/interface.xml.erb @@ -6,5 +6,10 @@ + <% if @boot_order[0] == 'network' %> + + <% elsif @boot_order.include?('network') %> + + <% end %> From f47cb7c98b1b3f3deef0af0caa8c1fc59101c838 Mon Sep 17 00:00:00 2001 From: Gerben Meijer Date: Wed, 29 Jul 2015 13:31:07 +0200 Subject: [PATCH 83/86] Describe changes to boot process due to boot order --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ee2e53..e4d5180 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ end * `machine` - Sets machine type. Equivalent to qemu `-machine`. Use `qemu-system-x86_64 -machine help` to get a list of supported machines. * `machine_arch` - Sets machine architecture. This helps libvirt to determine the correct emulator type. Possible values depend on your version of qemu. For possible values, see which emulator executable `qemu-system-*` your system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`, `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`, `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`, `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`, `xtensa`, `xtensaeb`. * `machine_virtual_size` - Sets the disk size in GB for the machine overriding the default specified in the box. Allows boxes to defined with a minimal size disk by default and to be grown to a larger size at creation time. Will ignore sizes smaller than the size specified by the box metadata. Note that currently there is no support for automatically resizing the filesystem to take advantage of the larger disk. -* `boot` - Change the boot order and enables the boot menu. Possible options are "hd" or "network". Defaults to "hd" with boot menu disabled. +* `boot` - Change the boot order and enables the boot menu. Possible options are "hd" or "network". Defaults to "hd" with boot menu disabled. When "network" is set first, *all* NICs will be tried before the first disk is tried. * `nic_adapter_count` - Defaults to '8'. Only use case for increasing this count is for VMs that virtualize switches such as Cumulus Linux. Max value for Cumulus Linux VMs is 33. From 1f45c5a788d5119ef2d157ea0da8e98e49b162ba Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Wed, 29 Jul 2015 17:23:16 +0100 Subject: [PATCH 84/86] Ensure correct order of logger creation Loggers must be defined in the correct heirarchial order to ensure that child loggers inherit the level defined on the parent logger. Otherwise need to traverse the entire tree to modify the level. --- lib/vagrant-libvirt.rb | 4 +++- lib/vagrant-libvirt/plugin.rb | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/vagrant-libvirt.rb b/lib/vagrant-libvirt.rb index 825e5fa..24322c0 100644 --- a/lib/vagrant-libvirt.rb +++ b/lib/vagrant-libvirt.rb @@ -1,5 +1,4 @@ require 'pathname' -require 'vagrant-libvirt/plugin' module VagrantPlugins module ProviderLibvirt @@ -27,3 +26,6 @@ module VagrantPlugins end end end + +# make sure base module class defined before loading plugin +require 'vagrant-libvirt/plugin' diff --git a/lib/vagrant-libvirt/plugin.rb b/lib/vagrant-libvirt/plugin.rb index 1dbb56c..0b7cae3 100644 --- a/lib/vagrant-libvirt/plugin.rb +++ b/lib/vagrant-libvirt/plugin.rb @@ -24,10 +24,6 @@ module VagrantPlugins end provider('libvirt', parallel: true) do - # Setup logging and i18n - setup_logging - setup_i18n - require_relative 'provider' Provider end @@ -90,6 +86,12 @@ module VagrantPlugins end end + # Setup logging and i18n before any autoloading loads other classes + # with logging configured as this prevents inheritance of the log level + # from the parent logger. + setup_logging + setup_i18n + end end end From 4c7a0d5db0805807699cfab2ec959dd9d8997335 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Wed, 29 Jul 2015 17:35:09 +0100 Subject: [PATCH 85/86] Enable travis CI testing of github PRs Add travis CI and support testing against a matrix of vagrant versions. --- .travis.yml | 20 ++++++++++++++++++++ Gemfile | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f967fdf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +--- +language: ruby +before_install: + - sudo apt-get update -qq + - sudo apt-get install -y libvirt-dev + - gem install bundler --version $BUNDLER_VERSION +install: bundle _${BUNDLER_VERSION}_ install +script: bundle _${BUNDLER_VERSION}_ exec rspec --color --format documentation +notifications: + email: false +rvm: + - 2.0.0 +env: + global: + - NOKOGIRI_USE_SYSTEM_LIBRARIES=true + matrix: + - VAGRANT_VERSION=v1.5.4 BUNDLER_VERSION=1.5.3 + - VAGRANT_VERSION=v1.6.5 BUNDLER_VERSION=1.6.9 + - VAGRANT_VERSION=v1.7.0 BUNDLER_VERSION=1.7.9 + - VAGRANT_VERSION= BUNDLER_VERSION=1.7.9 diff --git a/Gemfile b/Gemfile index c93c514..4e4fd9d 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,12 @@ group :development do # We depend on Vagrant for development, but we don't add it as a # gem dependency because we expect to be installed within the # Vagrant environment itself using `vagrant plugin`. - gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant.git' + if ENV['VAGRANT_VERSION'] + gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant.git', + tag: ENV['VAGRANT_VERSION'] + else + gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant.git' + end gem 'pry' end From edf730e9f51ed12acf87542a80179be8e17fcacf Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Fri, 31 Jul 2015 20:47:20 +0100 Subject: [PATCH 86/86] Enable provisionser cleanup hooks to be actioned Call the builtin ProvisionserCleanup action when destroying machines. Part of vagrant since version 1.3.0. --- lib/vagrant-libvirt/action.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index 48f1605..4fba536 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -172,6 +172,7 @@ module VagrantPlugins # b2.use PruneNFSExports b2.use DestroyDomain b2.use DestroyNetworks + b2.use ProvisionerCleanup end end end @@ -370,6 +371,7 @@ module VagrantPlugins autoload :HandleBox, 'vagrant/action/builtin/handle_box' autoload :SyncedFolders, 'vagrant/action/builtin/synced_folders' autoload :SyncedFolderCleanup, 'vagrant/action/builtin/synced_folder_cleanup' + autoload :ProvisionerCleanup, 'vagrant/action/builtin/provisioner_cleanup' end end end