From 45b588d7da9e3904992dabd6a39c721eb8d7b122 Mon Sep 17 00:00:00 2001 From: jasonwalsh Date: Tue, 17 Apr 2018 18:22:41 -0400 Subject: [PATCH 01/28] Use ps keyword `command` instead of `cmd` For Darwin operating systems, `cmd` is not a valid keyword, thus resulting in the following error when executing Vagrant `reload` and `destroy` commands: ps: cmd: keyword not found ps: no valid keywords; valid keywords: This commit ensures that SSH sessions for forwarded ports are terminated via their respective process ID for Darwin *and* Linux operating systems. Both Darwin and Linux operating systems support the `command` keyword, as reflected in the following documents, respectively: - https://apple.co/2H7jFwl - https://bit.ly/2HakfW0 --- lib/vagrant-libvirt/action/forward_ports.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-libvirt/action/forward_ports.rb b/lib/vagrant-libvirt/action/forward_ports.rb index 7afe1aa..51a4722 100644 --- a/lib/vagrant-libvirt/action/forward_ports.rb +++ b/lib/vagrant-libvirt/action/forward_ports.rb @@ -210,9 +210,9 @@ module VagrantPlugins end def ssh_pid?(pid) - @logger.debug 'Checking if #{pid} is an ssh process '\ - 'with `ps -o cmd= #{pid}`' - `ps -o cmd= #{pid}`.strip.chomp =~ /ssh/ + @logger.debug "Checking if #{pid} is an ssh process "\ + "with `ps -o command= #{pid}`" + `ps -o command= #{pid}`.strip.chomp =~ /ssh/ end def remove_ssh_pids From 8ba4865e0aa50e56d3d79ad8e6dd40ca0fe97097 Mon Sep 17 00:00:00 2001 From: Anton Dessiatov Date: Wed, 18 Apr 2018 15:06:16 +0700 Subject: [PATCH 02/28] Request 'configure_networks' capability only if there actually are networks to configure --- .../action/create_network_interfaces.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb index 74d9448..bc0feb4 100644 --- a/lib/vagrant-libvirt/action/create_network_interfaces.rb +++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb @@ -219,10 +219,12 @@ module VagrantPlugins networks_to_configure << network end - env[:ui].info I18n.t('vagrant.actions.vm.network.configuring') - env[:machine].guest.capability( - :configure_networks, networks_to_configure - ) + unless networks_to_configure.empty? + env[:ui].info I18n.t('vagrant.actions.vm.network.configuring') + env[:machine].guest.capability( + :configure_networks, networks_to_configure + ) + end end end From 9f203f75a2ecacef09a700bf9ed6f9d86616e988 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 18 Apr 2018 10:51:30 -0400 Subject: [PATCH 03/28] Don't add _ after user defined default_prefix Forcing an underscore between a defined default_prefix and the machine name forces a naming format that the user might not want. If they define their own default_prefix and want an underscore between that and the machine name, they can/should add the underscore to the default_prefix. --- lib/vagrant-libvirt/action/set_name_of_domain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/action/set_name_of_domain.rb b/lib/vagrant-libvirt/action/set_name_of_domain.rb index c421c9e..55896a6 100644 --- a/lib/vagrant-libvirt/action/set_name_of_domain.rb +++ b/lib/vagrant-libvirt/action/set_name_of_domain.rb @@ -51,7 +51,7 @@ module VagrantPlugins # don't have any prefix, not even "_" '' else - config.default_prefix.to_s.dup.concat('_') + config.default_prefix.to_s.dup end domain_name << env[:machine].name.to_s domain_name.gsub!(/[^-a-z0-9_\.]/i, '') From 2cfec56325c8f331b8e7e7c317514702732f0b8f Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 18 Apr 2018 10:59:19 -0400 Subject: [PATCH 04/28] Update unit test for building simple domain name Make the unit test match the new requirement that if a _ postfix is desired when default_prefix is defined, then it must be added to the default_prefix. --- spec/unit/action/set_name_of_domain_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/action/set_name_of_domain_spec.rb b/spec/unit/action/set_name_of_domain_spec.rb index d1b3035..a30ff87 100644 --- a/spec/unit/action/set_name_of_domain_spec.rb +++ b/spec/unit/action/set_name_of_domain_spec.rb @@ -14,7 +14,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do end it 'builds simple domain name' do - @env.default_prefix = 'pre' + @env.default_prefix = 'pre_' dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env) dmn.build_domain_name(@env).should eq('pre_') end From 7c436b42c3694131e82e409d9ac2946f84e76b62 Mon Sep 17 00:00:00 2001 From: David Breese Date: Mon, 7 May 2018 00:16:06 -0500 Subject: [PATCH 05/28] README (Debian install): Don't autorun dnsmasq Current install instructions for Debian/Ubuntu install the package "dnsmasq", which results in dnsmasq being immediately started and configured to run as a system service. This is probably not something vagrant-libvirt users typically want. Instead, package "dnsmasq-base" exists, which achieves precisely what is probably desired here. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a49240..7997646 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ vagrant-libvirt. This depends on your distro. An overview: * Ubuntu 12.04/14.04/16.04, Debian: ```shell apt-get build-dep vagrant ruby-libvirt -apt-get install qemu libvirt-bin ebtables dnsmasq +apt-get install qemu libvirt-bin ebtables dnsmasq-base apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev ``` From 24b12af31a7e18d1afceb84a085fc446029c0d49 Mon Sep 17 00:00:00 2001 From: Matthew Andersen Date: Mon, 21 May 2018 22:33:18 -0700 Subject: [PATCH 06/28] Default Port Forwarding to All Host Addresses Change the default scope of port forwarding from localhost to all host devices. --- lib/vagrant-libvirt/action/forward_ports.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/action/forward_ports.rb b/lib/vagrant-libvirt/action/forward_ports.rb index 7afe1aa..79c4d84 100644 --- a/lib/vagrant-libvirt/action/forward_ports.rb +++ b/lib/vagrant-libvirt/action/forward_ports.rb @@ -54,7 +54,7 @@ module VagrantPlugins ssh_pid = redirect_port( @env[:machine], - fp[:host_ip] || 'localhost', + fp[:host_ip] || '*', fp[:host], fp[:guest_ip] || @env[:machine].provider.ssh_info[:host], fp[:guest], From 7466b8e026748c3066092562324331183880f90e Mon Sep 17 00:00:00 2001 From: Brad Searle Date: Sun, 12 Aug 2018 10:00:34 +1000 Subject: [PATCH 07/28] add default_prefix domain option docs --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0a49240..24f9a90 100644 --- a/README.md +++ b/README.md @@ -321,6 +321,9 @@ end to qemu `-initrd`. * `random_hostname` - To create a domain name with extra information on the end to prevent hostname conflicts. +* `default_prefix` - The default libvirt guest name becomes a concatenation of the + `_`. The current working directory is the default prefix + to the guest name. The `default_prefix` options allow you to set the guest name prefix. * `cmd_line` - Arguments passed on to the guest kernel initramfs or initrd to use. Equivalent to qemu `-append`, only possible to use in combination with `initrd` and `kernel`. * `graphics_type` - Sets the protocol used to expose the guest display. From 5f7841ffffcdbdccd55f2065bef0ca16c2d79580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Sun, 2 Dec 2018 22:56:50 +0100 Subject: [PATCH 08/28] Revert back to development version of .gemspec file. (#929) This reverts commit 34a0def7d1d369a692ea5a431e127061403f6ec6, because it seems to be completely accidental change, when the file was overridden by Bundler or so. --- vagrant-libvirt.gemspec | 59 +++++++++++++---------------------------- 1 file changed, 18 insertions(+), 41 deletions(-) diff --git a/vagrant-libvirt.gemspec b/vagrant-libvirt.gemspec index 70610c0..dabb5f0 100644 --- a/vagrant-libvirt.gemspec +++ b/vagrant-libvirt.gemspec @@ -1,51 +1,28 @@ # -*- encoding: utf-8 -*- -# stub: vagrant-libvirt 0.0.42 ruby lib +require File.expand_path('../lib/vagrant-libvirt/version', __FILE__) Gem::Specification.new do |s| - s.name = "vagrant-libvirt".freeze - s.version = "0.0.45" + s.authors = ['Lukas Stanek','Dima Vasilets','Brian Pitts'] + s.email = ['ls@elostech.cz','pronix.service@gmail.com','brian@polibyte.com'] + s.license = 'MIT' + s.description = %q{libvirt provider for Vagrant.} + s.summary = %q{libvirt provider for Vagrant.} + s.homepage = 'https://github.com/vagrant-libvirt/vagrant-libvirt' - s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= - s.require_paths = ["lib".freeze] - s.authors = ["Lukas Stanek".freeze, "Dima Vasilets".freeze, "Brian Pitts".freeze] s.files = `git ls-files`.split($\) + s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) } s.test_files = s.files.grep(%r{^(test|spec|features)/}) - s.description = "libvirt provider for Vagrant.".freeze - s.email = ["ls@elostech.cz".freeze, "pronix.service@gmail.com".freeze, "brian@polibyte.com".freeze] - s.homepage = "https://github.com/vagrant-libvirt/vagrant-libvirt".freeze - s.licenses = ["MIT".freeze] - s.rubygems_version = "2.6.14".freeze - s.summary = "libvirt provider for Vagrant.".freeze + s.name = 'vagrant-libvirt' + s.require_paths = ['lib'] + s.version = VagrantPlugins::ProviderLibvirt::VERSION - s.installed_by_version = "2.6.14" if s.respond_to? :installed_by_version + s.add_development_dependency "rspec-core", "~> 3.5.0" + s.add_development_dependency "rspec-expectations", "~> 3.5.0" + s.add_development_dependency "rspec-mocks", "~> 3.5.0" - if s.respond_to? :specification_version then - s.specification_version = 4 + s.add_runtime_dependency 'fog-libvirt', '>= 0.3.0' + s.add_runtime_dependency 'nokogiri', '~> 1.6.0' + s.add_runtime_dependency 'fog-core', '~> 1.43.0' - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_development_dependency(%q.freeze, ["~> 3.5.0"]) - s.add_development_dependency(%q.freeze, ["~> 3.5.0"]) - s.add_development_dependency(%q.freeze, ["~> 3.5.0"]) - s.add_runtime_dependency(%q.freeze, [">= 0.3.0"]) - s.add_runtime_dependency(%q.freeze, [">= 1.6.0"]) - s.add_runtime_dependency(%q.freeze, ["~> 1.43.0"]) - s.add_development_dependency(%q.freeze, [">= 0"]) - else - s.add_dependency(%q.freeze, ["~> 3.5.0"]) - s.add_dependency(%q.freeze, ["~> 3.5.0"]) - s.add_dependency(%q.freeze, ["~> 3.5.0"]) - s.add_dependency(%q.freeze, [">= 0.3.0"]) - s.add_dependency(%q.freeze, [">= 1.6.0"]) - s.add_dependency(%q.freeze, ["~> 1.43.0"]) - s.add_dependency(%q.freeze, [">= 0"]) - end - else - s.add_dependency(%q.freeze, ["~> 3.5.0"]) - s.add_dependency(%q.freeze, ["~> 3.5.0"]) - s.add_dependency(%q.freeze, ["~> 3.5.0"]) - s.add_dependency(%q.freeze, [">= 0.3.0"]) - s.add_dependency(%q.freeze, [">= 1.6.0"]) - s.add_dependency(%q.freeze, ["~> 1.43.0"]) - s.add_dependency(%q.freeze, [">= 0"]) - end + s.add_development_dependency 'rake' end From d5ba63d413b5540fd75318cf0c50dc8de65c4ad9 Mon Sep 17 00:00:00 2001 From: Michael Ablassmeier Date: Tue, 4 Dec 2018 17:43:38 +0100 Subject: [PATCH 09/28] #952 : support different storage pool for base box snapshot (#953) --- lib/vagrant-libvirt/action/create_domain.rb | 9 ++++++++- lib/vagrant-libvirt/action/create_domain_volume.rb | 8 +++++++- lib/vagrant-libvirt/config.rb | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 81d8499..74a4f49 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -81,6 +81,7 @@ module VagrantPlugins # Storage @storage_pool_name = config.storage_pool_name + @snapshot_pool_name = config.snapshot_pool_name @disks = config.disks @cdroms = config.cdroms @@ -119,9 +120,15 @@ module VagrantPlugins # Get path to domain image from the storage pool selected if we have a box. if env[:machine].config.vm.box + if @snapshot_pool_name != 'default' + pool_name = @snapshot_pool_name + else + pool_name = @storage_pool_name + end + @logger.debug "Search for volume in pool: #{pool_name}" actual_volumes = env[:machine].provider.driver.connection.volumes.all.select do |x| - x.pool_name == @storage_pool_name + x.pool_name == pool_name end domain_volume = ProviderLibvirt::Util::Collection.find_matching( actual_volumes, "#{@name}.img" diff --git a/lib/vagrant-libvirt/action/create_domain_volume.rb b/lib/vagrant-libvirt/action/create_domain_volume.rb index 6633788..360d6a6 100644 --- a/lib/vagrant-libvirt/action/create_domain_volume.rb +++ b/lib/vagrant-libvirt/action/create_domain_volume.rb @@ -71,9 +71,15 @@ module VagrantPlugins Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS | Nokogiri::XML::Node::SaveOptions::FORMAT ) + if config.snapshot_pool_name != 'default' + pool_name = config.snapshot_pool_name + else + pool_name = config.storage_pool_name + end + @logger.debug "Using pool #{pool_name} for base box snapshot" domain_volume = env[:machine].provider.driver.connection.volumes.create( xml: xml, - pool_name: config.storage_pool_name + pool_name: pool_name ) rescue Fog::Errors::Error => e raise Errors::FogDomainVolumeCreateError, diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 887eb38..2aa1bce 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -42,6 +42,9 @@ module VagrantPlugins attr_accessor :storage_pool_name attr_accessor :storage_pool_path + # Libvirt storage pool where the base image snapshot shall be stored + attr_accessor :snapshot_pool_name + # Turn on to prevent hostname conflicts attr_accessor :random_hostname @@ -170,6 +173,7 @@ module VagrantPlugins @password = UNSET_VALUE @id_ssh_key_file = UNSET_VALUE @storage_pool_name = UNSET_VALUE + @snapshot_pool_name = UNSET_VALUE @random_hostname = UNSET_VALUE @management_network_device = UNSET_VALUE @management_network_name = UNSET_VALUE @@ -638,6 +642,7 @@ module VagrantPlugins @password = nil if @password == UNSET_VALUE @id_ssh_key_file = 'id_rsa' if @id_ssh_key_file == UNSET_VALUE @storage_pool_name = 'default' if @storage_pool_name == UNSET_VALUE + @snapshot_pool_name = 'default' if @snapshot_pool_name == UNSET_VALUE @storage_pool_path = nil if @storage_pool_path == UNSET_VALUE @random_hostname = false if @random_hostname == UNSET_VALUE @management_network_device = 'virbr0' if @management_network_device == UNSET_VALUE From c1d2144ec26b426112012d96dbd7bd5704fa43c4 Mon Sep 17 00:00:00 2001 From: Peter Slootweg Date: Thu, 17 Jan 2019 09:38:34 +0100 Subject: [PATCH 10/28] check for 'ssh' service to see if interface is up the 'echo' service is often not available out-of-the-box, so the 'ping' of the ssh interface fails. This results in the wrong ip addresses being used in /etc/exports, which results in the vm not being able to mount the vagrant shares. The 'vagrant ssh interface' will have the service 'ssh' available (you won't be able to login to your vagrant box else), so it makes sense to use that service for the ping. This fixes the vm not being able to mount the shares over nfs after a reload due to the wrong ip addresses being used. --- 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 6390891..b07543e 100644 --- a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +++ b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb @@ -79,7 +79,7 @@ module VagrantPlugins # Check if we can open a connection to the host def ping(host, timeout = 3) ::Timeout.timeout(timeout) do - s = TCPSocket.new(host, 'echo') + s = TCPSocket.new(host, 'ssh') s.close end true From 41e5b2f362e9296d89e69bfe2cbe01fa8b439dbc Mon Sep 17 00:00:00 2001 From: Daniel T Chen Date: Mon, 11 Feb 2019 20:18:02 -0500 Subject: [PATCH 11/28] Updated Libvirt-based Vagrant box search reference and edited names for consistency --- README.md | 120 +++++++++--------- example_box/README.md | 2 +- example_box/Vagrantfile | 8 +- lib/vagrant-libvirt/action.rb | 2 +- lib/vagrant-libvirt/action/create_domain.rb | 2 +- .../action/create_network_interfaces.rb | 2 +- lib/vagrant-libvirt/action/create_networks.rb | 4 +- lib/vagrant-libvirt/action/destroy_domain.rb | 2 +- lib/vagrant-libvirt/action/halt_domain.rb | 2 +- .../action/handle_box_image.rb | 2 +- .../action/handle_storage_pool.rb | 2 +- lib/vagrant-libvirt/action/package_domain.rb | 2 +- .../action/remove_libvirt_image.rb | 4 +- lib/vagrant-libvirt/action/set_boot_order.rb | 4 +- .../action/set_name_of_domain.rb | 2 +- lib/vagrant-libvirt/action/start_domain.rb | 2 +- lib/vagrant-libvirt/action/wait_till_up.rb | 2 +- lib/vagrant-libvirt/cap/synced_folder.rb | 6 +- lib/vagrant-libvirt/config.rb | 16 +-- lib/vagrant-libvirt/driver.rb | 6 +- lib/vagrant-libvirt/errors.rb | 2 +- lib/vagrant-libvirt/plugin.rb | 4 +- lib/vagrant-libvirt/templates/domain.xml.erb | 2 +- lib/vagrant-libvirt/util/network_util.rb | 2 +- locales/en.yml | 10 +- tools/prepare_redhat_for_box.sh | 8 +- 26 files changed, 110 insertions(+), 110 deletions(-) diff --git a/README.md b/README.md index dba79cf..1a4b426 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://travis-ci.org/vagrant-libvirt/vagrant-libvirt.svg)](https://travis-ci.org/vagrant-libvirt/vagrant-libvirt) [![Coverage Status](https://coveralls.io/repos/github/vagrant-libvirt/vagrant-libvirt/badge.svg?branch=master)](https://coveralls.io/github/vagrant-libvirt/vagrant-libvirt?branch=master) -This is a [Vagrant](http://www.vagrantup.com) plugin that adds an +This is a [Vagrant](http://www.vagrantup.com) plugin that adds a [Libvirt](http://libvirt.org) provider to Vagrant, allowing Vagrant to control and provision machines via Libvirt toolkit. @@ -83,24 +83,24 @@ can help a lot :-) ## Installation -First, you should have both qemu and libvirt installed if you plan to run VMs -on your local system. For instructions, refer to your linux distribution's +First, you should have both QEMU and Libvirt installed if you plan to run VMs +on your local system. For instructions, refer to your Linux distribution's documentation. -**NOTE:** Before you start using Vagrant-libvirt, please make sure your libvirt -and qemu installation is working correctly and you are able to create qemu or -kvm type virtual machines with `virsh` or `virt-manager`. +**NOTE:** Before you start using vagrant-libvirt, please make sure your Libvirt +and QEMU installation is working correctly and you are able to create QEMU or +KVM type virtual machines with `virsh` or `virt-manager`. Next, you must have [Vagrant installed](http://docs.vagrantup.com/v2/installation/index.html). Vagrant-libvirt supports Vagrant 1.5, 1.6, 1.7 and 1.8. -*We only test with the upstream version!* If you decide to install your distros +*We only test with the upstream version!* If you decide to install your distro's version and you run into problems, as a first step you should switch to upstream. Now you need to make sure your have all the build dependencies installed for vagrant-libvirt. This depends on your distro. An overview: -* Ubuntu 12.04/14.04/16.04, Debian: +* Ubuntu, Debian: ```shell apt-get build-dep vagrant ruby-libvirt apt-get install qemu libvirt-bin ebtables dnsmasq-base @@ -119,7 +119,7 @@ yum install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm dnf -y install qemu libvirt libvirt-devel ruby-devel gcc ``` -* Arch linux: please read the related [ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt) page. +* Arch Linux: please read the related [ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt) page. ```shell pacman -S vagrant ``` @@ -147,7 +147,7 @@ $ sudo dnf install libxslt-devel libxml2-devel libvirt-devel \ libguestfs-tools-c ruby-devel gcc ``` -On Arch linux it is recommended to follow [steps from ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt). +On Arch Linux it is recommended to follow [steps from ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt). If have problem with installation - check your linker. It should be `ld.gold`: @@ -169,8 +169,8 @@ CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/u After installing the plugin (instructions above), the quickest way to get 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. -You can find more libvirt ready boxes at -[Atlas](https://atlas.hashicorp.com/boxes/search?provider=libvirt). For +You can find more Libvirt-ready boxes at +[Vagrant Cloud](https://app.vagrantup.com/boxes/search?provider=libvirt). For example: ```shell @@ -210,7 +210,7 @@ export VAGRANT_DEFAULT_PROVIDER=libvirt Vagrant goes through steps below when creating new project: -1. Connect to Libvirt localy or remotely via SSH. +1. Connect to Libvirt locally or remotely via SSH. 2. Check if box image is available in Libvirt storage pool. If not, upload it to remote Libvirt storage pool as new volume. 3. Create COW diff image of base box image for new Libvirt domain. @@ -227,22 +227,22 @@ Vagrant goes through steps below when creating new project: Although it should work without any configuration for most people, this provider exposes quite a few provider-specific configuration options. The following options allow you to configure how vagrant-libvirt connects to -libvirt, and are used to generate the [libvirt connection +Libvirt, and are used to generate the [Libvirt connection URI](http://libvirt.org/uri.html): -* `driver` - A hypervisor name to access. For now only kvm and qemu are +* `driver` - A hypervisor name to access. For now only KVM and QEMU are supported -* `host` - The name of the server, where libvirtd is running +* `host` - The name of the server, where Libvirtd is running * `connect_via_ssh` - If use ssh tunnel to connect to Libvirt. Absolutely - needed to access libvirt on remote host. It will not be able to get the IP + needed to access Libvirt on remote host. It will not be able to get the IP address of a started VM otherwise. * `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 -* `socket` - Path to the libvirt unix socket (e.g. +* `socket` - Path to the Libvirt unix socket (e.g. `/var/run/libvirt/libvirt-sock`) -* `uri` - For advanced usage. Directly specifies what libvirt connection URI +* `uri` - For advanced usage. Directly specifies what Libvirt connection URI vagrant-libvirt should use. Overrides all other connection configuration options @@ -264,7 +264,7 @@ end ### Domain Specific Options * `disk_bus` - The type of disk device to emulate. Defaults to virtio if not - set. Possible values are documented in libvirt's [description for + set. Possible values are documented in Libvirt's [description for _target_](http://libvirt.org/formatdomain.html#elementsDisks). NOTE: this option applies only to disks associated with a box image. To set the bus type on additional disks, see the [Additional Disks](#additional-disks) section. @@ -275,7 +275,7 @@ end * `nic_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](https://libvirt.org/formatdomain.html#elementsNICSModel). + Libvirt](https://libvirt.org/formatdomain.html#elementsNICSModel). * `memory` - Amount of memory in MBytes. Defaults to 512 if not set. * `cpus` - Number of virtual cpus. Defaults to 1 if not set. * `cputopology` - Number of CPU sockets, cores and threads running per core. All fields of `:sockets`, `:cores` and `:threads` are mandatory, `cpus` domain option must be present and must be equal to total count of **sockets * cores * threads**. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsCPU). @@ -299,7 +299,7 @@ end * `cpu_model` - CPU Model. Defaults to 'qemu64' if not set and `cpu_mode` is `custom` and to '' otherwise. This can really only be used when setting `cpu_mode` to `custom`. -* `cpu_fallback` - Whether to allow libvirt to fall back to a CPU model close +* `cpu_fallback` - Whether to allow Libvirt to fall back to a CPU model close to the specified model if features in the guest CPU are not supported on the host. Defaults to 'allow' if not set. Allowed values: `allow`, `forbid`. * `numa_nodes` - Specify an array of NUMA nodes for the guest. The syntax is similar to what would be set in the domain XML. `memory` must be in MB. Symmetrical and asymmetrical topologies are supported but make sure your total count of defined CPUs adds up to `v.cpus`. @@ -315,7 +315,7 @@ end * `loader` - Sets path to custom UEFI loader. * `volume_cache` - Controls the cache mechanism. Possible values are "default", "none", "writethrough", "writeback", "directsync" and "unsafe". [See - driver->cache in libvirt + driver->cache in Libvirt documentation](http://libvirt.org/formatdomain.html#elementsDisks). * `kernel` - To launch the guest with a kernel residing on host filesystems. Equivalent to qemu `-kernel`. @@ -323,7 +323,7 @@ end to qemu `-initrd`. * `random_hostname` - To create a domain name with extra information on the end to prevent hostname conflicts. -* `default_prefix` - The default libvirt guest name becomes a concatenation of the +* `default_prefix` - The default Libvirt guest name becomes a concatenation of the `_`. The current working directory is the default prefix to the guest name. The `default_prefix` options allow you to set the guest name prefix. * `cmd_line` - Arguments passed on to the guest kernel initramfs or initrd to @@ -336,8 +336,8 @@ end * `graphics_ip` - Sets the IP for the display protocol to bind to. Defaults to "127.0.0.1". * `graphics_passwd` - Sets the password for the display protocol. Working for - vnc and spice. by default working without passsword. -* `graphics_autoport` - Sets autoport for graphics, libvirt in this case + vnc and Spice. by default working without passsword. +* `graphics_autoport` - Sets autoport for graphics, Libvirt in this case ignores graphics_port value, Defaults to 'yes'. Possible value are "yes" and "no" * `keymap` - Set keymap for vm. default: en-us @@ -354,8 +354,8 @@ end Defaults to "ich6". * `machine_type` - 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. +* `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`, @@ -379,7 +379,7 @@ end * `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. -* `uuid` - Force a domain UUID. Defaults to autogenerated value by libvirt if +* `uuid` - Force a domain UUID. Defaults to autogenerated value by Libvirt if not set. * `suspend_mode` - What is done on vagrant suspend. Possible values: 'pause', 'managedsave'. Pause mode executes a la `virsh suspend`, which just pauses @@ -393,10 +393,10 @@ end specified here. * `autostart` - Automatically start the domain when the host boots. Defaults to 'false'. -* `channel` - [libvirt +* `channel` - [Libvirt channels](https://libvirt.org/formatdomain.html#elementCharChannel). Configure a private communication channel between the host and guest, e.g. - for use by the [qemu guest + for use by the [QEMU guest agent](http://wiki.libvirt.org/page/Qemu_guest_agent) and the Spice/QXL graphics type. * `mgmt_attach` - Decide if VM has interface in mgmt network. If set to 'false' @@ -477,11 +477,11 @@ https://libvirt.org/formatdomain.html#elementsNICSTCP http://libvirt.org/formatdomain.html#elementsNICSMulticast -http://libvirt.org/formatdomain.html#elementsNICSUDP _(in libvirt v1.2.20 and higher)_ +http://libvirt.org/formatdomain.html#elementsNICSUDP _(in Libvirt v1.2.20 and higher)_ 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 documentation for the details of the macvtap usage. +See the following Libvirt documentation for the details of the macvtap usage. http://www.libvirt.org/formatdomain.html#elementsNICSDirect @@ -550,7 +550,7 @@ In example below, one network interface is configured for VM `test_vm1`. After you run `vagrant up`, VM will be accessible on IP address `10.20.30.40`. So if you install a web server via provisioner, you will be able to access your testing server on `http://10.20.30.40` URL. But beware that this address is -private to libvirt host only. It's not visible outside of the hypervisor box. +private to Libvirt host only. It's not visible outside of the hypervisor box. If network `10.20.30.0/24` doesn't exist, provider will create it. By default created networks are NATed to outside world, so your VM will be able to connect @@ -567,11 +567,11 @@ reachable by anyone with access to the public network. *Note: These options are not applicable to public network interfaces.* -There is a way to pass specific options for libvirt provider when using +There is a way to pass specific options for Libvirt provider when using `config.vm.network` to configure new network interface. Each parameter name starts with `libvirt__` string. Here is a list of those options: -* `:libvirt__network_name` - Name of libvirt network to connect to. By default, +* `:libvirt__network_name` - Name of Libvirt network to connect to. By default, network 'default' is used. * `:libvirt__netmask` - Used only together with `:ip` option. Default is '255.255.255.0'. @@ -610,7 +610,7 @@ starts with `libvirt__` string. Here is a list of those options: between Guests. Useful for Switch VMs like Cumulus Linux. No virtual switch setting like `libvirt__network_name` applies with tunnel interfaces and will be ignored if configured. -* `:libvirt__tunnel_ip` - Sets the source IP of the libvirt tunnel interface. +* `:libvirt__tunnel_ip` - Sets the source IP of the Libvirt tunnel interface. By default this is `127.0.0.1` for TCP and UDP tunnels and `239.255.1.1` for Multicast tunnels. It populates the address field in the `` of the interface xml configuration. @@ -620,11 +620,11 @@ starts with `libvirt__` string. Here is a list of those options: * `:libvirt__tunnel_local_port` - Sets the local port used by the udp tunnel interface type. It populates the port field in the `` section of the interface xml configuration. _(This feature only works in - libvirt 1.2.20 and higher)_ + Libvirt 1.2.20 and higher)_ * `:libvirt__tunnel_local_ip` - Sets the local IP used by the udp tunnel interface type. It populates the ip entry of the `` section of the interface xml configuration. _(This feature only works in - libvirt 1.2.20 and higher)_ + Libvirt 1.2.20 and higher)_ * `:libvirt__guest_ipv6` - Enable or disable guest-to-guest IPv6 communication. See [here](https://libvirt.org/formatnetwork.html#examplesPrivate6), and [here](http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=705e67d40b09a905cd6a4b8b418d5cb94eaa95a8) @@ -636,18 +636,18 @@ starts with `libvirt__` string. Here is a list of those options: failures](https://github.com/vagrant-libvirt/vagrant-libvirt/pull/498) * `:mac` - MAC address for the interface. *Note: specify this in lowercase since Vagrant network scripts assume it will be!* -* `:libvirt__mtu` - MTU size for the libvirt network, if not defined, the - created network will use the libvirt default (1500). VMs still need to set the +* `:libvirt__mtu` - MTU size for the Libvirt network, if not defined, the + created network will use the Libvirt default (1500). VMs still need to set the MTU accordingly. * `: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 + documentation for Libvirt * `:libvirt__driver_name` - Define which network driver to use. [More info](https://libvirt.org/formatdomain.html#elementsDriverBackendOptions) * `:libvirt__driver_queues` - Define a number of queues to be used for network interface. Set equal to numer of vCPUs for best performance. [More info](http://www.linux-kvm.org/page/Multiqueue) -* `:autostart` - Automatic startup of network by the libvirt daemon. +* `:autostart` - Automatic startup of network by the Libvirt daemon. If not specified the default is 'false'. * `:bus` - The bus of the PCI device. Both :bus and :slot have to be defined. * `:slot` - The slot of the PCI device. Both :bus and :slot have to be defined. @@ -668,8 +668,8 @@ virtual network. Default mode is 'bridge'. * `:type` - is type of interface.(``) * `:mac` - MAC address for the interface. -* `:network_name` - Name of libvirt network to connect to. -* `:portgroup` - Name of libvirt portgroup to connect to. +* `:network_name` - Name of Libvirt network to connect to. +* `:portgroup` - Name of Libvirt portgroup to connect to. * `:ovs` - Support to connect to an Open vSwitch bridge device. Default is 'false'. * `:trust_guest_rx_filters` - Support trustGuestRxFilters attribute. Details @@ -680,17 +680,17 @@ virtual network. vagrant-libvirt uses a private network to perform some management operations on VMs. All VMs will have an interface connected to this network and an IP address -dynamically assigned by libvirt unless you set `:mgmt_attach` to 'false'. +dynamically assigned by Libvirt unless you set `:mgmt_attach` to 'false'. This is in addition to any networks you configure. The name and address used by this network are configurable at the provider level. -* `management_network_name` - Name of libvirt network to which all VMs will be +* `management_network_name` - Name of Libvirt network to which all VMs will be connected. If not specified the default is 'vagrant-libvirt'. * `management_network_address` - Address of network to which all VMs will be connected. Must include the address and subnet mask. If not specified the default is '192.168.121.0/24'. -* `management_network_mode` - Network mode for the libvirt management network. - Specify one of veryisolated, none, nat or route options. Further documentated +* `management_network_mode` - Network mode for the Libvirt management network. + Specify one of veryisolated, none, nat or route options. Further documented under [Private Networks](#private-network-options) * `management_network_guest_ipv6` - Enable or disable guest-to-guest IPv6 communication. See @@ -892,8 +892,8 @@ Bus 001 Device 002: ID 1234:abcd Example device Additionally, the following options can be used: -* `startupPolicy` - Is passed through to libvirt and controls if the device has - to exist. libvirt currently allows the following values: "mandatory", +* `startupPolicy` - Is passed through to Libvirt and controls if the device has + to exist. Libvirt currently allows the following values: "mandatory", "requisite", "optional". @@ -987,7 +987,7 @@ The optional action attribute describes what `action` to take when the watchdog ```ruby Vagrant.configure("2") do |config| config.vm.provider :libvirt do |libvirt| - # Add libvirt watchdog device model i6300esb + # Add Libvirt watchdog device model i6300esb libvirt.watchdog :model => 'i6300esb', :action => 'reset' end end @@ -1047,7 +1047,7 @@ running Microsoft Windows. You can specify HyperV features via `libvirt.hyperv_feature`. Available options are listed below. Note that both options are required: -* `name` - The name of the feature Hypervisor feature (see libvirt doc) +* `name` - The name of the feature Hypervisor feature (see Libvirt doc) * `state` - The state for this feature which can be either `on` or `off`. ```ruby @@ -1066,10 +1066,10 @@ end You can specify CPU feature policies via `libvirt.cpu_feature`. Available options are listed below. Note that both options are required: -* `name` - The name of the feature for the chosen CPU (see libvirts +* `name` - The name of the feature for the chosen CPU (see Libvirt's `cpu_map.xml`) * `policy` - The policy for this feature (one of `force`, `require`, - `optional`, `disable` and `forbid` - see libvirt documentation) + `optional`, `disable` and `forbid` - see Libvirt documentation) ```ruby Vagrant.configure("2") do |config| @@ -1224,8 +1224,8 @@ mounting them at boot. Further documentation on using 9p can be found in [kernel docs](https://www.kernel.org/doc/Documentation/filesystems/9p.txt) and in [QEMU wiki](https://wiki.qemu.org/Documentation/9psetup#Starting_the_Guest_directly). Please do note that 9p depends on support in the guest and not all distros come with the 9p module by default. -**SECURITY 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. ## QEMU Session Support @@ -1242,7 +1242,7 @@ Vagrant.configure("2") do |config| libvirt.uri = 'qemu:///session' # URI of QEMU system connection, use to obtain IP address for management libvirt.system_uri = 'qemu:///system' - # Path to store libvirt images for the virtual machine, default is as ~/.local/share/libvirt/images + # Path to store Libvirt images for the virtual machine, default is as ~/.local/share/libvirt/images libvirt.storage_pool_path = '/home/user/.local/share/libvirt/images' # Management network device libvirt.management_network_device = 'virbr0' @@ -1305,7 +1305,7 @@ end For certain functionality to be available within a guest, a private communication channel must be established with the host. Two notable examples -of this are the qemu guest agent, and the Spice/QXL graphics type. +of this are the QEMU guest agent, and the Spice/QXL graphics type. Below is a simple example which exposes a virtio serial channel to the guest. Note: in a multi-VM environment, the channel would be created for all VMs. @@ -1331,7 +1331,7 @@ end These settings can be specified on a per-VM basis, however the per-guest settings will OVERRIDE any global 'config' setting. In the following example, -we create 3 VM with the following configuration: +we create 3 VMs with the following configuration: * **master**: No channel settings specified, so we default to the provider setting of a single virtio guest agent channel. diff --git a/example_box/README.md b/example_box/README.md index 3210ac0..53464fc 100644 --- a/example_box/README.md +++ b/example_box/README.md @@ -2,7 +2,7 @@ Vagrant providers each require a custom provider-specific box format. This folder shows the example contents of a box for the `libvirt` provider. -To turn this into a box create a vagrant image according documentation (don't +To turn this into a box create a Vagrant image according documentation (don't forget to install rsync command) and create box with following command: ``` diff --git a/example_box/Vagrantfile b/example_box/Vagrantfile index a34b797..6b22b31 100644 --- a/example_box/Vagrantfile +++ b/example_box/Vagrantfile @@ -27,18 +27,18 @@ Vagrant.configure("2") do |config| #test_vm.vm.network :public_network, :ip => '10.20.30.41' #end - # Options for libvirt vagrant provider. + # Options for Libvirt Vagrant provider. config.vm.provider :libvirt do |libvirt| # A hypervisor name to access. Different drivers can be specified, but # this version of provider creates KVM machines only. Some examples of - # drivers are kvm (qemu hardware accelerated), qemu (qemu emulated), - # xen (Xen hypervisor), lxc (Linux Containers), + # drivers are KVM (QEMU hardware accelerated), QEMU (QEMU emulated), + # Xen (Xen hypervisor), lxc (Linux Containers), # esx (VMware ESX), vmwarews (VMware Workstation) and more. Refer to # documentation for available drivers (http://libvirt.org/drivers.html). libvirt.driver = "kvm" - # The name of the server, where libvirtd is running. + # The name of the server, where Libvirtd is running. # libvirt.host = "localhost" # If use ssh tunnel to connect to Libvirt. diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index 146d339..4dea598 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -8,7 +8,7 @@ module VagrantPlugins include Vagrant::Action::Builtin @logger = Log4r::Logger.new('vagrant_libvirt::action') - # remove image from libvirt storage pool + # remove image from Libvirt storage pool def self.remove_libvirt_image Vagrant::Action::Builder.new.tap do |b| b.use RemoveLibvirtImage diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 74a4f49..1862237 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -323,7 +323,7 @@ module VagrantPlugins env[:ui].info(" -- Command line : #{@cmd_line}") unless @cmd_line.empty? - # Create libvirt domain. + # Create Libvirt domain. # Is there a way to tell fog to create new domain with already # existing volume? Use domain creation from template.. begin diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb index bc0feb4..130b37c 100644 --- a/lib/vagrant-libvirt/action/create_network_interfaces.rb +++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb @@ -283,7 +283,7 @@ module VagrantPlugins return options[:network_name] end - # Get list of all (active and inactive) libvirt networks. + # Get list of all (active and inactive) Libvirt networks. available_networks = libvirt_networks(libvirt_client) return 'public' if options[:iface_type] == :public_network diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index f5ee5b5..9ca21d3 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -47,9 +47,9 @@ module VagrantPlugins # should fix other methods so this doesn't have to be instance var @options = options - # Get a list of all (active and inactive) libvirt networks. This + # 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. + # process than Libvirt API calls. @available_networks = libvirt_networks( env[:machine].provider.driver.connection.client ) diff --git a/lib/vagrant-libvirt/action/destroy_domain.rb b/lib/vagrant-libvirt/action/destroy_domain.rb index ce6ffbd..037b902 100644 --- a/lib/vagrant-libvirt/action/destroy_domain.rb +++ b/lib/vagrant-libvirt/action/destroy_domain.rb @@ -14,7 +14,7 @@ module VagrantPlugins env[:ui].info(I18n.t('vagrant_libvirt.destroy_domain')) # Must delete any snapshots before domain can be destroyed - # Fog libvirt currently doesn't support snapshots. Use + # 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[:machine].provider.driver.connection.client.lookup_domain_by_uuid( diff --git a/lib/vagrant-libvirt/action/halt_domain.rb b/lib/vagrant-libvirt/action/halt_domain.rb index 668ebd2..274acd0 100644 --- a/lib/vagrant-libvirt/action/halt_domain.rb +++ b/lib/vagrant-libvirt/action/halt_domain.rb @@ -19,7 +19,7 @@ module VagrantPlugins begin env[:machine].guest.capability(:halt) rescue - @logger.info('Trying libvirt graceful shutdown.') + @logger.info('Trying Libvirt graceful shutdown.') domain.shutdown end diff --git a/lib/vagrant-libvirt/action/handle_box_image.rb b/lib/vagrant-libvirt/action/handle_box_image.rb index 990ea7d..3a97356 100644 --- a/lib/vagrant-libvirt/action/handle_box_image.rb +++ b/lib/vagrant-libvirt/action/handle_box_image.rb @@ -161,7 +161,7 @@ module VagrantPlugins protected - # Fog libvirt currently doesn't support uploading images to storage + # Fog Libvirt currently doesn't support uploading images to storage # pool volumes. Use ruby-libvirt client instead. def upload_image(image_file, pool_name, volume_name, env) image_size = File.size(image_file) # B diff --git a/lib/vagrant-libvirt/action/handle_storage_pool.rb b/lib/vagrant-libvirt/action/handle_storage_pool.rb index 04be07c..c2f0a72 100644 --- a/lib/vagrant-libvirt/action/handle_storage_pool.rb +++ b/lib/vagrant-libvirt/action/handle_storage_pool.rb @@ -36,7 +36,7 @@ module VagrantPlugins @logger.info("Creating storage pool 'default'") - # Fog libvirt currently doesn't support creating pools. Use + # Fog Libvirt currently doesn't support creating pools. Use # ruby-libvirt client directly. begin @storage_pool_path = storage_pool_path(env) diff --git a/lib/vagrant-libvirt/action/package_domain.rb b/lib/vagrant-libvirt/action/package_domain.rb index 94d3199..84e25ba 100644 --- a/lib/vagrant-libvirt/action/package_domain.rb +++ b/lib/vagrant-libvirt/action/package_domain.rb @@ -3,7 +3,7 @@ require 'log4r' module VagrantPlugins module ProviderLibvirt module Action - # Action for create new box for libvirt provider + # Action for create new box for Libvirt provider class PackageDomain def initialize(app, env) @logger = Log4r::Logger.new('vagrant_libvirt::action::package_domain') diff --git a/lib/vagrant-libvirt/action/remove_libvirt_image.rb b/lib/vagrant-libvirt/action/remove_libvirt_image.rb index 37dd36c..c9d9379 100644 --- a/lib/vagrant-libvirt/action/remove_libvirt_image.rb +++ b/lib/vagrant-libvirt/action/remove_libvirt_image.rb @@ -10,8 +10,8 @@ module VagrantPlugins 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 manually(virsh, virt-manager or by any other tool)') + env[:ui].info('Vagrant-libvirt plugin removed box only from your LOCAL ~/.vagrant/boxes directory') + env[:ui].info('From Libvirt storage pool you have to delete image manually(virsh, virt-manager or by any other tool)') @app.call(env) end end diff --git a/lib/vagrant-libvirt/action/set_boot_order.rb b/lib/vagrant-libvirt/action/set_boot_order.rb index a4629af..c5997f9 100644 --- a/lib/vagrant-libvirt/action/set_boot_order.rb +++ b/lib/vagrant-libvirt/action/set_boot_order.rb @@ -33,7 +33,7 @@ module VagrantPlugins if @boot_order.count >= 1 # If a domain is initially defined with no box or disk or - # with an explicit boot order, libvirt adds + # with an explicit boot order, Libvirt adds # This conflicts with an explicit boot_order configuration, # so we need to remove it from the domain xml and feed it back. # Also see https://bugzilla.redhat.com/show_bug.cgi?id=1248514 @@ -66,7 +66,7 @@ module VagrantPlugins logger_msg(node, index) end - # Finally redefine the domain XML through libvirt + # Finally redefine the domain XML through Libvirt # to apply the boot ordering env[:machine].provider .driver diff --git a/lib/vagrant-libvirt/action/set_name_of_domain.rb b/lib/vagrant-libvirt/action/set_name_of_domain.rb index c421c9e..5e76495 100644 --- a/lib/vagrant-libvirt/action/set_name_of_domain.rb +++ b/lib/vagrant-libvirt/action/set_name_of_domain.rb @@ -41,7 +41,7 @@ module VagrantPlugins # parsable and sortable by epoch time # @example # development-centos-6-chef-11_1404488971_3b7a569e2fd7c554b852 - # @return [String] libvirt domain name + # @return [String] Libvirt domain name def build_domain_name(env) config = env[:machine].provider_config domain_name = diff --git a/lib/vagrant-libvirt/action/start_domain.rb b/lib/vagrant-libvirt/action/start_domain.rb index 7461905..cc58cba 100644 --- a/lib/vagrant-libvirt/action/start_domain.rb +++ b/lib/vagrant-libvirt/action/start_domain.rb @@ -23,7 +23,7 @@ module VagrantPlugins libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id) - # libvirt API doesn't support modifying memory on NUMA enabled CPUs + # Libvirt API doesn't support modifying memory on NUMA enabled CPUs # http://libvirt.org/git/?p=libvirt.git;a=commit;h=d174394105cf00ed266bf729ddf461c21637c736 if config.numa_nodes == nil if config.memory.to_i * 1024 != libvirt_domain.max_memory diff --git a/lib/vagrant-libvirt/action/wait_till_up.rb b/lib/vagrant-libvirt/action/wait_till_up.rb index 972f4e4..4d5496d 100644 --- a/lib/vagrant-libvirt/action/wait_till_up.rb +++ b/lib/vagrant-libvirt/action/wait_till_up.rb @@ -28,7 +28,7 @@ module VagrantPlugins end # Wait for domain to obtain an ip address. Ip address is searched - # from arp table, either localy or remotely via ssh, if libvirt + # from arp table, either locally or remotely via ssh, if Libvirt # connection was done via ssh. env[:ip_address] = nil @logger.debug("Searching for IP for MAC address: #{domain.mac}") diff --git a/lib/vagrant-libvirt/cap/synced_folder.rb b/lib/vagrant-libvirt/cap/synced_folder.rb index 2f784bd..ce496da 100644 --- a/lib/vagrant-libvirt/cap/synced_folder.rb +++ b/lib/vagrant-libvirt/cap/synced_folder.rb @@ -20,7 +20,7 @@ module VagrantPlugins end def usable?(machine, _raise_error = false) - # bail now if not using libvirt since checking version would throw error + # 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 @@ -30,7 +30,7 @@ module VagrantPlugins end def prepare(machine, folders, _opts) - raise Vagrant::Errors::Error('No libvirt connection') if machine.provider.driver.connection.nil? + raise Vagrant::Errors::Error('No Libvirt connection') if machine.provider.driver.connection.nil? @conn = machine.provider.driver.connection.client begin @@ -89,7 +89,7 @@ module VagrantPlugins def cleanup(machine, _opts) if machine.provider.driver.connection.nil? - raise Vagrant::Errors::Error('No libvirt connection') + raise Vagrant::Errors::Error('No Libvirt connection') end @conn = machine.provider.driver.connection.client begin diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 2aa1bce..8f1ac5a 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -20,12 +20,12 @@ module VagrantPlugins # A hypervisor name to access via Libvirt. attr_accessor :driver - # The name of the server, where libvirtd is running. + # The name of the server, where Libvirtd is running. attr_accessor :host # If use ssh tunnel to connect to Libvirt. attr_accessor :connect_via_ssh - # Path towards the libvirt socket + # Path towards the Libvirt socket attr_accessor :socket # The username to access Libvirt. @@ -161,7 +161,7 @@ module VagrantPlugins # Additional qemuargs arguments attr_accessor :qemu_args - # Use qemu session instead of system + # Use QEMU session instead of system attr_accessor :qemu_use_session def initialize @@ -309,7 +309,7 @@ module VagrantPlugins end end - # is it better to raise our own error, or let libvirt cause the exception? + # is it better to raise our own error, or let Libvirt cause the exception? raise 'Only four cdroms may be attached at a time' end @@ -586,7 +586,7 @@ module VagrantPlugins # code to generate URI from a config moved out of the connect action def _generate_uri - # builds the libvirt connection URI from the given driver config + # builds the Libvirt connection URI from the given driver config # Setup connection uri. uri = @driver.dup virt_path = case uri @@ -602,7 +602,7 @@ module VagrantPlugins raise "Require specify driver #{uri}" end if uri == 'kvm' - uri = 'qemu' # use qemu uri for kvm domain type + uri = 'qemu' # use QEMU uri for KVM domain type end if @connect_via_ssh @@ -623,13 +623,13 @@ module VagrantPlugins uri << '?no_verify=1' if @id_ssh_key_file - # set ssh key for access to libvirt host + # set ssh key for access to Libvirt host uri << "\&keyfile=" # if no slash, prepend $HOME/.ssh/ @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 + # set path to Libvirt socket uri << "\&socket=" + @socket if @socket uri end diff --git a/lib/vagrant-libvirt/driver.rb b/lib/vagrant-libvirt/driver.rb index 8d64ac4..9352020 100644 --- a/lib/vagrant-libvirt/driver.rb +++ b/lib/vagrant-libvirt/driver.rb @@ -19,11 +19,11 @@ module VagrantPlugins end def connection - # If already connected to libvirt, just use it and don't connect + # If already connected to Libvirt, just use it and don't connect # again. return @@connection if @@connection - # Get config options for libvirt provider. + # Get config options for Libvirt provider. config = @machine.provider_config uri = config.uri @@ -50,7 +50,7 @@ module VagrantPlugins end def system_connection - # If already connected to libvirt, just use it and don't connect + # If already connected to Libvirt, just use it and don't connect # again. return @@system_connection if @@system_connection diff --git a/lib/vagrant-libvirt/errors.rb b/lib/vagrant-libvirt/errors.rb index 52ca770..5023ce2 100644 --- a/lib/vagrant-libvirt/errors.rb +++ b/lib/vagrant-libvirt/errors.rb @@ -54,7 +54,7 @@ module VagrantPlugins error_key(:wrong_box_format) end - # Fog libvirt exceptions + # Fog Libvirt exceptions class FogError < VagrantLibvirtError error_key(:fog_error) end diff --git a/lib/vagrant-libvirt/plugin.rb b/lib/vagrant-libvirt/plugin.rb index 4733d0c..8f7e85d 100644 --- a/lib/vagrant-libvirt/plugin.rb +++ b/lib/vagrant-libvirt/plugin.rb @@ -4,7 +4,7 @@ rescue LoadError raise 'The Vagrant Libvirt plugin must be run within Vagrant.' end -# compatibility fix to define constant not available vagrant <1.6 +# compatibility fix to define constant not available Vagrant <1.6 ::Vagrant::MachineState::NOT_CREATED_ID ||= :not_created module VagrantPlugins @@ -12,7 +12,7 @@ module VagrantPlugins class Plugin < Vagrant.plugin('2') name 'libvirt' description <<-DESC - Vagrant plugin to manage VMs in libvirt. + Vagrant plugin to manage VMs in Libvirt. DESC config('libvirt', :provider) do diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 5e0b91b..b42d6bb 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -117,7 +117,7 @@ <% if d[:serial] %> <%= d[:serial] %> <% end %> -<%# this will get auto generated by libvirt +<%# this will get auto generated by Libvirt
-%> diff --git a/lib/vagrant-libvirt/util/network_util.rb b/lib/vagrant-libvirt/util/network_util.rb index 610bbbf..ae40f7a 100644 --- a/lib/vagrant-libvirt/util/network_util.rb +++ b/lib/vagrant-libvirt/util/network_util.rb @@ -109,7 +109,7 @@ module VagrantPlugins networks end - # Return a list of all (active and inactive) libvirt networks as a list + # Return a list of all (active and inactive) Libvirt networks as a list # of hashes with their name, network address and status (active or not) def libvirt_networks(libvirt_client) libvirt_networks = [] diff --git a/locales/en.yml b/locales/en.yml index 9a10809..2a59768 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -16,7 +16,7 @@ en: 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... + Uploading base box image as volume into Libvirt storage... creating_domain_volume: |- Creating image (snapshot of base box volume). removing_domain_volume: |- @@ -60,7 +60,7 @@ en: Forwarding UDP ports is not supported. Ignoring. errors: - package_not_supported: No support for package with libvirt. Create box manually. + package_not_supported: No support for package with Libvirt. Create box manually. fog_error: |- There was an error talking to Libvirt. The error message is shown below: @@ -97,7 +97,7 @@ en: wrong_box_format: |- Wrong image format specified for box. fog_libvirt_connection_error: |- - Error while connecting to libvirt: %{error_message} + Error while connecting to Libvirt: %{error_message} fog_create_volume_error: |- Error while creating a storage pool volume: %{error_message} fog_create_domain_volume_error: |- @@ -108,9 +108,9 @@ en: Name `%{domain_name}` of domain about to create is already taken. Please try to run `vagrant up` command again. creating_storage_pool_error: |- - There was error while creating libvirt storage pool: %{error_message} + There was error while creating Libvirt storage pool: %{error_message} creating_volume_error: |- - There was error while creating libvirt volume: %{error_message} + There was error while creating Libvirt volume: %{error_message} image_upload_error: |- Error while uploading image to storage pool: %{error_message} no_domain_error: |- diff --git a/tools/prepare_redhat_for_box.sh b/tools/prepare_redhat_for_box.sh index 68a6261..4a98249 100755 --- a/tools/prepare_redhat_for_box.sh +++ b/tools/prepare_redhat_for_box.sh @@ -1,6 +1,6 @@ #!/bin/bash +x -# This script should help to prepare RedHat and RedHat like OS (CentOS, +# This script should help to prepare Red Hat and Red Hat-like OS (CentOS, # Scientific Linux, ...) for Vagrant box usage. # To create new box image, just install minimal base system in VM on top of not @@ -18,13 +18,13 @@ if [ $# -ne 1 ]; then fi -# On which version of RedHet are we running? +# On which version of Red Hat are we running? RHEL_MAJOR_VERSION=$(sed 's/.*release \([0-9]\)\..*/\1/' /etc/redhat-release) if [ $? -ne 0 ]; then - echo "Is this a RedHat distro?" + echo "Is this a Red Hat distro?" exit 1 fi -echo "* Found RedHat ${RHEL_MAJOR_VERSION} version." +echo "* Found Red Hat ${RHEL_MAJOR_VERSION} version." # Setup hostname vagrant-something. From abc2c65b040637f59eaa141b97b39496149d615e Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Wed, 13 Feb 2019 12:56:29 +0000 Subject: [PATCH 12/28] Handle rubygems >= 3 dropping support for ruby < 2.3.0 Rubygems releases >= 3 have removed support for older versions of ruby (<2.3). While testing with distributions with older versions of ruby make sure to use the conservative install method as suggested from https://github.com/rubygems/rubygems/issues/2534#issuecomment-448843746 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0a848a7..cac21e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ dist: trusty before_install: - sudo apt-get update -qq - sudo apt-get install -y libvirt-dev - - gem update --system - - gem install bundler + - gem update --system --conservative || (gem i "rubygems-update:~>2.7" --no-document && update_rubygems) + - gem update bundler --conservative install: bundle install script: bundle exec rspec --color --format documentation notifications: From d3a2f8ad97b764a2cbf402ed0c57e4e77bedd09a Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Wed, 13 Feb 2019 13:29:23 +0000 Subject: [PATCH 13/28] Update travis conf and test multiple combinations Attempt to use latest travis CI settings for installing required packages. Should attempt to test various combinations to try and catch problems occurring across different versions of vagrant with different versions of ruby when people are using distro provided versions. --- .travis.yml | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index cac21e5..0cd7f0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,35 @@ --- language: ruby -dist: trusty +dist: xenial before_install: - - sudo apt-get update -qq - - sudo apt-get install -y libvirt-dev - gem update --system --conservative || (gem i "rubygems-update:~>2.7" --no-document && update_rubygems) - gem update bundler --conservative +addons: + apt: + packages: libvirt-dev + update: true install: bundle install script: bundle exec rspec --color --format documentation notifications: email: false -rvm: - - 2.2.5 - - 2.3.3 env: global: - NOKOGIRI_USE_SYSTEM_LIBRARIES=true matrix: - - VAGRANT_VERSION=v2.0.1 + - VAGRANT_VERSION=v2.0.4 + - VAGRANT_VERSION=v2.1.5 + - VAGRANT_VERSION=v2.2.3 +rvm: + - 2.2.7 + - 2.3.4 + - 2.4.1 + - 2.6.1 + matrix: allow_failures: - env: VAGRANT_VERSION=master - rvm: 2.3.3 + exclude: + - env: VAGRANT_VERSION=v2.0.4 + rvm: 2.6.1 + - env: VAGRANT_VERSION=v2.1.5 + rvm: 2.6.1 From 429b2360876c4931d17e84ba44916fcd2a13fae8 Mon Sep 17 00:00:00 2001 From: James Conroy-Finn Date: Thu, 27 Apr 2017 13:51:28 +0100 Subject: [PATCH 14/28] Use the same version of Nokogiri as Vagrant --- vagrant-libvirt.gemspec | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vagrant-libvirt.gemspec b/vagrant-libvirt.gemspec index dabb5f0..4f6ad31 100644 --- a/vagrant-libvirt.gemspec +++ b/vagrant-libvirt.gemspec @@ -21,8 +21,10 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec-mocks", "~> 3.5.0" s.add_runtime_dependency 'fog-libvirt', '>= 0.3.0' - s.add_runtime_dependency 'nokogiri', '~> 1.6.0' s.add_runtime_dependency 'fog-core', '~> 1.43.0' + # Make sure to allow use of the same version as Vagrant by being less specific + s.add_runtime_dependency 'nokogiri', '~> 1.6' + s.add_development_dependency 'rake' end From 53539f6ad4f434f55145cb83f68b5c553b08f165 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Sat, 10 Nov 2018 12:16:17 +0100 Subject: [PATCH 15/28] add domain name for the management network this allows users to have a dedicated domain for their vagrant VMs and point their regular resolver at the libvirt dnsmasq for that domain to make them reachable by a full name instead of the IP when accessing the services on said VM. an example for such a setup can be found in [1] and [2] [1] https://liquidat.wordpress.com/2017/03/03/howto-automated-dns-resolution-for-kvmlibvirt-guests-with-a-local-domain/ [2] https://m0dlx.com/blog/Automatic_DNS_updates_from_libvirt_guests.html --- README.md | 5 +++-- lib/vagrant-libvirt/config.rb | 3 +++ lib/vagrant-libvirt/util/network_util.rb | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a4b426..0e30792 100644 --- a/README.md +++ b/README.md @@ -699,9 +699,10 @@ used by this network are configurable at the provider level. for for more information. * `management_network_autostart` - Automatic startup of mgmt network, if not specified the default is 'false'. -* `:management_network_pci_bus` - The bus of the PCI device. -* `:management_network_pci_slot` - The slot of the PCI device. +* `management_network_pci_bus` - The bus of the PCI device. +* `management_network_pci_slot` - The slot of the PCI device. * `management_network_mac` - MAC address of management network interface. +* `management_network_domain` - Domain name assigned to the management network. You may wonder how vagrant-libvirt knows the IP address a VM received. Libvirt doesn't provide a standard way to find out the IP address of a running domain. diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 8f1ac5a..baca798 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -58,6 +58,7 @@ module VagrantPlugins attr_accessor :management_network_autostart attr_accessor :management_network_pci_bus attr_accessor :management_network_pci_slot + attr_accessor :management_network_domain # System connection information attr_accessor :system_uri @@ -184,6 +185,7 @@ module VagrantPlugins @management_network_autostart = UNSET_VALUE @management_network_pci_slot = UNSET_VALUE @management_network_pci_bus = UNSET_VALUE + @management_network_domain = UNSET_VALUE # System connection information @system_uri = UNSET_VALUE @@ -654,6 +656,7 @@ module VagrantPlugins @management_network_autostart = false if @management_network_autostart == UNSET_VALUE @management_network_pci_bus = nil if @management_network_pci_bus == UNSET_VALUE @management_network_pci_slot = nil if @management_network_pci_slot == UNSET_VALUE + @management_network_domain = nil if @management_network_domain == UNSET_VALUE @system_uri = 'qemu:///system' if @system_uri == UNSET_VALUE @qemu_use_session = false if @qemu_use_session == UNSET_VALUE diff --git a/lib/vagrant-libvirt/util/network_util.rb b/lib/vagrant-libvirt/util/network_util.rb index ae40f7a..ea71cb1 100644 --- a/lib/vagrant-libvirt/util/network_util.rb +++ b/lib/vagrant-libvirt/util/network_util.rb @@ -18,6 +18,7 @@ module VagrantPlugins management_network_autostart = env[:machine].provider_config.management_network_autostart management_network_pci_bus = env[:machine].provider_config.management_network_pci_bus management_network_pci_slot = env[:machine].provider_config.management_network_pci_slot + management_network_domain = env[:machine].provider_config.management_network_domain logger.info "Using #{management_network_name} at #{management_network_address} as the management network #{management_network_mode} is the mode" begin @@ -65,6 +66,10 @@ module VagrantPlugins management_network_options[:mac] = management_network_mac end + unless management_network_domain.nil? + management_network_options[:domain_name] = management_network_domain + end + unless management_network_pci_bus.nil? and management_network_pci_slot.nil? management_network_options[:bus] = management_network_pci_bus management_network_options[:slot] = management_network_pci_slot From e40f1c67b4a0d52dead7f9eac0727ec5b8668a39 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Wed, 13 Feb 2019 16:52:20 +0000 Subject: [PATCH 16/28] Default to storage pool if snapshot pool not defined Default to using the same storage pool in case the user defines storage_pool_name without defining snapshot_pool_name and only use a separate pool when snapshot_pool_name is explicitly set. This will ensure that setting storage_pool_name to a different pool does not also require setting snapshot_pool_name to match previous behaviour. Additionally it is reasonable for a user to assume that if a Vagrantfile sets storage_pool_name to something other than 'default', then there should be no need for a default pool. --- lib/vagrant-libvirt/action/create_domain.rb | 2 +- lib/vagrant-libvirt/action/create_domain_volume.rb | 2 +- lib/vagrant-libvirt/config.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 74a4f49..9bac763 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -120,7 +120,7 @@ module VagrantPlugins # Get path to domain image from the storage pool selected if we have a box. if env[:machine].config.vm.box - if @snapshot_pool_name != 'default' + if @snapshot_pool_name != @storage_pool_name pool_name = @snapshot_pool_name else pool_name = @storage_pool_name diff --git a/lib/vagrant-libvirt/action/create_domain_volume.rb b/lib/vagrant-libvirt/action/create_domain_volume.rb index 360d6a6..6d41c7b 100644 --- a/lib/vagrant-libvirt/action/create_domain_volume.rb +++ b/lib/vagrant-libvirt/action/create_domain_volume.rb @@ -71,7 +71,7 @@ module VagrantPlugins Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS | Nokogiri::XML::Node::SaveOptions::FORMAT ) - if config.snapshot_pool_name != 'default' + if config.snapshot_pool_name != config.storage_pool_name pool_name = config.snapshot_pool_name else pool_name = config.storage_pool_name diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 2aa1bce..08810c5 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -642,7 +642,7 @@ module VagrantPlugins @password = nil if @password == UNSET_VALUE @id_ssh_key_file = 'id_rsa' if @id_ssh_key_file == UNSET_VALUE @storage_pool_name = 'default' if @storage_pool_name == UNSET_VALUE - @snapshot_pool_name = 'default' if @snapshot_pool_name == UNSET_VALUE + @snapshot_pool_name = @storage_pool_name if @snapshot_pool_name == UNSET_VALUE @storage_pool_path = nil if @storage_pool_path == UNSET_VALUE @random_hostname = false if @random_hostname == UNSET_VALUE @management_network_device = 'virbr0' if @management_network_device == UNSET_VALUE From 44a760f6682767cc1d01285ac008cc554080006d Mon Sep 17 00:00:00 2001 From: Pirate Praveen Arimbrathodiyil Date: Thu, 7 Feb 2019 20:57:20 +0530 Subject: [PATCH 17/28] Update fog-core to latest version fog-core 2.x is released and we'd like to use it in debian --- vagrant-libvirt.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vagrant-libvirt.gemspec b/vagrant-libvirt.gemspec index 4f6ad31..b1e97a7 100644 --- a/vagrant-libvirt.gemspec +++ b/vagrant-libvirt.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec-mocks", "~> 3.5.0" s.add_runtime_dependency 'fog-libvirt', '>= 0.3.0' - s.add_runtime_dependency 'fog-core', '~> 1.43.0' + s.add_runtime_dependency 'fog-core', '~> 2.1' # Make sure to allow use of the same version as Vagrant by being less specific s.add_runtime_dependency 'nokogiri', '~> 1.6' From deb36bef8b6c0b696ea0045563fb5cc0e4895f73 Mon Sep 17 00:00:00 2001 From: "Zak B. Elep" Date: Wed, 27 Feb 2019 20:32:37 +0800 Subject: [PATCH 18/28] Allow customizing of virt-sysprep behaviour on package (#955) Support `vagrant package` of e.g. bento-derived boxes that require SSH hostkeys already set (as in the case of bento/debian-7 and above,) as well as leave existing LVM UUIDs untouched (e.g. in bento/ubuntu-18.04.) Instead of hard-coding sysprep operations, use an environment variable to set these instead. Use the Chef bento use case as an example for customizing sysprep operations. --- README.md | 23 ++++++++++++++++++++ lib/vagrant-libvirt/action/package_domain.rb | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e30792..82646bd 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ can help a lot :-) - [Customized Graphics](#customized-graphics) - [Box Format](#box-format) - [Create Box](#create-box) +- [Package Box from VM](#package-box-from-vm) - [Development](#development) - [Contributing](#contributing) @@ -1420,6 +1421,28 @@ $ cd packer-qemu-templates $ packer build ubuntu-14.04-server-amd64-vagrant.json ``` +## Package Box from VM + +vagrant-libvirt has native support for [`vagrant +package`](https://www.vagrantup.com/docs/cli/package.html) via +libguestfs [virt-sysprep](http://libguestfs.org/virt-sysprep.1.html). +virt-sysprep operations can be customized via the +`VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS` environment variable; see the +[upstream +documentation](http://libguestfs.org/virt-sysprep.1.html#operations) for +further details especially on default sysprep operations enabled for +your system. + +For example, on Chef [bento](https://github.com/chef/bento) VMs that +require SSH hostkeys already set (e.g. bento/debian-7) as well as leave +existing LVM UUIDs untouched (e.g. bento/ubuntu-18.04), these can be +packaged into vagrant-libvirt boxes like so: + +```shell +$ export VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS="defaults,-ssh-userdir,-ssh-hostkeys,-lvm-uuids" +$ vagrant package +``` + ## Development To work on the `vagrant-libvirt` plugin, clone this repository out, and use diff --git a/lib/vagrant-libvirt/action/package_domain.rb b/lib/vagrant-libvirt/action/package_domain.rb index 84e25ba..740c79e 100644 --- a/lib/vagrant-libvirt/action/package_domain.rb +++ b/lib/vagrant-libvirt/action/package_domain.rb @@ -38,7 +38,8 @@ 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 --operations defaults,-ssh-userdir -a #{@tmp_img}` + operations = ENV.get('VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS', 'defaults,-ssh-userdir') + `virt-sysprep --no-logfile --operations #{operations} -a #{@tmp_img}` # add any user provided file extra = '' @tmp_include = @tmp_dir + '/_include' From 8f314cbb0e781b9ee883985ab25dd5953097f951 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Wed, 6 Mar 2019 11:27:25 +0000 Subject: [PATCH 19/28] Fail on port collisions Partial Fix #321 by enabling option ExitOnForwardFailure=yes to detect and fail on forward port mappings failing to bind. --- lib/vagrant-libvirt/action/forward_ports.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/vagrant-libvirt/action/forward_ports.rb b/lib/vagrant-libvirt/action/forward_ports.rb index e48a6f4..c7c747e 100644 --- a/lib/vagrant-libvirt/action/forward_ports.rb +++ b/lib/vagrant-libvirt/action/forward_ports.rb @@ -97,6 +97,7 @@ module VagrantPlugins User=#{ssh_info[:username]} Port=#{ssh_info[:port]} UserKnownHostsFile=/dev/null + ExitOnForwardFailure=yes StrictHostKeyChecking=no PasswordAuthentication=no ForwardX11=#{ssh_info[:forward_x11] ? 'yes' : 'no'} From 222b50925d967facab4a44bc4854b5f3322161e2 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 13 Mar 2019 20:49:11 +1100 Subject: [PATCH 20/28] Avoid TOCTOU error in volume creation Checking if a volume exists before attempting to create it results in a "time of check to time of use" race. When the check is done the volume doesn't exist but then, because it is shared storage, it is then created by another node before the local attempt to create it. This results in an unexpected failure. It is better to simply attempt to create the volume and ignore EEXIST in cases where this is permissible. Implementing this properly is complicated by the fact that the exception appears to contain only an error message and does not appear to contain a useful error code. Digging through the layers in, for example, fog-libvirt provides no evidence why this is so. However, the error message seems fairly unique and matching it is easy, so just do that. A small hack to vastly improve stability. Signed-off-by: Martin Schwenke --- lib/vagrant-libvirt/action/create_domain.rb | 36 +++++++++++---------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 1862237..ba5c8d2 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -162,26 +162,28 @@ module VagrantPlugins disk[:absolute_path] = storage_prefix + disk[:path] - if env[:machine].provider.driver.connection.volumes.select do |x| - x.name == disk[:name] && x.pool_name == @storage_pool_name - end.empty? - # make the disk. equivalent to: - # qemu-img create -f qcow2 5g - begin - env[:machine].provider.driver.connection.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 + # make the disk. equivalent to: + # qemu-img create -f qcow2 5g + begin + env[:machine].provider.driver.connection.volumes.create( + name: disk[:name], + format_type: disk[:type], + path: disk[:absolute_path], + capacity: disk[:size], + #:allocation => ?, + pool_name: @storage_pool_name + ) + rescue Libvirt::Error => e + # It is hard to believe that e contains just a string + # and no useful error code! + msg = "Call to virStorageVolCreateXML failed: " + + "storage volume '#{disk[:path]}' exists already" + if e.message == msg and disk[:allow_existing] + disk[:preexisting] = true + else raise Errors::FogDomainVolumeCreateError, error_message: e.message end - else - disk[:preexisting] = true end end From 2f41402c9abbf3b5efee66d67290ad2e229d8f05 Mon Sep 17 00:00:00 2001 From: Vratislav Podzimek Date: Thu, 9 May 2019 13:27:04 +0200 Subject: [PATCH 21/28] Use parallel gzip in box creation if available This can speed up box creation significantly on modern machines. --- tools/create_box.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/create_box.sh b/tools/create_box.sh index 3a975a8..201d1d4 100755 --- a/tools/create_box.sh +++ b/tools/create_box.sh @@ -118,7 +118,12 @@ EOF echo "==> Creating box, tarring and gzipping" -tar cvzf "$BOX" -S --totals ./metadata.json ./Vagrantfile ./box.img +if type pigz >/dev/null 2>/dev/null; then + GZ="pigz" +else + GZ="gzip" +fi +tar cv -S --totals ./metadata.json ./Vagrantfile ./box.img | $GZ -c > "$BOX" # if box is in tmpdir move it to CWD before removing tmpdir if ! isabspath "$BOX"; then From 3f30606021444ac922c398e1737e09be4fe8fcfd Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Mon, 1 Jul 2019 10:43:21 +0100 Subject: [PATCH 22/28] Update versions tested in README (#1006) --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 82646bd..75cd1da 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,12 @@ KVM type virtual machines with `virsh` or `virt-manager`. Next, you must have [Vagrant installed](http://docs.vagrantup.com/v2/installation/index.html). -Vagrant-libvirt supports Vagrant 1.5, 1.6, 1.7 and 1.8. +Vagrant-libvirt supports Vagrant 2.0, 2.1 & 2.2. It should also work with earlier +releases from 1.5 onwards but they are not actively tested. + +Check the [.travis.yml](https://github.com/vagrant-libvirt/vagrant-libvirt/blob/master/.travis.yml) +for the current list of tested versions. + *We only test with the upstream version!* If you decide to install your distro's version and you run into problems, as a first step you should switch to upstream. From e45f6a5110ff4808a7f2306d244f8998c9302714 Mon Sep 17 00:00:00 2001 From: Dario Maiocchi Date: Fri, 5 Jul 2019 13:46:53 +0200 Subject: [PATCH 23/28] Update readme with openSUSE installation Update readme with openSUSE installation --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 75cd1da..a339203 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,11 @@ yum install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm dnf -y install qemu libvirt libvirt-devel ruby-devel gcc ``` +* OpenSUSE leap 15.1: +```shell +zypper install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm +``` + * Arch Linux: please read the related [ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt) page. ```shell pacman -S vagrant From 608037c15c099161ba3354d5083c4dcb99405fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Wed, 17 Jul 2019 17:43:35 +0200 Subject: [PATCH 24/28] Use fog-libvirt facilities to create volumes for QEMU session. This is supported since fog-libvirt 0.6.0 via https://github.com/fog/fog-libvirt/pull/60 --- .../action/handle_box_image.rb | 67 ++++--------------- lib/vagrant-libvirt/errors.rb | 4 -- .../templates/default_storage_volume.xml.erb | 14 ---- locales/en.yml | 2 - vagrant-libvirt.gemspec | 2 +- 5 files changed, 15 insertions(+), 74 deletions(-) delete mode 100644 lib/vagrant-libvirt/templates/default_storage_volume.xml.erb diff --git a/lib/vagrant-libvirt/action/handle_box_image.rb b/lib/vagrant-libvirt/action/handle_box_image.rb index 3a97356..93256aa 100644 --- a/lib/vagrant-libvirt/action/handle_box_image.rb +++ b/lib/vagrant-libvirt/action/handle_box_image.rb @@ -4,7 +4,6 @@ module VagrantPlugins module ProviderLibvirt module Action class HandleBoxImage - include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate include VagrantPlugins::ProviderLibvirt::Util::StorageUtil @@ -81,40 +80,19 @@ module VagrantPlugins message << " in storage pool #{config.storage_pool_name}." @logger.info(message) - if config.qemu_use_session - begin - @name = env[:box_volume_name] - @allocation = "#{box_image_size / 1024 / 1024}M" - @capacity = "#{box_virtual_size}G" - @format_type = box_format ? box_format : 'raw' - - @storage_volume_uid = storage_uid env - @storage_volume_gid = storage_gid env - - libvirt_client = env[:machine].provider.driver.connection.client - libvirt_pool = libvirt_client.lookup_storage_pool_by_name( - config.storage_pool_name - ) - libvirt_volume = libvirt_pool.create_volume_xml( - to_xml('default_storage_volume') - ) - rescue => e - raise Errors::CreatingVolumeError, - error_message: e.message - end - else - begin - fog_volume = env[:machine].provider.driver.connection.volumes.create( - name: env[:box_volume_name], - allocation: "#{box_image_size / 1024 / 1024}M", - capacity: "#{box_virtual_size}G", - format_type: box_format, - pool_name: config.storage_pool_name - ) - rescue Fog::Errors::Error => e - raise Errors::FogCreateVolumeError, - error_message: e.message - end + begin + fog_volume = env[:machine].provider.driver.connection.volumes.create( + name: env[:box_volume_name], + allocation: "#{box_image_size / 1024 / 1024}M", + capacity: "#{box_virtual_size}G", + format_type: box_format, + owner: storage_uid env, + group: storage_gid env, + pool_name: config.storage_pool_name + ) + rescue Fog::Errors::Error => e + raise Errors::FogCreateVolumeError, + error_message: e.message end # Upload box image to storage pool @@ -132,11 +110,7 @@ module VagrantPlugins # storage pool. if env[:interrupted] || !ret begin - if config.qemu_use_session - libvirt_volume.delete - else - fog_volume.destroy - end + fog_volume.destroy rescue nil end @@ -146,19 +120,6 @@ module VagrantPlugins @app.call(env) end - def split_size_unit(text) - if text.kind_of? Integer - # if text is an integer, match will fail - size = text - unit = 'G' - else - matcher = text.match(/(\d+)(.+)/) - size = matcher[1] - unit = matcher[2] - end - [size, unit] - end - protected # Fog Libvirt currently doesn't support uploading images to storage diff --git a/lib/vagrant-libvirt/errors.rb b/lib/vagrant-libvirt/errors.rb index 5023ce2..0bb3c3a 100644 --- a/lib/vagrant-libvirt/errors.rb +++ b/lib/vagrant-libvirt/errors.rb @@ -29,10 +29,6 @@ module VagrantPlugins error_key(:creating_storage_pool_error) end - class CreatingVolumeError < VagrantLibvirtError - error_key(:creating_volume_error) - end - class ImageUploadError < VagrantLibvirtError error_key(:image_upload_error) end diff --git a/lib/vagrant-libvirt/templates/default_storage_volume.xml.erb b/lib/vagrant-libvirt/templates/default_storage_volume.xml.erb deleted file mode 100644 index c4b2268..0000000 --- a/lib/vagrant-libvirt/templates/default_storage_volume.xml.erb +++ /dev/null @@ -1,14 +0,0 @@ - - <%= @name %> - <%= split_size_unit(@allocation)[0] %> - <%= split_size_unit(@capacity)[0] %> - - - - <%= @storage_volume_uid %> - <%= @storage_volume_gid %> - 0744 - - - - diff --git a/locales/en.yml b/locales/en.yml index 2a59768..08a4c71 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -109,8 +109,6 @@ en: `vagrant up` command again. creating_storage_pool_error: |- There was error while creating Libvirt storage pool: %{error_message} - creating_volume_error: |- - There was error while creating Libvirt volume: %{error_message} image_upload_error: |- Error while uploading image to storage pool: %{error_message} no_domain_error: |- diff --git a/vagrant-libvirt.gemspec b/vagrant-libvirt.gemspec index b1e97a7..6d08374 100644 --- a/vagrant-libvirt.gemspec +++ b/vagrant-libvirt.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec-expectations", "~> 3.5.0" s.add_development_dependency "rspec-mocks", "~> 3.5.0" - s.add_runtime_dependency 'fog-libvirt', '>= 0.3.0' + s.add_runtime_dependency 'fog-libvirt', '>= 0.6.0' s.add_runtime_dependency 'fog-core', '~> 2.1' # Make sure to allow use of the same version as Vagrant by being less specific From f8eae9984d7f9f0bcc83fa3082592968487c0fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Tue, 13 Aug 2019 13:06:19 +0200 Subject: [PATCH 25/28] Use fetch to obtain environment variable value in package_domain (#1035) ENV is a Ruby Hash which doesn't have a get method but the fetch method. --- 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 740c79e..c767fce 100644 --- a/lib/vagrant-libvirt/action/package_domain.rb +++ b/lib/vagrant-libvirt/action/package_domain.rb @@ -38,7 +38,7 @@ module VagrantPlugins `qemu-img rebase -p -b "" #{@tmp_img}` # remove hw association with interface # working for centos with lvs default disks - operations = ENV.get('VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS', 'defaults,-ssh-userdir') + operations = ENV.fetch('VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS', 'defaults,-ssh-userdir') `virt-sysprep --no-logfile --operations #{operations} -a #{@tmp_img}` # add any user provided file extra = '' From 330b0f83cdc7695cdf2fb95a466e3573d2ee65be Mon Sep 17 00:00:00 2001 From: Katherine Pata Date: Fri, 30 Aug 2019 11:02:16 +0200 Subject: [PATCH 26/28] Added more details on how to use vagrant-libvirt with QEMU user sessions --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a339203..933f043 100644 --- a/README.md +++ b/README.md @@ -1241,7 +1241,14 @@ public network interface and you must connect to Libvirt via ssh. ## QEMU Session Support -vagrant-libvirt supports using the QEMU session connection to maintain Vagrant VMs. As the session connection does not have root access to the system features which require root will not work. Access to networks created by the system QEMU connection can be granted by using the [QEMU bridge helper](https://wiki.qemu.org/Features/HelperNetworking). The bridge helper is enabled by default on some distros but may need to be enabled/installed on others. +vagrant-libvirt supports using QEMU user sessions to maintain Vagrant VMs. As the session connection does not have root access to the system features which require root will not work. Access to networks created by the system QEMU connection can be granted by using the [QEMU bridge helper](https://wiki.qemu.org/Features/HelperNetworking). The bridge helper is enabled by default on some distros but may need to be enabled/installed on others. + +There must be a virbr network defined in the QEMU system session. The libvirt `default` network which comes by default, the vagrant `vagrant-libvirt` network which is generated if you run a Vagrantfile using the System session, or a manually defined network can be used. These networks can be set to autostart with `sudo virsh net-autostart `, which'll mean no further root access is required even after reboots. + +The QEMU bridge helper is configured via `/etc/qemu/bridge.conf`. This file must include the virbr you wish to use (e.g. virbr0, virbr1, etc). You can find this out via `sudo virsh net-dumpxml `. +``` +allow virbr0 +``` An example configuration of a machine using the QEMU session connection: @@ -1252,11 +1259,11 @@ Vagrant.configure("2") do |config| libvirt.qemu_use_session = true # URI of QEMU session connection, default is as below libvirt.uri = 'qemu:///session' - # URI of QEMU system connection, use to obtain IP address for management + # URI of QEMU system connection, use to obtain IP address for management, default is below libvirt.system_uri = 'qemu:///system' # Path to store Libvirt images for the virtual machine, default is as ~/.local/share/libvirt/images libvirt.storage_pool_path = '/home/user/.local/share/libvirt/images' - # Management network device + # Management network device, default is below libvirt.management_network_device = 'virbr0' end From 1739809a129484398bddfcc2578fc3a600c2dbdc Mon Sep 17 00:00:00 2001 From: Jeff Welling Date: Thu, 10 Oct 2019 12:39:58 -0700 Subject: [PATCH 27/28] Update readme doc howto troubleshoot (#1052) Note common troubleshooting tools/steps in README --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index a339203..0a02024 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ can help a lot :-) - [Box Format](#box-format) - [Create Box](#create-box) - [Package Box from VM](#package-box-from-vm) +- [Troubleshooting VMs](#troubleshooting-vms) - [Development](#development) - [Contributing](#contributing) @@ -1453,6 +1454,43 @@ $ export VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS="defaults,-ssh-userdir,-ssh-hos $ vagrant package ``` +## Troubleshooting VMs + +The first step for troubleshooting a VM image that appears to not boot correctly, +or hangs waiting to get an IP, is to check it with a VNC viewer. A key thing +to remember is that if the VM doesn't get an IP, then vagrant can't communicate +with it to configure anything, so a problem at this stage is likely to come from +the VM, but we'll outline the tools and common problems to help you troubleshoot +that. + +By default, when you create a new VM, a vnc server will listen on `127.0.0.1` on +port `TCP5900`. If you connect with a vnc viewer you can see the boot process. If +your VM isn't listening on `5900` by default, you can use `virsh dumpxml` to find +out which port it's listening on, or can configure it with `graphics_port` and +`graphics_ip` (see 'Domain Specific Options' above). + +Note: Connecting with the console (`virsh console`) requires additional config, +so some VMs may not show anything on the console at all, instead displaying it in +the VNC console. The issue with the text console is that you also need to build the +image used to tell the kernel to output to the console during boot, and typically +most do not have this built in. + +Problems we've seen in the past include: +- Forgetting to remove `/etc/udev/rules.d/70-persistent-net.rules` before packaging +the VM +- VMs expecting a specific disk device to be connected + +If you're still confused, check the Github Issues for this repo for anything that +looks similar to your problem. + +[Github Issue #1032](https://github.com/vagrant-libvirt/vagrant-libvirt/issues/1032) +contains some historical troubleshooting for VMs that appeared +to hang. + +Did you hit a problem that you'd like to note here to save time in the future? +Please do! + + ## Development To work on the `vagrant-libvirt` plugin, clone this repository out, and use From 2947a1d52cbe8ee9e397f846fbce532e0d2975d1 Mon Sep 17 00:00:00 2001 From: Vadym Haidamaka Date: Sun, 20 Oct 2019 15:35:44 +0300 Subject: [PATCH 28/28] docs: update build dependencies for newer Debian-based distros See https://lists.debian.org/debian-user/2016/11/msg00518.html --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a02024..2d8ba82 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,14 @@ version and you run into problems, as a first step you should switch to upstream Now you need to make sure your have all the build dependencies installed for vagrant-libvirt. This depends on your distro. An overview: -* Ubuntu, Debian: +* Ubuntu 18.10, Debian 9 and up: +```shell +apt-get build-dep vagrant ruby-libvirt +apt-get install qemu libvirt-daemon-system libvirt-clients ebtables dnsmasq-base +apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev +``` + +* Ubuntu 18.04, Debian 8 and older: ```shell apt-get build-dep vagrant ruby-libvirt apt-get install qemu libvirt-bin ebtables dnsmasq-base