vagrant-libvirt 0.0.41 → 0.0.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.github/issue_template.md +37 -0
  4. data/.gitignore +21 -0
  5. data/.travis.yml +24 -0
  6. data/Gemfile +26 -0
  7. data/LICENSE +22 -0
  8. data/README.md +1380 -0
  9. data/Rakefile +8 -0
  10. data/example_box/README.md +29 -0
  11. data/example_box/Vagrantfile +60 -0
  12. data/example_box/metadata.json +5 -0
  13. data/lib/vagrant-libvirt.rb +29 -0
  14. data/lib/vagrant-libvirt/action.rb +370 -0
  15. data/lib/vagrant-libvirt/action/create_domain.rb +322 -0
  16. data/lib/vagrant-libvirt/action/create_domain_volume.rb +87 -0
  17. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +302 -0
  18. data/lib/vagrant-libvirt/action/create_networks.rb +361 -0
  19. data/lib/vagrant-libvirt/action/destroy_domain.rb +83 -0
  20. data/lib/vagrant-libvirt/action/destroy_networks.rb +95 -0
  21. data/lib/vagrant-libvirt/action/forward_ports.rb +227 -0
  22. data/lib/vagrant-libvirt/action/halt_domain.rb +41 -0
  23. data/lib/vagrant-libvirt/action/handle_box_image.rb +156 -0
  24. data/lib/vagrant-libvirt/action/handle_storage_pool.rb +57 -0
  25. data/lib/vagrant-libvirt/action/is_created.rb +18 -0
  26. data/lib/vagrant-libvirt/action/is_running.rb +21 -0
  27. data/lib/vagrant-libvirt/action/is_suspended.rb +42 -0
  28. data/lib/vagrant-libvirt/action/message_already_created.rb +16 -0
  29. data/lib/vagrant-libvirt/action/message_not_created.rb +16 -0
  30. data/lib/vagrant-libvirt/action/message_not_running.rb +16 -0
  31. data/lib/vagrant-libvirt/action/message_not_suspended.rb +16 -0
  32. data/lib/vagrant-libvirt/action/message_will_not_destroy.rb +17 -0
  33. data/lib/vagrant-libvirt/action/package_domain.rb +105 -0
  34. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +94 -0
  35. data/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb +17 -0
  36. data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +27 -0
  37. data/lib/vagrant-libvirt/action/read_mac_addresses.rb +40 -0
  38. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +20 -0
  39. data/lib/vagrant-libvirt/action/remove_stale_volume.rb +50 -0
  40. data/lib/vagrant-libvirt/action/resume_domain.rb +34 -0
  41. data/lib/vagrant-libvirt/action/set_boot_order.rb +109 -0
  42. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +64 -0
  43. data/lib/vagrant-libvirt/action/share_folders.rb +71 -0
  44. data/lib/vagrant-libvirt/action/start_domain.rb +307 -0
  45. data/lib/vagrant-libvirt/action/suspend_domain.rb +40 -0
  46. data/lib/vagrant-libvirt/action/wait_till_up.rb +109 -0
  47. data/lib/vagrant-libvirt/cap/mount_p9.rb +42 -0
  48. data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +17 -0
  49. data/lib/vagrant-libvirt/cap/synced_folder.rb +113 -0
  50. data/lib/vagrant-libvirt/config.rb +746 -0
  51. data/lib/vagrant-libvirt/driver.rb +118 -0
  52. data/lib/vagrant-libvirt/errors.rb +153 -0
  53. data/lib/vagrant-libvirt/plugin.rb +92 -0
  54. data/lib/vagrant-libvirt/provider.rb +130 -0
  55. data/lib/vagrant-libvirt/templates/default_storage_pool.xml.erb +13 -0
  56. data/lib/vagrant-libvirt/templates/domain.xml.erb +244 -0
  57. data/lib/vagrant-libvirt/templates/private_network.xml.erb +42 -0
  58. data/lib/vagrant-libvirt/templates/public_interface.xml.erb +26 -0
  59. data/lib/vagrant-libvirt/util.rb +11 -0
  60. data/lib/vagrant-libvirt/util/collection.rb +19 -0
  61. data/lib/vagrant-libvirt/util/erb_template.rb +22 -0
  62. data/lib/vagrant-libvirt/util/error_codes.rb +100 -0
  63. data/lib/vagrant-libvirt/util/network_util.rb +151 -0
  64. data/lib/vagrant-libvirt/util/timer.rb +17 -0
  65. data/lib/vagrant-libvirt/version.rb +5 -0
  66. data/locales/en.yml +162 -0
  67. data/spec/spec_helper.rb +9 -0
  68. data/spec/support/environment_helper.rb +46 -0
  69. data/spec/support/libvirt_context.rb +30 -0
  70. data/spec/support/sharedcontext.rb +34 -0
  71. data/spec/unit/action/destroy_domain_spec.rb +97 -0
  72. data/spec/unit/action/set_name_of_domain_spec.rb +21 -0
  73. data/spec/unit/action/wait_till_up_spec.rb +127 -0
  74. data/spec/unit/config_spec.rb +113 -0
  75. data/spec/unit/templates/domain_all_settings.xml +137 -0
  76. data/spec/unit/templates/domain_defaults.xml +46 -0
  77. data/spec/unit/templates/domain_spec.rb +84 -0
  78. data/tools/create_box.sh +130 -0
  79. data/tools/prepare_redhat_for_box.sh +119 -0
  80. data/vagrant-libvirt.gemspec +54 -0
  81. metadata +93 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e240e86048a283add145256b06fd6f6e2865d88b
4
- data.tar.gz: 7ed0c6c8ac25944be64c8039bc75197871b33455
3
+ metadata.gz: d032026c991c626b3b48677af7e977cb9ed3092c
4
+ data.tar.gz: 36104f3a0e77326d19665b97ec4854443959914d
5
5
  SHA512:
6
- metadata.gz: e45c2d6bc2dd65249f5853014b9f70c6f8c3c85c29e340cc90ac83c5fba3bf563628cd4e7f3b8e63ec1b5e9d3e05d827e56553b4ea4db43ec2c16fe7c32de3ca
7
- data.tar.gz: cb0f4aa9607189d4881848b52bf83a65abfd6318db5806f86edcf493c39e1ea3955237c0ed8d28b6fc755fe09588541856a993d6b977ac75c5c49d3809258a72
6
+ metadata.gz: b7fdf0aa740282235fe782d72974149b6ebede496e6e8e48554c1625a47f1767e3befd674d3a115b9de2c6a9d0c1bb045e922b767ba7d9fa24176cc96a2fc63f
7
+ data.tar.gz: e0477096ac9324861676ea69cc83ed4ce17146a9f1644fbfeb11facd69a1af83a3a09454334922a58b8d8bb8daa465eb743060655f84a34655f69bdd21873b68
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,37 @@
1
+ <!--
2
+ Thank you for reporting issues to vagrant-libvirt.
3
+
4
+ To make it possible for us to help you quickly, we kindly request that you use the template below to report issues. If the issue you are reporting does not fit the template (a feature request for example) please feel free to adapt it to your needs.
5
+
6
+ Please be aware that we are not actively testing previous versions of both Vagrant and Vagrant-libvirt, so before reporting an issue, please install the latest Vagrant version from Vagrantup.com, run `vagrant plugin update` and reproduce the issue.
7
+ -->
8
+ ### Steps to reproduce
9
+ 1.
10
+ 2.
11
+ 3.
12
+
13
+ ### Expected behaviour
14
+ Tell us what should happen
15
+
16
+ ### Actual behaviour
17
+ Tell us what happens instead
18
+
19
+ ### System configuration
20
+ **OS/Distro version:**:
21
+
22
+ **Libvirt version:**
23
+
24
+ **Output of `vagrant version; vagrant plugin list`:**
25
+
26
+ **Output of `VAGRANT_LOG=debug vagrant ... --provider=libvirt`**
27
+ ```
28
+ Insert debug output inside quotes here (replace ... with whatever command you use to trigger the issue)
29
+ ```
30
+
31
+ **A Vagrantfile to reproduce the issue:**
32
+ ```
33
+ Insert Vagrantfile inside quotes here (remove sensitive data if needed)
34
+ ```
35
+
36
+ **Are you using upstream vagrant package or your distros package?**
37
+ Upstream / Distro
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ Vagrantfile
19
+ !example_box/Vagrantfile
20
+ .vagrant
21
+ *.swp
@@ -0,0 +1,24 @@
1
+ ---
2
+ language: ruby
3
+ dist: trusty
4
+ before_install:
5
+ - sudo apt-get update -qq
6
+ - sudo apt-get install -y libvirt-dev
7
+ - gem update --system
8
+ - gem install bundler
9
+ install: bundle install
10
+ script: bundle exec rspec --color --format documentation
11
+ notifications:
12
+ email: false
13
+ rvm:
14
+ - 2.2.5
15
+ - 2.3.3
16
+ env:
17
+ global:
18
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
19
+ matrix:
20
+ - VAGRANT_VERSION=v2.0.1
21
+ matrix:
22
+ allow_failures:
23
+ - env: VAGRANT_VERSION=master
24
+ rvm: 2.3.3
data/Gemfile ADDED
@@ -0,0 +1,26 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-libvirt.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ # We depend on Vagrant for development, but we don't add it as a
8
+ # gem dependency because we expect to be installed within the
9
+ # Vagrant environment itself using `vagrant plugin`.
10
+ if ENV['VAGRANT_VERSION']
11
+ gem 'vagrant', :git => 'https://github.com/hashicorp/vagrant.git',
12
+ tag: ENV['VAGRANT_VERSION']
13
+ else
14
+ gem 'vagrant', :git => 'https://github.com/hashicorp/vagrant.git'
15
+ end
16
+
17
+ gem 'vagrant-spec', :github => 'hashicorp/vagrant-spec'
18
+
19
+ gem 'pry'
20
+ end
21
+
22
+ group :plugins do
23
+ gemspec
24
+ end
25
+
26
+ gem 'coveralls', require: false
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Lukas Stanek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,1380 @@
1
+ # Vagrant Libvirt Provider
2
+
3
+ [![Join the chat at https://gitter.im/vagrant-libvirt/vagrant-libvirt](https://badges.gitter.im/vagrant-libvirt/vagrant-libvirt.svg)](https://gitter.im/vagrant-libvirt/vagrant-libvirt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+ [![Build Status](https://travis-ci.org/vagrant-libvirt/vagrant-libvirt.svg)](https://travis-ci.org/vagrant-libvirt/vagrant-libvirt)
5
+ [![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)
6
+
7
+ This is a [Vagrant](http://www.vagrantup.com) plugin that adds an
8
+ [Libvirt](http://libvirt.org) provider to Vagrant, allowing Vagrant to
9
+ control and provision machines via Libvirt toolkit.
10
+
11
+ **Note:** Actual version is still a development one. Feedback is welcome and
12
+ can help a lot :-)
13
+
14
+ ## QA status
15
+
16
+ We periodically test basic functionality for vagrant-libvirt on various distributions.
17
+ In the table below, build passing means that specific version combination of Vagrant + Vagrant-libvirt was installed correctly and `vagrant up` is working. Click the badge to see the log.
18
+
19
+ |Vagrant|Vagrant-libvirt|ubuntu-12.04|ubuntu-14.04|ubuntu-16.04|debian-8|debian-9|centos-6|centos-7|fedora-21|fedora-22|fedora-23|fedora-24|arch|
20
+ |---|---|---|---|---|---|---|---|---|---|---|---|---|---|
21
+ |2.0.1|master|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=ubuntu-12.04/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=ubuntu-12.04/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=ubuntu-14.04/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=ubuntu-14.04/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=ubuntu-16.04/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=ubuntu-16.04/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=debian-8/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=debian-8/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=debian-9/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=debian-9/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=centos-6/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=centos-6/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=centos-7/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=centos-7/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=fedora-21/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=fedora-21/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=fedora-22/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=fedora-22/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=fedora-23/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=fedora-23/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=fedora-24/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=fedora-24/)|[![Build Status](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=arch/badge/icon)](https://jenkins.infernix.net/job/vagrant-libvirt-qa/qa_vagrant_libvirt_version=master,qa_vagrant_version=2.0.1,distro=arch/)|
22
+
23
+ ## Index
24
+
25
+
26
+ - [Features](#features)
27
+ - [Future work](#future-work)
28
+ - [Installation](#installation)
29
+ - [Possible problems with plugin installation on Linux](#possible-problems-with-plugin-installation-on-linux)
30
+ - [Vagrant Project Preparation](#vagrant-project-preparation)
31
+ - [Add Box](#add-box)
32
+ - [Create Vagrantfile](#create-vagrantfile)
33
+ - [Start VM](#start-vm)
34
+ - [How Project Is Created](#how-project-is-created)
35
+ - [Libvirt Configuration](#libvirt-configuration)
36
+ - [Provider Options](#provider-options)
37
+ - [Domain Specific Options](#domain-specific-options)
38
+ - [Reload behavior](#reload-behavior)
39
+ - [Networks](#networks)
40
+ - [Private Network Options](#private-network-options)
41
+ - [Public Network Options](#public-network-options)
42
+ - [Management Network](#management-network)
43
+ - [Additional Disks](#additional-disks)
44
+ - [Reload behavior](#reload-behavior-1)
45
+ - [CDROMs](#cdroms)
46
+ - [Input](#input)
47
+ - [PCI device passthrough](#pci-device-passthrough)
48
+ - [USB Redirector Devices](#usb-redirector-devices)
49
+ - [Random number generator passthrough](#random-number-generator-passthrough)
50
+ - [Watchdog·Device](#watchdog-device)
51
+ - [Smartcard device](#smartcard-device)
52
+ - [CPU Features](#cpu-features)
53
+ - [No box and PXE boot](#no-box-and-pxe-boot)
54
+ - [SSH Access To VM](#ssh-access-to-vm)
55
+ - [Forwarded Ports](#forwarded-ports)
56
+ - [Synced Folders](#synced-folders)
57
+ - [Customized Graphics](#customized-graphics)
58
+ - [Box Format](#box-format)
59
+ - [Create Box](#create-box)
60
+ - [Development](#development)
61
+ - [Contributing](#contributing)
62
+
63
+ ## Features
64
+
65
+ * Control local Libvirt hypervisors.
66
+ * Vagrant `up`, `destroy`, `suspend`, `resume`, `halt`, `ssh`, `reload`,
67
+ `package` and `provision` commands.
68
+ * Upload box image (qcow2 format) to Libvirt storage pool.
69
+ * Create volume as COW diff image for domains.
70
+ * Create private networks.
71
+ * Create and boot Libvirt domains.
72
+ * SSH into domains.
73
+ * Setup hostname and network interfaces.
74
+ * Provision domains with any built-in Vagrant provisioner.
75
+ * Synced folder support via `rsync`, `nfs` or `9p`.
76
+ * Snapshots via [sahara](https://github.com/jedi4ever/sahara).
77
+ * Package caching via
78
+ [vagrant-cachier](http://fgrehm.viewdocs.io/vagrant-cachier/).
79
+ * Use boxes from other Vagrant providers via
80
+ [vagrant-mutate](https://github.com/sciurus/vagrant-mutate).
81
+ * Support VMs with no box for PXE boot purposes (Vagrant 1.6 and up)
82
+
83
+ ## Future work
84
+
85
+ * Take a look at [open
86
+ issues](https://github.com/vagrant-libvirt/vagrant-libvirt/issues?state=open).
87
+
88
+ ## Installation
89
+
90
+ First, you should have both qemu and libvirt installed if you plan to run VMs
91
+ on your local system. For instructions, refer to your linux distribution's
92
+ documentation.
93
+
94
+ **NOTE:** Before you start using Vagrant-libvirt, please make sure your libvirt
95
+ and qemu installation is working correctly and you are able to create qemu or
96
+ kvm type virtual machines with `virsh` or `virt-manager`.
97
+
98
+ Next, you must have [Vagrant
99
+ installed](http://docs.vagrantup.com/v2/installation/index.html).
100
+ Vagrant-libvirt supports Vagrant 1.5, 1.6, 1.7 and 1.8.
101
+ *We only test with the upstream version!* If you decide to install your distros
102
+ version and you run into problems, as a first step you should switch to upstream.
103
+
104
+ Now you need to make sure your have all the build dependencies installed for
105
+ vagrant-libvirt. This depends on your distro. An overview:
106
+
107
+ * Ubuntu 12.04/14.04/16.04, Debian:
108
+ ```shell
109
+ apt-get build-dep vagrant ruby-libvirt
110
+ apt-get install qemu libvirt-bin ebtables dnsmasq
111
+ apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
112
+ ```
113
+
114
+ (It is possible some users will already have libraries from the third line installed, but this is the way to make it work OOTB.)
115
+
116
+ * CentOS 6, 7, Fedora 21:
117
+ ```shell
118
+ yum install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm
119
+ ```
120
+
121
+ * Fedora 22 and up:
122
+ ```shell
123
+ dnf -y install qemu libvirt libvirt-devel ruby-devel gcc
124
+ ```
125
+
126
+ * Arch linux: please read the related [ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt) page.
127
+ ```shell
128
+ pacman -S vagrant
129
+ ```
130
+
131
+ Now you're ready to install vagrant-libvirt using standard [Vagrant
132
+ plugin](http://docs.vagrantup.com/v2/plugins/usage.html) installation methods.
133
+
134
+ ```shell
135
+ $ vagrant plugin install vagrant-libvirt
136
+ ```
137
+
138
+ ### Possible problems with plugin installation on Linux
139
+
140
+ In case of problems with building nokogiri and ruby-libvirt gem, install
141
+ missing development libraries for libxslt, libxml2 and libvirt.
142
+
143
+
144
+ On Ubuntu, Debian, make sure you are running all three of the `apt` commands above with `sudo`.
145
+
146
+
147
+ On RedHat, Centos, Fedora, ...
148
+
149
+ ```shell
150
+ $ sudo dnf install libxslt-devel libxml2-devel libvirt-devel \
151
+ libguestfs-tools-c ruby-devel gcc
152
+ ```
153
+
154
+ On Arch linux it is recommended to follow [steps from ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt).
155
+
156
+ If have problem with installation - check your linker. It should be `ld.gold`:
157
+
158
+ ```shell
159
+ sudo alternatives --set ld /usr/bin/ld.gold
160
+ # OR
161
+ sudo ln -fs /usr/bin/ld.gold /usr/bin/ld
162
+ ```
163
+
164
+ If you have issues building ruby-libvirt, try the following:
165
+ ```shell
166
+ CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/include/libvirt with-libvirt-lib=/usr/lib' GEM_HOME=~/.vagrant.d/gems GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems PATH=/opt/vagrant/embedded/bin:$PATH vagrant plugin install vagrant-libvirt
167
+ ```
168
+
169
+ ## Vagrant Project Preparation
170
+
171
+ ### Add Box
172
+
173
+ After installing the plugin (instructions above), the quickest way to get
174
+ started is to add Libvirt box and specify all the details manually within a
175
+ `config.vm.provider` block. So first, add Libvirt box using any name you want.
176
+ You can find more libvirt ready boxes at
177
+ [Atlas](https://atlas.hashicorp.com/boxes/search?provider=libvirt). For
178
+ example:
179
+
180
+ ```shell
181
+ vagrant init fedora/24-cloud-base
182
+ ```
183
+
184
+ ### Create Vagrantfile
185
+
186
+ And then make a Vagrantfile that looks like the following, filling in your
187
+ information where necessary. For example:
188
+
189
+ ```ruby
190
+ Vagrant.configure("2") do |config|
191
+ config.vm.define :test_vm do |test_vm|
192
+ test_vm.vm.box = "fedora/24-cloud-base"
193
+ end
194
+ end
195
+ ```
196
+
197
+ ### Start VM
198
+
199
+ In prepared project directory, run following command:
200
+
201
+ ```shell
202
+ $ vagrant up --provider=libvirt
203
+ ```
204
+
205
+ Vagrant needs to know that we want to use Libvirt and not default VirtualBox.
206
+ That's why there is `--provider=libvirt` option specified. Other way to tell
207
+ Vagrant to use Libvirt provider is to setup environment variable
208
+
209
+ ```shell
210
+ export VAGRANT_DEFAULT_PROVIDER=libvirt
211
+ ```
212
+
213
+ ### How Project Is Created
214
+
215
+ Vagrant goes through steps below when creating new project:
216
+
217
+ 1. Connect to Libvirt localy or remotely via SSH.
218
+ 2. Check if box image is available in Libvirt storage pool. If not, upload it
219
+ to remote Libvirt storage pool as new volume.
220
+ 3. Create COW diff image of base box image for new Libvirt domain.
221
+ 4. Create and start new domain on Libvirt host.
222
+ 5. Check for DHCP lease from dnsmasq server.
223
+ 6. Wait till SSH is available.
224
+ 7. Sync folders and run Vagrant provisioner on new domain if setup in
225
+ Vagrantfile.
226
+
227
+ ### Libvirt Configuration
228
+
229
+ ### Provider Options
230
+
231
+ Although it should work without any configuration for most people, this
232
+ provider exposes quite a few provider-specific configuration options. The
233
+ following options allow you to configure how vagrant-libvirt connects to
234
+ libvirt, and are used to generate the [libvirt connection
235
+ URI](http://libvirt.org/uri.html):
236
+
237
+ * `driver` - A hypervisor name to access. For now only kvm and qemu are
238
+ supported
239
+ * `host` - The name of the server, where libvirtd is running
240
+ * `connect_via_ssh` - If use ssh tunnel to connect to Libvirt. Absolutely
241
+ needed to access libvirt on remote host. It will not be able to get the IP
242
+ address of a started VM otherwise.
243
+ * `username` - Username and password to access Libvirt
244
+ * `password` - Password to access Libvirt
245
+ * `id_ssh_key_file` - If not nil, uses this ssh private key to access Libvirt.
246
+ Default is `$HOME/.ssh/id_rsa`. Prepends `$HOME/.ssh/` if no directory
247
+ * `socket` - Path to the libvirt unix socket (e.g.
248
+ `/var/run/libvirt/libvirt-sock`)
249
+ * `uri` - For advanced usage. Directly specifies what libvirt connection URI
250
+ vagrant-libvirt should use. Overrides all other connection configuration
251
+ options
252
+
253
+ Connection-independent options:
254
+
255
+ * `storage_pool_name` - Libvirt storage pool name, where box image and instance
256
+ snapshots will be stored.
257
+
258
+ For example:
259
+
260
+ ```ruby
261
+ Vagrant.configure("2") do |config|
262
+ config.vm.provider :libvirt do |libvirt|
263
+ libvirt.host = "example.com"
264
+ end
265
+ end
266
+ ```
267
+
268
+ ### Domain Specific Options
269
+
270
+ * `disk_bus` - The type of disk device to emulate. Defaults to virtio if not
271
+ set. Possible values are documented in libvirt's [description for
272
+ _target_](http://libvirt.org/formatdomain.html#elementsDisks). NOTE: this
273
+ option applies only to disks associated with a box image. To set the bus type
274
+ on additional disks, see the [Additional Disks](#additional-disks) section.
275
+ * `disk_device` - The disk device to emulate. Defaults to vda if not
276
+ set, which should be fine for paravirtualized guests, but some fully
277
+ virtualized guests may require hda. NOTE: this option also applies only to
278
+ disks associated with a box image.
279
+ * `nic_model_type` - parameter specifies the model of the network adapter when
280
+ you create a domain value by default virtio KVM believe possible values, see
281
+ the [documentation for
282
+ libvirt](https://libvirt.org/formatdomain.html#elementsNICSModel).
283
+ * `memory` - Amount of memory in MBytes. Defaults to 512 if not set.
284
+ * `cpus` - Number of virtual cpus. Defaults to 1 if not set.
285
+ * `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).
286
+
287
+ ```ruby
288
+ Vagrant.configure("2") do |config|
289
+ config.vm.provider :libvirt do |libvirt|
290
+ libvirt.cpus = 4
291
+ libvirt.cputopology :sockets => '2', :cores => '2', :threads => '1'
292
+ end
293
+ end
294
+ ```
295
+
296
+ * `nested` - [Enable nested
297
+ virtualization](https://github.com/torvalds/linux/blob/master/Documentation/virtual/kvm/nested-vmx.txt).
298
+ Default is false.
299
+ * `cpu_mode` - [CPU emulation
300
+ mode](https://libvirt.org/formatdomain.html#elementsCPU). Defaults to
301
+ 'host-model' if not set. Allowed values: host-model, host-passthrough,
302
+ custom.
303
+ * `cpu_model` - CPU Model. Defaults to 'qemu64' if not set and `cpu_mode` is
304
+ `custom` and to '' otherwise. This can really only be used when setting
305
+ `cpu_mode` to `custom`.
306
+ * `cpu_fallback` - Whether to allow libvirt to fall back to a CPU model close
307
+ to the specified model if features in the guest CPU are not supported on the
308
+ host. Defaults to 'allow' if not set. Allowed values: `allow`, `forbid`.
309
+ * `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`.
310
+
311
+ The sum of all the memory defined here will act as your total memory for your guest VM. **This sum will override what is set in `v.memory`**
312
+ ```
313
+ v.cpus = 4
314
+ v.numa_nodes = [
315
+ {:cpus => "0-1", :memory => "1024"},
316
+ {:cpus => "2-3", :memory => "4096"}
317
+ ]
318
+ ```
319
+ * `loader` - Sets path to custom UEFI loader.
320
+ * `volume_cache` - Controls the cache mechanism. Possible values are "default",
321
+ "none", "writethrough", "writeback", "directsync" and "unsafe". [See
322
+ driver->cache in libvirt
323
+ documentation](http://libvirt.org/formatdomain.html#elementsDisks).
324
+ * `kernel` - To launch the guest with a kernel residing on host filesystems.
325
+ Equivalent to qemu `-kernel`.
326
+ * `initrd` - To specify the initramfs/initrd to use for the guest. Equivalent
327
+ to qemu `-initrd`.
328
+ * `random_hostname` - To create a domain name with extra information on the end
329
+ to prevent hostname conflicts.
330
+ * `cmd_line` - Arguments passed on to the guest kernel initramfs or initrd to
331
+ use. Equivalent to qemu `-append`, only possible to use in combination with `initrd` and `kernel`.
332
+ * `graphics_type` - Sets the protocol used to expose the guest display.
333
+ Defaults to `vnc`. Possible values are "sdl", "curses", "none", "gtk", "vnc"
334
+ or "spice".
335
+ * `graphics_port` - Sets the port for the display protocol to bind to.
336
+ Defaults to 5900.
337
+ * `graphics_ip` - Sets the IP for the display protocol to bind to. Defaults to
338
+ "127.0.0.1".
339
+ * `graphics_passwd` - Sets the password for the display protocol. Working for
340
+ vnc and spice. by default working without passsword.
341
+ * `graphics_autoport` - Sets autoport for graphics, libvirt in this case
342
+ ignores graphics_port value, Defaults to 'yes'. Possible value are "yes" and
343
+ "no"
344
+ * `keymap` - Set keymap for vm. default: en-us
345
+ * `kvm_hidden` - [Hide the hypervisor from the
346
+ guest](https://libvirt.org/formatdomain.html#elementsFeatures). Useful for
347
+ [GPU passthrough](#pci-device-passthrough) on stubborn drivers. Default is false.
348
+ * `video_type` - Sets the graphics card type exposed to the guest. Defaults to
349
+ "cirrus". [Possible
350
+ values](http://libvirt.org/formatdomain.html#elementsVideo) are "vga",
351
+ "cirrus", "vmvga", "xen", "vbox", or "qxl".
352
+ * `video_vram` - Used by some graphics card types to vary the amount of RAM
353
+ dedicated to video. Defaults to 9216.
354
+ * `sound_type` - [Set the virtual sound card](https://libvirt.org/formatdomain.html#elementsSound)
355
+ Defaults to "ich6".
356
+ * `machine_type` - Sets machine type. Equivalent to qemu `-machine`. Use
357
+ `qemu-system-x86_64 -machine help` to get a list of supported machines.
358
+ * `machine_arch` - Sets machine architecture. This helps libvirt to determine
359
+ the correct emulator type. Possible values depend on your version of qemu.
360
+ For possible values, see which emulator executable `qemu-system-*` your
361
+ system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`,
362
+ `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`,
363
+ `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`,
364
+ `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`,
365
+ `xtensa`, `xtensaeb`.
366
+ * `machine_virtual_size` - Sets the disk size in GB for the machine overriding
367
+ the default specified in the box. Allows boxes to defined with a minimal size
368
+ disk by default and to be grown to a larger size at creation time. Will
369
+ ignore sizes smaller than the size specified by the box metadata. Note that
370
+ currently there is no support for automatically resizing the filesystem to
371
+ take advantage of the larger disk.
372
+ * `emulator_path` - Explicitly select which device model emulator to use by
373
+ providing the path, e.g. `/usr/bin/qemu-system-x86_64`. This is especially
374
+ useful on systems that fail to select it automatically based on
375
+ `machine_arch` which then results in a capability error.
376
+ * `boot` - Change the boot order and enables the boot menu. Possible options
377
+ are "hd", "network", "cdrom". Defaults to "hd" with boot menu disabled. When
378
+ "network" is set without "hd", only all NICs will be tried; see below for
379
+ more detail.
380
+ * `nic_adapter_count` - Defaults to '8'. Only use case for increasing this
381
+ count is for VMs that virtualize switches such as Cumulus Linux. Max value
382
+ for Cumulus Linux VMs is 33.
383
+ * `uuid` - Force a domain UUID. Defaults to autogenerated value by libvirt if
384
+ not set.
385
+ * `suspend_mode` - What is done on vagrant suspend. Possible values: 'pause',
386
+ 'managedsave'. Pause mode executes a la `virsh suspend`, which just pauses
387
+ execution of a VM, not freeing resources. Managed save mode does a la `virsh
388
+ managedsave` which frees resources suspending a domain.
389
+ * `tpm_model` - The model of the TPM to which you wish to connect.
390
+ * `tpm_type` - The type of TPM device to which you are connecting.
391
+ * `tpm_path` - The path to the TPM device on the host system.
392
+ * `dtb` - The device tree blob file, mostly used for non-x86 platforms. In case
393
+ the device tree isn't added in-line to the kernel, it can be manually
394
+ specified here.
395
+ * `autostart` - Automatically start the domain when the host boots. Defaults to
396
+ 'false'.
397
+ * `channel` - [libvirt
398
+ channels](https://libvirt.org/formatdomain.html#elementCharChannel).
399
+ Configure a private communication channel between the host and guest, e.g.
400
+ for use by the [qemu guest
401
+ agent](http://wiki.libvirt.org/page/Qemu_guest_agent) and the Spice/QXL
402
+ graphics type.
403
+ * `mgmt_attach` - Decide if VM has interface in mgmt network. If set to 'false'
404
+ it is not possible to communicate with VM through `vagrant ssh` or run
405
+ provisioning. Setting to 'false' is only possible when VM doesn't use box.
406
+ Defaults set to 'true'.
407
+
408
+ Specific domain settings can be set for each domain separately in multi-VM
409
+ environment. Example below shows a part of Vagrantfile, where specific options
410
+ are set for dbserver domain.
411
+
412
+ ```ruby
413
+ Vagrant.configure("2") do |config|
414
+ config.vm.define :dbserver do |dbserver|
415
+ dbserver.vm.box = "centos64"
416
+ dbserver.vm.provider :libvirt do |domain|
417
+ domain.memory = 2048
418
+ domain.cpus = 2
419
+ domain.nested = true
420
+ domain.volume_cache = 'none'
421
+ end
422
+ end
423
+
424
+ # ...
425
+ ```
426
+
427
+ The following example shows part of a Vagrantfile that enables the VM to boot
428
+ from a network interface first and a hard disk second. This could be used to
429
+ run VMs that are meant to be a PXE booted machines. Be aware that if `hd` is
430
+ not specified as a boot option, it will never be tried.
431
+
432
+ ```ruby
433
+ Vagrant.configure("2") do |config|
434
+ config.vm.define :pxeclient do |pxeclient|
435
+ pxeclient.vm.box = "centos64"
436
+ pxeclient.vm.provider :libvirt do |domain|
437
+ domain.boot 'network'
438
+ domain.boot 'hd'
439
+ end
440
+ end
441
+
442
+ # ...
443
+ ```
444
+
445
+ #### Reload behavior
446
+
447
+ On `vagrant reload` the following domain specific attributes are updated in
448
+ defined domain:
449
+
450
+ * `disk_bus` - Is updated only on disks. It skips CDROMs
451
+ * `nic_model_type` - Updated
452
+ * `memory` - Updated
453
+ * `cpus` - Updated
454
+ * `nested` - Updated
455
+ * `cpu_mode` - Updated. Pay attention that custom mode is not supported
456
+ * `graphics_type` - Updated
457
+ * `graphics_port` - Updated
458
+ * `graphics_ip` - Updated
459
+ * `graphics_passwd` - Updated
460
+ * `graphics_autoport` - Updated
461
+ * `keymap` - Updated
462
+ * `video_type` - Updated
463
+ * `video_vram` - Updated
464
+ * `tpm_model` - Updated
465
+ * `tpm_type` - Updated
466
+ * `tpm_path` - Updated
467
+
468
+ ## Networks
469
+
470
+ Networking features in the form of `config.vm.network` support private networks
471
+ concept. It supports both the virtual network switch routing types and the
472
+ point to point Guest OS to Guest OS setting using UDP/Mcast/TCP tunnel
473
+ interfaces.
474
+
475
+ http://wiki.libvirt.org/page/VirtualNetworking
476
+
477
+ https://libvirt.org/formatdomain.html#elementsNICSTCP
478
+
479
+ http://libvirt.org/formatdomain.html#elementsNICSMulticast
480
+
481
+ http://libvirt.org/formatdomain.html#elementsNICSUDP _(in libvirt v1.2.20 and higher)_
482
+
483
+ Public Network interfaces are currently implemented using the macvtap driver.
484
+ The macvtap driver is only available with the Linux Kernel version >= 2.6.24.
485
+ See the following libvirt documentation for the details of the macvtap usage.
486
+
487
+ http://www.libvirt.org/formatdomain.html#elementsNICSDirect
488
+
489
+ An examples of network interface definitions:
490
+
491
+ ```ruby
492
+ # Private network using virtual network switching
493
+ config.vm.define :test_vm1 do |test_vm1|
494
+ test_vm1.vm.network :private_network, :ip => "10.20.30.40"
495
+ end
496
+
497
+ # Private network using DHCP and a custom network
498
+ config.vm.define :test_vm1 do |test_vm1|
499
+ test_vm1.vm.network :private_network,
500
+ :type => "dhcp",
501
+ :libvirt__network_address => '10.20.30.0'
502
+ end
503
+
504
+ # Private network (as above) using a domain name
505
+ config.vm.define :test_vm1 do |test_vm1|
506
+ test_vm1.vm.network :private_network,
507
+ :ip => "10.20.30.40",
508
+ :libvirt__domain_name => "test.local"
509
+ end
510
+
511
+ # Private network. Point to Point between 2 Guest OS using a TCP tunnel
512
+ # Guest 1
513
+ config.vm.define :test_vm1 do |test_vm1|
514
+ test_vm1.vm.network :private_network,
515
+ :libvirt__tunnel_type => 'server',
516
+ # default is 127.0.0.1 if omitted
517
+ # :libvirt__tunnel_ip => '127.0.0.1',
518
+ :libvirt__tunnel_port => '11111'
519
+ # network with ipv6 support
520
+ test_vm1.vm.network :private_network,
521
+ :ip => "10.20.5.42",
522
+ :libvirt__guest_ipv6 => "yes",
523
+ :libvirt__ipv6_address => "2001:db8:ca2:6::1",
524
+ :libvirt__ipv6_prefix => "64"
525
+
526
+ # Guest 2
527
+ config.vm.define :test_vm2 do |test_vm2|
528
+ test_vm2.vm.network :private_network,
529
+ :libvirt__tunnel_type => 'client',
530
+ # default is 127.0.0.1 if omitted
531
+ # :libvirt__tunnel_ip => '127.0.0.1',
532
+ :libvirt__tunnel_port => '11111'
533
+ # network with ipv6 support
534
+ test_vm2.vm.network :private_network,
535
+ :ip => "10.20.5.45",
536
+ :libvirt__guest_ipv6 => "yes",
537
+ :libvirt__ipv6_address => "2001:db8:ca2:6::1",
538
+ :libvirt__ipv6_prefix => "64"
539
+
540
+
541
+ # Public Network
542
+ config.vm.define :test_vm1 do |test_vm1|
543
+ test_vm1.vm.network :public_network,
544
+ :dev => "virbr0",
545
+ :mode => "bridge",
546
+ :type => "bridge"
547
+ end
548
+ ```
549
+
550
+ In example below, one network interface is configured for VM `test_vm1`. After
551
+ you run `vagrant up`, VM will be accessible on IP address `10.20.30.40`. So if
552
+ you install a web server via provisioner, you will be able to access your
553
+ testing server on `http://10.20.30.40` URL. But beware that this address is
554
+ private to libvirt host only. It's not visible outside of the hypervisor box.
555
+
556
+ If network `10.20.30.0/24` doesn't exist, provider will create it. By default
557
+ created networks are NATed to outside world, so your VM will be able to connect
558
+ to the internet (if hypervisor can). And by default, DHCP is offering addresses
559
+ on newly created networks.
560
+
561
+ The second interface is created and bridged into the physical device `eth0`.
562
+ This mechanism uses the macvtap Kernel driver and therefore does not require an
563
+ existing bridge device. This configuration assumes that DHCP and DNS services
564
+ are being provided by the public network. This public interface should be
565
+ reachable by anyone with access to the public network.
566
+
567
+ ### Private Network Options
568
+
569
+ *Note: These options are not applicable to public network interfaces.*
570
+
571
+ There is a way to pass specific options for libvirt provider when using
572
+ `config.vm.network` to configure new network interface. Each parameter name
573
+ starts with `libvirt__` string. Here is a list of those options:
574
+
575
+ * `:libvirt__network_name` - Name of libvirt network to connect to. By default,
576
+ network 'default' is used.
577
+ * `:libvirt__netmask` - Used only together with `:ip` option. Default is
578
+ '255.255.255.0'.
579
+ * `:libvirt__network_address` - Used only when `:type` is set to `dhcp`. Only `/24` subnet is supported. Default is `172.28.128.0`.
580
+ * `:libvirt__host_ip` - Address to use for the host (not guest). Default is
581
+ first possible address (after network address).
582
+ * `:libvirt__domain_name` - DNS domain of the DHCP server. Used only
583
+ when creating new network.
584
+ * `:libvirt__dhcp_enabled` - If DHCP will offer addresses, or not. Used only
585
+ when creating new network. Default is true.
586
+ * `:libvirt__dhcp_start` - First address given out via DHCP. Default is third
587
+ address in range (after network name and gateway).
588
+ * `:libvirt__dhcp_stop` - Last address given out via DHCP. Default is last
589
+ possible address in range (before broadcast address).
590
+ * `:libvirt__dhcp_bootp_file` - The file to be used for the boot image. Used
591
+ only when dhcp is enabled.
592
+ * `:libvirt__dhcp_bootp_server` - The server that runs the DHCP server. Used
593
+ only when dhcp is enabled.By default is the same host that runs the DHCP
594
+ server.
595
+ * `:libvirt__adapter` - Number specifiyng sequence number of interface.
596
+ * `:libvirt__forward_mode` - Specify one of `veryisolated`, `none`, `nat` or
597
+ `route` options. This option is used only when creating new network. Mode
598
+ `none` will create isolated network without NATing or routing outside. You
599
+ will want to use NATed forwarding typically to reach networks outside of
600
+ hypervisor. Routed forwarding is typically useful to reach other networks
601
+ within hypervisor. `veryisolated` described
602
+ [here](https://libvirt.org/formatnetwork.html#examplesNoGateway). By
603
+ default, option `nat` is used.
604
+ * `:libvirt__forward_device` - Name of interface/device, where network should
605
+ be forwarded (NATed or routed). Used only when creating new network. By
606
+ default, all physical interfaces are used.
607
+ * `:libvirt__tunnel_type` - Set to 'udp' if using UDP unicast tunnel mode
608
+ (libvirt v1.2.20 or higher). Set this to either "server" or "client" for tcp
609
+ tunneling. Set this to 'mcast' if using multicast tunneling. This
610
+ configuration type uses tunnels to generate point to point connections
611
+ between Guests. Useful for Switch VMs like Cumulus Linux. No virtual switch
612
+ setting like `libvirt__network_name` applies with tunnel interfaces and will
613
+ be ignored if configured.
614
+ * `:libvirt__tunnel_ip` - Sets the source IP of the libvirt tunnel interface.
615
+ By default this is `127.0.0.1` for TCP and UDP tunnels and `239.255.1.1` for
616
+ Multicast tunnels. It populates the address field in the `<source
617
+ address="XXX">` of the interface xml configuration.
618
+ * `:libvirt__tunnel_port` - Sets the source port the tcp/udp/mcast tunnel with
619
+ use. This port information is placed in the `<source port=XXX/>` section of
620
+ interface xml configuration.
621
+ * `:libvirt__tunnel_local_port` - Sets the local port used by the udp tunnel
622
+ interface type. It populates the port field in the `<local port=XXX">`
623
+ section of the interface xml configuration. _(This feature only works in
624
+ libvirt 1.2.20 and higher)_
625
+ * `:libvirt__tunnel_local_ip` - Sets the local IP used by the udp tunnel
626
+ interface type. It populates the ip entry of the `<local address=XXX">`
627
+ section of the interface xml configuration. _(This feature only works in
628
+ libvirt 1.2.20 and higher)_
629
+ * `:libvirt__guest_ipv6` - Enable or disable guest-to-guest IPv6 communication.
630
+ See [here](https://libvirt.org/formatnetwork.html#examplesPrivate6), and
631
+ [here](http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=705e67d40b09a905cd6a4b8b418d5cb94eaa95a8)
632
+ for for more information. *Note: takes either 'yes' or 'no' for value*
633
+ * `:libvirt__ipv6_address` - Define ipv6 address, require also prefix.
634
+ * `:libvirt__ipv6_prefix` - Define ipv6 prefix. generate string `<ip family="ipv6" address="address" prefix="prefix" >`
635
+ * `:libvirt__iface_name` - Define a name for the private network interface.
636
+ With this feature one can [simulate physical link
637
+ failures](https://github.com/vagrant-libvirt/vagrant-libvirt/pull/498)
638
+ * `:mac` - MAC address for the interface. *Note: specify this in lowercase
639
+ since Vagrant network scripts assume it will be!*
640
+ * `:libvirt__mtu` - MTU size for the libvirt network, if not defined, the
641
+ created network will use the libvirt default (1500). VMs still need to set the
642
+ MTU accordingly.
643
+ * `:model_type` - parameter specifies the model of the network adapter when you
644
+ create a domain value by default virtio KVM believe possible values, see the
645
+ documentation for libvirt
646
+ * `:libvirt__driver_name` - Define which network driver to use. [More
647
+ info](https://libvirt.org/formatdomain.html#elementsDriverBackendOptions)
648
+ * `:libvirt__driver_queues` - Define a number of queues to be used for network
649
+ interface. Set equal to numer of vCPUs for best performance. [More
650
+ info](http://www.linux-kvm.org/page/Multiqueue)
651
+ * `:autostart` - Automatic startup of network by the libvirt daemon.
652
+ If not specified the default is 'false'.
653
+ * `:bus` - The bus of the PCI device. Both :bus and :slot have to be defined.
654
+ * `:slot` - The slot of the PCI device. Both :bus and :slot have to be defined.
655
+
656
+ When the option `:libvirt__dhcp_enabled` is to to 'false' it shouldn't matter
657
+ whether the virtual network contains a DHCP server or not and vagrant-libvirt
658
+ should not fail on it. The only situation where vagrant-libvirt should fail is
659
+ when DHCP is requested but isn't configured on a matching already existing
660
+ virtual network.
661
+
662
+ ### Public Network Options
663
+
664
+ * `:dev` - Physical device that the public interface should use. Default is
665
+ 'eth0'.
666
+ * `:mode` - The mode in which the public interface should operate in. Supported
667
+ modes are available from the [libvirt
668
+ documentation](http://www.libvirt.org/formatdomain.html#elementsNICSDirect).
669
+ Default mode is 'bridge'.
670
+ * `:type` - is type of interface.(`<interface type="#{@type}">`)
671
+ * `:mac` - MAC address for the interface.
672
+ * `:network_name` - Name of libvirt network to connect to.
673
+ * `:portgroup` - Name of libvirt portgroup to connect to.
674
+ * `:ovs` - Support to connect to an Open vSwitch bridge device. Default is
675
+ 'false'.
676
+ * `:trust_guest_rx_filters` - Support trustGuestRxFilters attribute. Details
677
+ are listed [here](http://www.libvirt.org/formatdomain.html#elementsNICSDirect).
678
+ Default is 'false'.
679
+
680
+ ### Management Network
681
+
682
+ vagrant-libvirt uses a private network to perform some management operations on
683
+ VMs. All VMs will have an interface connected to this network and an IP address
684
+ dynamically assigned by libvirt unless you set `:mgmt_attach` to 'false'.
685
+ This is in addition to any networks you configure. The name and address
686
+ used by this network are configurable at the provider level.
687
+
688
+ * `management_network_name` - Name of libvirt network to which all VMs will be
689
+ connected. If not specified the default is 'vagrant-libvirt'.
690
+ * `management_network_address` - Address of network to which all VMs will be
691
+ connected. Must include the address and subnet mask. If not specified the
692
+ default is '192.168.121.0/24'.
693
+ * `management_network_mode` - Network mode for the libvirt management network.
694
+ Specify one of veryisolated, none, nat or route options. Further documentated
695
+ under [Private Networks](#private-network-options)
696
+ * `management_network_guest_ipv6` - Enable or disable guest-to-guest IPv6
697
+ communication. See
698
+ [here](https://libvirt.org/formatnetwork.html#examplesPrivate6), and
699
+ [here](http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=705e67d40b09a905cd6a4b8b418d5cb94eaa95a8)
700
+ for for more information.
701
+ * `management_network_autostart` - Automatic startup of mgmt network, if not
702
+ specified the default is 'false'.
703
+ * `:management_network_pci_bus` - The bus of the PCI device.
704
+ * `:management_network_pci_slot` - The slot of the PCI device.
705
+ * `management_network_mac` - MAC address of management network interface.
706
+
707
+ You may wonder how vagrant-libvirt knows the IP address a VM received. Libvirt
708
+ doesn't provide a standard way to find out the IP address of a running domain.
709
+ But we do know the MAC address of the virtual machine's interface on the
710
+ management network. Libvirt is closely connected with dnsmasq, which acts as a
711
+ DHCP server. dnsmasq writes lease information in the `/var/lib/libvirt/dnsmasq`
712
+ directory. Vagrant-libvirt looks for the MAC address in this file and extracts
713
+ the corresponding IP address.
714
+
715
+ ## Additional Disks
716
+
717
+ You can create and attach additional disks to a VM via `libvirt.storage :file`.
718
+ It has a number of options:
719
+
720
+ * `path` - Location of the disk image. If unspecified, a path is automtically
721
+ chosen in the same storage pool as the VMs primary disk.
722
+ * `device` - Name of the device node the disk image will have in the VM, e.g.
723
+ *vdb*. If unspecified, the next available device is chosen.
724
+ * `size` - Size of the disk image. If unspecified, defaults to 10G.
725
+ * `type` - Type of disk image to create. Defaults to *qcow2*.
726
+ * `bus` - Type of bus to connect device to. Defaults to *virtio*.
727
+ * `cache` - Cache mode to use, e.g. `none`, `writeback`, `writethrough` (see
728
+ the [libvirt documentation for possible
729
+ values](http://libvirt.org/formatdomain.html#elementsDisks) or
730
+ [here](https://www.suse.com/documentation/sles11/book_kvm/data/sect1_chapter_book_kvm.html)
731
+ for a fuller explanation). Defaults to *default*.
732
+ * `allow_existing` - Set to true if you want to allow the VM to use a
733
+ pre-existing disk. If the disk doesn't exist it will be created.
734
+ Disks with this option set to true need to be removed manually.
735
+ * `shareable` - Set to true if you want to simulate shared SAN storage.
736
+ * `serial` - Serial number of the disk device.
737
+
738
+ The following example creates two additional disks.
739
+
740
+ ```ruby
741
+ Vagrant.configure("2") do |config|
742
+ config.vm.provider :libvirt do |libvirt|
743
+ libvirt.storage :file, :size => '20G'
744
+ libvirt.storage :file, :size => '40G', :type => 'raw'
745
+ end
746
+ end
747
+ ```
748
+
749
+ For shared SAN storage to work the following example can be used:
750
+ ```ruby
751
+ Vagrant.configure("2") do |config|
752
+ config.vm.provider :libvirt do |libvirt|
753
+ libvirt.storage :file, :size => '20G', :path => 'my_shared_disk.img', :allow_existing => true, :shareable => true, :type => 'raw'
754
+ end
755
+ end
756
+ ```
757
+
758
+ ### Reload behavior
759
+
760
+ On `vagrant reload` the following additional disk attributes are updated in
761
+ defined domain:
762
+
763
+ * `bus` - Updated. Uses `device` as a search marker. It is not required to
764
+ define `device`, but it's recommended. If `device` is defined then the order
765
+ of addtitional disk definition becomes irrelevant.
766
+
767
+ ## CDROMs
768
+
769
+ You can attach up to four CDROMs to a VM via `libvirt.storage :file,
770
+ :device => :cdrom`. Available options are:
771
+
772
+ * `path` - The path to the iso to be used for the CDROM drive.
773
+ * `dev` - The device to use (`hda`, `hdb`, `hdc`, or `hdd`). This will be
774
+ automatically determined if unspecified.
775
+ * `bus` - The bus to use for the CDROM drive. Defaults to `ide`
776
+
777
+ The following example creates three CDROM drives in the VM:
778
+
779
+ ```ruby
780
+ Vagrant.configure("2") do |config|
781
+ config.vm.provider :libvirt do |libvirt|
782
+ libvirt.storage :file, :device => :cdrom, :path => '/path/to/iso1.iso'
783
+ libvirt.storage :file, :device => :cdrom, :path => '/path/to/iso2.iso'
784
+ libvirt.storage :file, :device => :cdrom, :path => '/path/to/iso3.iso'
785
+ end
786
+ end
787
+ ```
788
+
789
+ ## Input
790
+
791
+ You can specify multiple inputs to the VM via `libvirt.input`. Available
792
+ options are listed below. Note that both options are required:
793
+
794
+ * `type` - The type of the input
795
+ * `bus` - The bus of the input
796
+
797
+ ```ruby
798
+ Vagrant.configure("2") do |config|
799
+ config.vm.provider :libvirt do |libvirt|
800
+ # this is the default
801
+ # libvirt.input :type => "mouse", :bus => "ps2"
802
+
803
+ # very useful when having mouse issues when viewing VM via VNC
804
+ libvirt.input :type => "tablet", :bus => "usb"
805
+ end
806
+ end
807
+ ```
808
+
809
+ ## PCI device passthrough
810
+
811
+ You can specify multiple PCI devices to passthrough to the VM via
812
+ `libvirt.pci`. Available options are listed below. Note that all options are
813
+ required:
814
+
815
+ * `bus` - The bus of the PCI device
816
+ * `slot` - The slot of the PCI device
817
+ * `function` - The function of the PCI device
818
+
819
+ You can extract that information from output of `lspci` command. First
820
+ characters of each line are in format `[<bus>]:[<slot>].[<func>]`. For example:
821
+
822
+ ```shell
823
+ $ lspci| grep NVIDIA
824
+ 03:00.0 VGA compatible controller: NVIDIA Corporation GK110B [GeForce GTX TITAN Black] (rev a1)
825
+ ```
826
+
827
+ In that case `bus` is `0x03`, `slot` is `0x00` and `function` is `0x0`.
828
+
829
+ ```ruby
830
+ Vagrant.configure("2") do |config|
831
+ config.vm.provider :libvirt do |libvirt|
832
+ libvirt.pci :bus => '0x06', :slot => '0x12', :function => '0x5'
833
+
834
+ # Add another one if it is neccessary
835
+ libvirt.pci :bus => '0x03', :slot => '0x00', :function => '0x0'
836
+ end
837
+ end
838
+ ```
839
+
840
+ Note! Above options affect configuration only at domain creation. It won't change VM behaviour on `vagrant reload` after domain was created.
841
+
842
+ Don't forget to [set](#domain-specific-options) `kvm_hidden` option to `true` especially if you are passthroughing NVIDIA GPUs. Otherwise GPU is visible from VM but cannot be operated.
843
+
844
+ ## USB Redirector Devices
845
+ You can specify multiple redirect devices via `libvirt.redirdev`. There are two types, `tcp` and `spicevmc` supported, for forwarding USB-devices to the guest. Available options are listed below.
846
+
847
+ * `type` - The type of the USB redirector device. (`tcp` or `spicevmc`)
848
+ * `host` - The host where the device is attached to. (mandatory for type `tcp`)
849
+ * `port` - The port where the device is listening. (mandatory for type `tcp`)
850
+
851
+ ```ruby
852
+ Vagrant.configure("2") do |config|
853
+ config.vm.provider :libvirt do |libvirt|
854
+ # add two devices using spicevmc channel
855
+ (1..2).each do
856
+ libvirt.redirdev :type => "spicevmc"
857
+ end
858
+ # add device, provided by localhost:4000
859
+ libvirt.redirdev :type => "tcp", :host => "localhost", :port => "4000"
860
+ end
861
+ end
862
+ ```
863
+
864
+ ### Filter for USB Redirector Devices
865
+ You can define filter for redirected devices. These filters can be positiv or negative, by setting the mandatory option `allow=yes` or `allow=no`. All available options are listed below. Note the option `allow` is mandatory.
866
+
867
+ * `class` - The device class of the USB device. A list of device classes is available on [Wikipedia](https://en.wikipedia.org/wiki/USB#Device_classes).
868
+ * `vendor` - The vendor of the USB device.
869
+ * `product` - The product id of the USB device.
870
+ * `version` - The version of the USB device. Note that this is the version of `bcdDevice`
871
+ * `allow` - allow or disallow redirecting this device. (mandatory)
872
+
873
+ You can extract that information from output of `lsusb` command. Every line contains the information in format `Bus [<bus>] Device [<device>]: ID [<vendor>:[<product>]`. The `version` can be extracted from the detailed output of the device using `lsusb -D /dev/usb/[<bus>]/[<device>]`. For example:
874
+
875
+ ```shell
876
+ # get bcdDevice from
877
+ $: lsusb
878
+ Bus 001 Device 009: ID 08e6:3437 Gemalto (was Gemplus) GemPC Twin SmartCard Reader
879
+
880
+ $: lsusb -D /dev/bus/usb/001/009 | grep bcdDevice
881
+ bcdDevice 2.00
882
+ ```
883
+
884
+ In this case, the USB device with `class 0x0b`, `vendor 0x08e6`, `product 0x3437` and `bcdDevice version 2.00` is allowed to be redirected to the guest. All other devices will be refused.
885
+
886
+ ```ruby
887
+ Vagrant.configure("2") do |config|
888
+ config.vm.provider :libvirt do |libvirt|
889
+ libvirt.redirdev :type => "spicevmc"
890
+ libvirt.redirfilter :class => "0x0b" :vendor => "0x08e6" :product => "0x3437" :version => "2.00" :allow => "yes"
891
+ libvirt.redirfilter :allow => "no"
892
+ end
893
+ end
894
+ ```
895
+
896
+ ## Random number generator passthrough
897
+
898
+ You can pass through `/dev/random` to your VM by configuring the domain like this:
899
+
900
+ ```ruby
901
+ Vagrant.configure("2") do |config|
902
+ config.vm.provider :libvirt do |libvirt|
903
+ # Pass through /dev/random from the host to the VM
904
+ libvirt.random :model => 'random'
905
+ end
906
+ end
907
+ ```
908
+
909
+ At the moment only the `random` backend is supported.
910
+
911
+ ## Watchdog device
912
+ A virtual hardware watchdog device can be added to the guest via the `libvirt.watchdog` element. The option `model` is mandatory and could have on of the following values.
913
+
914
+ * `i6300esb` - the recommended device, emulating a PCI Intel 6300ESB
915
+ * 'ib700` - emulating an ISA iBase IB700
916
+ * `diag288` - emulating an S390 DIAG288 device
917
+
918
+ The optional action attribute describes what `action` to take when the watchdog expires. Valid values are specific to the underlying hypervisor. The default behavior is `reset`.
919
+
920
+ * `reset` - default, forcefully reset the guest
921
+ * `shutdown` - gracefully shutdown the guest (not recommended)
922
+ * `poweroff` - forcefully power off the guest
923
+ * `pause` - pause the guest
924
+ * `none` - do nothing
925
+ * `dump` - automatically dump the guest
926
+ * `inject-nmi` - inject a non-maskable interrupt into the guest
927
+
928
+ ```ruby
929
+ Vagrant.configure("2") do |config|
930
+ config.vm.provider :libvirt do |libvirt|
931
+ # Add libvirt watchdog device model i6300esb
932
+ libvirt.watchdog :model => 'i6300esb', :action => 'reset'
933
+ end
934
+ end
935
+ ```
936
+
937
+ ## Smartcard device
938
+ A virtual smartcard device can be supplied to the guest via the `libvirt.smartcard` element. The option `mode` is mandatory and currently only value `passthrough` is supported. The value `spicevmc` for option `type` is default value and can be supressed. On using `type = tcp`, the options `source_mode`, `source_host` and `source_service` are mandatory.
939
+
940
+ ```ruby
941
+ Vagrant.configure("2") do |config|
942
+ config.vm.provider :libvirt do |libvirt|
943
+ # Add smartcard device with type 'spicevmc'
944
+ libvirt.smartcard :mode => 'passthrough', :type => 'spicevmc'
945
+ end
946
+ end
947
+ ```
948
+
949
+ ```ruby
950
+ Vagrant.configure("2") do |config|
951
+ config.vm.provider :libvirt do |libvirt|
952
+ # Add smartcard device with type 'tcp'
953
+ domain.smartcard :mode => 'passthrough', :type => 'tcp', :source_mode => 'bind', :source_host => '127.0.0.1', :source_service => '2001'
954
+ end
955
+ end
956
+ ```
957
+ ## Features
958
+
959
+ Hypervisor features can be specified via `libvirt.features` as a list. The default
960
+ options that are enabled are `acpi`, `apic` and `pae`. If you define `libvirt.features`
961
+ you overwrite the defaults, so keep that in mind.
962
+
963
+ An example:
964
+
965
+ ```ruby
966
+ Vagrant.configure("2") do |config|
967
+ config.vm.provider :libvirt do |libvirt|
968
+ # Specify the default hypervisor features
969
+ libvirt.features = ['acpi', 'apic', 'pae' ]
970
+ end
971
+ end
972
+ ```
973
+
974
+ A different example for ARM boards:
975
+
976
+ ```ruby
977
+ Vagrant.configure("2") do |config|
978
+ config.vm.provider :libvirt do |libvirt|
979
+ # Specify the default hypervisor features
980
+ libvirt.features = ["apic", "gic version='2'" ]
981
+ end
982
+ end
983
+ ```
984
+
985
+ ## CPU features
986
+
987
+ You can specify CPU feature policies via `libvirt.cpu_feature`. Available
988
+ options are listed below. Note that both options are required:
989
+
990
+ * `name` - The name of the feature for the chosen CPU (see libvirts
991
+ `cpu_map.xml`)
992
+ * `policy` - The policy for this feature (one of `force`, `require`,
993
+ `optional`, `disable` and `forbid` - see libvirt documentation)
994
+
995
+ ```ruby
996
+ Vagrant.configure("2") do |config|
997
+ config.vm.provider :libvirt do |libvirt|
998
+ # The feature will not be supported by virtual CPU.
999
+ libvirt.cpu_feature :name => 'hypervisor', :policy => 'disable'
1000
+ # Guest creation will fail unless the feature is supported by host CPU.
1001
+ libvirt.cpu_feature :name => 'vmx', :policy => 'require'
1002
+ # The virtual CPU will claim the feature is supported regardless of it being supported by host CPU.
1003
+ libvirt.cpu_feature :name => 'pdpe1gb', :policy => 'force'
1004
+ end
1005
+ end
1006
+ ```
1007
+
1008
+ ## Memory Backing
1009
+
1010
+ You can specify memoryBacking options via `libvirt.memorybacking`. Available options are shown below. Full documentation is available at the [libvirt _memoryBacking_ section](https://libvirt.org/formatdomain.html#elementsMemoryBacking).
1011
+
1012
+ NOTE: The hugepages `<page>` element is not yet supported
1013
+
1014
+ ```ruby
1015
+ Vagrant.configure("2") do |config|
1016
+ config.vm.provider :libvirt do |libvirt|
1017
+ libvirt.memorybacking :hugepages
1018
+ libvirt.memorybacking :nosharepages
1019
+ libvirt.memorybacking :locked
1020
+ libvirt.memorybacking :source, :type => 'file'
1021
+ libvirt.memorybacking :access, :mode => 'shared'
1022
+ libvirt.memorybacking :allocation, :mode => 'immediate'
1023
+ end
1024
+ end
1025
+ ```
1026
+ ## USB device passthrough
1027
+
1028
+ You can specify multiple USB devices to passthrough to the VM via
1029
+ `libvirt.usb`. The device can be specified by the following options:
1030
+
1031
+ * `bus` - The USB bus ID, e.g. "1"
1032
+ * `device` - The USB device ID, e.g. "2"
1033
+ * `vendor` - The USB devices vendor ID (VID), e.g. "0x1234"
1034
+ * `product` - The USB devices product ID (PID), e.g. "0xabcd"
1035
+
1036
+ At least one of these has to be specified, and `bus` and `device` may only be
1037
+ used together.
1038
+
1039
+ The example values above match the device from the following output of `lsusb`:
1040
+
1041
+ ```
1042
+ Bus 001 Device 002: ID 1234:abcd Example device
1043
+ ```
1044
+
1045
+ Additionally, the following options can be used:
1046
+
1047
+ * `startupPolicy` - Is passed through to libvirt and controls if the device has
1048
+ to exist. libvirt currently allows the following values: "mandatory",
1049
+ "requisite", "optional".
1050
+
1051
+ ## No box and PXE boot
1052
+
1053
+ There is support for PXE booting VMs with no disks as well as PXE booting VMs
1054
+ with blank disks. There are some limitations:
1055
+
1056
+ * Requires Vagrant 1.6.0 or newer
1057
+ * No provisioning scripts are ran
1058
+ * No network configuration is being applied to the VM
1059
+ * No SSH connection can be made
1060
+ * `vagrant halt` will only work cleanly if the VM handles ACPI shutdown signals
1061
+
1062
+ In short, VMs without a box can be created, halted and destroyed but all other
1063
+ functionality cannot be used.
1064
+
1065
+ An example for a PXE booted VM with no disks whatsoever:
1066
+
1067
+ ```ruby
1068
+ Vagrant.configure("2") do |config|
1069
+ config.vm.define :pxeclient do |pxeclient|
1070
+ pxeclient.vm.provider :libvirt do |domain|
1071
+ domain.boot 'network'
1072
+ end
1073
+ end
1074
+ end
1075
+ ```
1076
+
1077
+ And an example for a PXE booted VM with no box but a blank disk which will boot from this HD if the NICs fail to PXE boot:
1078
+
1079
+ ```ruby
1080
+ Vagrant.configure("2") do |config|
1081
+ config.vm.define :pxeclient do |pxeclient|
1082
+ pxeclient.vm.provider :libvirt do |domain|
1083
+ domain.storage :file, :size => '100G', :type => 'qcow2'
1084
+ domain.boot 'network'
1085
+ domain.boot 'hd'
1086
+ end
1087
+ end
1088
+ end
1089
+ ```
1090
+
1091
+ Example for vm with 2 networks and only 1 is bootable and has dhcp server in this subnet, for example foreman with dhcp server
1092
+ Name of network "foreman_managed" is key for define boot order
1093
+ ```ruby
1094
+ config.vm.define :pxeclient do |pxeclient|
1095
+ pxeclient.vm.network :private_network,ip: '10.0.0.5',
1096
+ libvirt__network_name: "foreman_managed",
1097
+ libvirt__dhcp_enabled: false,
1098
+ libvirt__host_ip: '10.0.0.1'
1099
+
1100
+ pxeclient.vm.provider :libvirt do |domain|
1101
+ domain.memory = 1000
1102
+ boot_network = {'network' => 'foreman_managed'}
1103
+ domain.storage :file, :size => '100G', :type => 'qcow2'
1104
+ domain.boot boot_network
1105
+ domain.boot 'hd'
1106
+ end
1107
+ end
1108
+ ```
1109
+
1110
+ ## SSH Access To VM
1111
+
1112
+ vagrant-libvirt supports vagrant's [standard ssh
1113
+ settings](https://docs.vagrantup.com/v2/vagrantfile/ssh_settings.html).
1114
+
1115
+ ## Forwarded Ports
1116
+
1117
+ vagrant-libvirt supports Forwarded Ports via ssh port forwarding. Please note
1118
+ that due to a well known limitation only the TCP protocol is supported. For
1119
+ each `forwarded_port` directive you specify in your Vagrantfile,
1120
+ vagrant-libvirt will maintain an active ssh process for the lifetime of the VM.
1121
+ If your VM should happen to be rebooted, the SSH session will need to be
1122
+ restablished by halting the VM and bringing it back up.
1123
+
1124
+ vagrant-libvirt supports an additional `forwarded_port` option `gateway_ports`
1125
+ which defaults to `false`, but can be set to `true` if you want the forwarded
1126
+ port to be accessible from outside the Vagrant host. In this case you should
1127
+ also set the `host_ip` option to `'*'` since it defaults to `'localhost'`.
1128
+
1129
+ You can also provide a custom adapter to forward from by 'adapter' option.
1130
+ Default is `eth0`.
1131
+
1132
+ **Internally Accessible Port Forward**
1133
+
1134
+ `config.vm.network :forwarded_port, guest: 80, host: 2000`
1135
+
1136
+ **Externally Accessible Port Forward**
1137
+
1138
+ `config.vm.network :forwarded_port, guest: 80, host: 2000, host_ip: "0.0.0.0"`
1139
+
1140
+ ## Synced Folders
1141
+
1142
+ Vagrant automatically syncs the project folder on the host to `/vagrant` in the guest. You can also configure
1143
+ additional synced folders.
1144
+
1145
+ `vagrant-libvirt` supports bidirectional synced folders via [NFS](https://en.wikipedia.org/wiki/Network_File_System) or [VirtFS](http://www.linux-kvm.org/page/VirtFS) ([9p or Plan 9](https://en.wikipedia.org/wiki/9P_(protocol))) and
1146
+ unidirectional via rsync. The default is NFS. Difference between NFS and 9p is explained [here](https://unix.stackexchange.com/questions/240281/virtfs-plan-9-vs-nfs-as-tool-for-share-folder-for-virtual-machine).
1147
+
1148
+ You can change the synced folder type for `/vagrant` by explicity configuring
1149
+ it an setting the type, e.g.
1150
+
1151
+ ```shell
1152
+ config.vm.synced_folder './', '/vagrant', type: 'rsync'
1153
+ ```
1154
+
1155
+ or
1156
+
1157
+ ```shell
1158
+ config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "squash", owner: "1000"
1159
+ ```
1160
+
1161
+ or
1162
+
1163
+ ```shell
1164
+ config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "mapped", mount: false
1165
+ ```
1166
+
1167
+ For 9p shares, a `mount: false` option allows to define synced folders without
1168
+ mounting them at boot.
1169
+
1170
+ 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.
1171
+
1172
+ **SECURITY NOTE:** for remote libvirt, nfs synced folders requires a bridged
1173
+ public network interface and you must connect to libvirt via ssh.
1174
+
1175
+
1176
+ ## Customized Graphics
1177
+
1178
+ vagrant-libvirt supports customizing the display and video settings of the
1179
+ managed guest. This is probably most useful for VNC-type displays with
1180
+ multiple guests. It lets you specify the exact port for each guest to use
1181
+ deterministically.
1182
+
1183
+ Here is an example of using custom display options:
1184
+
1185
+ ```ruby
1186
+ Vagrant.configure("2") do |config|
1187
+ config.vm.provider :libvirt do |libvirt|
1188
+ libvirt.graphics_port = 5901
1189
+ libvirt.graphics_ip = '0.0.0.0'
1190
+ libvirt.video_type = 'qxl'
1191
+ end
1192
+ end
1193
+ ```
1194
+
1195
+ ## TPM Devices
1196
+
1197
+ Modern versions of Libvirt support connecting to TPM devices on the host
1198
+ system. This allows you to enable Trusted Boot Extensions, among other
1199
+ features, on your guest VMs.
1200
+
1201
+ In general, you will only need to modify the `tpm_path` variable in your guest
1202
+ configuration. However, advanced usage, such as the application of a Software
1203
+ TPM, may require modifying the `tpm_model` and `tpm_type` variables.
1204
+
1205
+ The TPM options will only be used if you specify a TPM path. Declarations of
1206
+ any TPM options without specifying a path will result in those options being
1207
+ ignored.
1208
+
1209
+ Here is an example of using the TPM options:
1210
+
1211
+ ```ruby
1212
+ Vagrant.configure("2") do |config|
1213
+ config.vm.provider :libvirt do |libvirt|
1214
+ libvirt.tpm_model = 'tpm-tis'
1215
+ libvirt.tpm_type = 'passthrough'
1216
+ libvirt.tpm_path = '/dev/tpm0'
1217
+ end
1218
+ end
1219
+ ```
1220
+
1221
+ ## Libvirt communication channels
1222
+
1223
+ For certain functionality to be available within a guest, a private
1224
+ communication channel must be established with the host. Two notable examples
1225
+ of this are the qemu guest agent, and the Spice/QXL graphics type.
1226
+
1227
+ Below is a simple example which exposes a virtio serial channel to the guest.
1228
+ Note: in a multi-VM environment, the channel would be created for all VMs.
1229
+
1230
+ ```ruby
1231
+ vagrant.configure(2) do |config|
1232
+ config.vm.provider :libvirt do |libvirt|
1233
+ libvirt.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
1234
+ end
1235
+ end
1236
+ ```
1237
+
1238
+ Below is the syntax for creating a spicevmc channel for use by a qxl graphics
1239
+ card.
1240
+
1241
+ ```ruby
1242
+ vagrant.configure(2) do |config|
1243
+ config.vm.provider :libvirt do |libvirt|
1244
+ libvirt.channel :type => 'spicevmc', :target_name => 'com.redhat.spice.0', :target_type => 'virtio'
1245
+ end
1246
+ end
1247
+ ```
1248
+
1249
+ These settings can be specified on a per-VM basis, however the per-guest
1250
+ settings will OVERRIDE any global 'config' setting. In the following example,
1251
+ we create 3 VM with the following configuration:
1252
+
1253
+ * **master**: No channel settings specified, so we default to the provider
1254
+ setting of a single virtio guest agent channel.
1255
+ * **node1**: Override the channel setting, setting both the guest agent
1256
+ channel, and a spicevmc channel
1257
+ * **node2**: Override the channel setting, setting both the guest agent
1258
+ channel, and a 'guestfwd' channel. TCP traffic sent by the guest to the given
1259
+ IP address and port is forwarded to the host socket `/tmp/foo`. Note: this
1260
+ device must be unique for each VM.
1261
+
1262
+ For example:
1263
+
1264
+ ```ruby
1265
+ Vagrant.configure(2) do |config|
1266
+ config.vm.box = "fedora/24-cloud-base"
1267
+ config.vm.provider :libvirt do |libvirt|
1268
+ libvirt.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
1269
+ end
1270
+
1271
+ config.vm.define "master" do |master|
1272
+ master.vm.provider :libvirt do |domain|
1273
+ domain.memory = 1024
1274
+ end
1275
+ end
1276
+ config.vm.define "node1" do |node1|
1277
+ node1.vm.provider :libvirt do |domain|
1278
+ domain.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
1279
+ domain.channel :type => 'spicevmc', :target_name => 'com.redhat.spice.0', :target_type => 'virtio'
1280
+ end
1281
+ end
1282
+ config.vm.define "node2" do |node2|
1283
+ node2.vm.provider :libvirt do |domain|
1284
+ domain.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
1285
+ domain.channel :type => 'unix', :target_type => 'guestfwd', :target_address => '192.0.2.42', :target_port => '4242',
1286
+ :source_path => '/tmp/foo'
1287
+ end
1288
+ end
1289
+ end
1290
+ ```
1291
+
1292
+ ## Custom command line arguments
1293
+ You can also specify multiple qemuargs arguments for qemu-system
1294
+
1295
+ * `value` - Value
1296
+
1297
+ ```ruby
1298
+ Vagrant.configure("2") do |config|
1299
+ config.vm.provider :libvirt do |libvirt|
1300
+ libvirt.qemuargs :value => "-device"
1301
+ libvirt.qemuargs :value => "intel-iommu"
1302
+ end
1303
+ end
1304
+ ```
1305
+
1306
+ ## Box Format
1307
+
1308
+ You can view an example box in the
1309
+ [`example_box/directory`](https://github.com/vagrant-libvirt/vagrant-libvirt/tree/master/example_box).
1310
+ That directory also contains instructions on how to build a box.
1311
+
1312
+ The box is a tarball containing:
1313
+
1314
+ * qcow2 image file named `box.img`
1315
+ * `metadata.json` file describing box image (`provider`, `virtual_size`,
1316
+ `format`)
1317
+ * `Vagrantfile` that does default settings for the provider-specific
1318
+ configuration for this provider
1319
+
1320
+ ## Create Box
1321
+
1322
+ To create a vagrant-libvirt box from a qcow2 image, run `create_box.sh`
1323
+ (located in the tools directory):
1324
+
1325
+ ```shell
1326
+ $ create_box.sh ubuntu14.qcow2
1327
+ ```
1328
+
1329
+ You can also create a box by using [Packer](https://packer.io). Packer
1330
+ templates for use with vagrant-libvirt are available at
1331
+ https://github.com/jakobadam/packer-qemu-templates. After cloning that project
1332
+ you can build a vagrant-libvirt box by running:
1333
+
1334
+ ```shell
1335
+ $ cd packer-qemu-templates
1336
+ $ packer build ubuntu-14.04-server-amd64-vagrant.json
1337
+ ```
1338
+
1339
+ ## Development
1340
+
1341
+ To work on the `vagrant-libvirt` plugin, clone this repository out, and use
1342
+ [Bundler](http://gembundler.com) to get the dependencies:
1343
+
1344
+ ```shell
1345
+ $ git clone https://github.com/vagrant-libvirt/vagrant-libvirt.git
1346
+ $ cd vagrant-libvirt
1347
+ $ bundle install
1348
+ ```
1349
+
1350
+ Once you have the dependencies, verify the unit tests pass with `rspec`:
1351
+
1352
+ ```shell
1353
+ $ bundle exec rspec spec/
1354
+ ```
1355
+
1356
+ If those pass, you're ready to start developing the plugin. You can test the
1357
+ plugin without installing it into your Vagrant environment by just creating a
1358
+ `Vagrantfile` in the top level of this directory (it is gitignored) that uses
1359
+ it. Don't forget to add following line at the beginning of your `Vagrantfile`
1360
+ while in development mode:
1361
+
1362
+ ```ruby
1363
+ Vagrant.require_plugin "vagrant-libvirt"
1364
+ ```
1365
+
1366
+ Now you can use bundler to execute Vagrant:
1367
+
1368
+ ```shell
1369
+ $ bundle exec vagrant up --provider=libvirt
1370
+ ```
1371
+
1372
+ **IMPORTANT NOTE:** bundle is crucial. You need to use bundled Vagrant.
1373
+
1374
+ ## Contributing
1375
+
1376
+ 1. Fork it
1377
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
1378
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
1379
+ 4. Push to the branch (`git push origin my-new-feature`)
1380
+ 5. Create new Pull Request