2013-03-27 00:55:30 +01:00
# Vagrant Libvirt Provider
2014-05-18 17:27:32 -05:00
This is a [Vagrant ](http://www.vagrantup.com ) plugin that adds an
2013-03-27 00:55:30 +01:00
[Libvirt ](http://libvirt.org ) provider to Vagrant, allowing Vagrant to
control and provision machines via Libvirt toolkit.
2014-05-18 17:27:32 -05:00
**Note:** Actual version is still a development one. Feedback is
2013-04-02 20:06:52 +02:00
welcome and can help a lot :-)
2013-03-27 00:55:30 +01:00
2015-09-26 20:43:24 +03:00
- [Features ](#features )
- [Future work ](#future-work )
- [Installation ](#installation )
- [Possible problems with plugin installation on Linux ](#possible-problems-with-plugin-installation-on-linux )
- [Vagrant Project Preparation ](#vagrant-project-preparation )
- [Add Box ](#add-box )
- [Create Vagrantfile ](#create-vagrantfile )
- [Start VM ](#start-vm )
- [How Project Is Created ](#how-project-is-created )
- [Libvirt Configuration ](#libvirt-configuration )
- [Provider Options ](#provider-options )
- [Domain Specific Options ](#domain-specific-options )
- [Reload behavior ](#reload-behavior )
- [Networks ](#networks )
- [Private Network Options ](#private-network-options )
- [Public Network Options ](#public-network-options )
- [Management Network ](#management-network )
- [Additional Disks ](#additional-disks )
- [CDROMs ](#cdroms )
- [Input ](#input )
- [No box and PXE boot ](#no-box-and-pxe-boot )
- [SSH Access To VM ](#ssh-access-to-vm )
- [Forwarded Ports ](#forwarded-ports )
- [Synced Folders ](#synced-folders )
- [Customized Graphics ](#customized-graphics )
- [Box Format ](#box-format )
- [Create Box ](#create-box )
- [Development ](#development )
- [Contributing ](#contributing )
2015-09-25 16:39:20 +03:00
2014-02-24 17:24:22 +01:00
## Features
2013-03-27 00:55:30 +01:00
2014-05-06 21:01:43 +01:00
* Control local Libvirt hypervisors.
2015-05-17 19:47:07 +02:00
* Vagrant `up` , `destroy` , `suspend` , `resume` , `halt` , `ssh` , `reload` , `package` and `provision` commands.
2013-03-27 00:55:30 +01:00
* Upload box image (qcow2 format) to Libvirt storage pool.
* Create volume as COW diff image for domains.
2013-05-10 15:11:13 +02:00
* Create private networks.
2013-03-27 00:55:30 +01:00
* Create and boot Libvirt domains.
* SSH into domains.
2013-05-10 15:11:13 +02:00
* Setup hostname and network interfaces.
2013-03-27 00:55:30 +01:00
* Provision domains with any built-in Vagrant provisioner.
2014-05-03 17:14:15 -05:00
* Synced folder support via `rsync` , `nfs` or `9p` .
2014-05-06 21:01:43 +01:00
* Snapshots via [sahara ](https://github.com/jedi4ever/sahara ).
* Package caching via [vagrant-cachier ](http://fgrehm.viewdocs.io/vagrant-cachier/ ).
* Use boxes from other Vagrant providers via [vagrant-mutate ](https://github.com/sciurus/vagrant-mutate ).
2015-08-14 14:33:01 +02:00
* Support VMs with no box for PXE boot purposes (Vagrant 1.6 and up)
2013-03-27 00:55:30 +01:00
2013-04-02 20:06:52 +02:00
## Future work
* Take a look at [open issues ](https://github.com/pradels/vagrant-libvirt/issues?state=open ).
2013-03-27 00:55:30 +01:00
2013-04-02 20:06:52 +02:00
## Installation
2014-05-18 17:27:32 -05:00
First, you should have libvirt installed if you plan to run VMs on your local system. For instructions, refer to your linux distribution's documentation,
2015-02-13 15:49:33 -05:00
Next, you must have [Vagrant installed ](http://docs.vagrantup.com/v2/installation/index.html ). Vagrant-libvirt supports Vagrant 1.5, 1.6 and 1.7.
2014-05-18 17:27:32 -05:00
Now you're ready to install vagrant-libvirt using standard [Vagrant plugin ](http://docs.vagrantup.com/v2/plugins/usage.html ) installation methods.
2013-03-27 00:55:30 +01:00
```
$ vagrant plugin install vagrant-libvirt
```
2013-05-10 15:11:13 +02:00
### Possible problems with plugin installation on Linux
2013-03-27 00:55:30 +01:00
2013-04-11 17:03:24 +02:00
In case of problems with building nokogiri and ruby-libvirt gem, install
missing development libraries for libxslt, libxml2 and libvirt.
2013-03-27 00:55:30 +01:00
In Ubuntu, Debian, ...
```
2015-05-04 19:44:27 +08:00
$ sudo apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev
2013-03-27 00:55:30 +01:00
```
In RedHat, Centos, Fedora, ...
```
2015-05-17 19:47:07 +02:00
# yum install libxslt-devel libxml2-devel libvirt-devel libguestfs-tools-c
2013-03-27 00:55:30 +01:00
```
2015-05-15 12:38:50 +02:00
If have problem with installation - check your linker. It should be ld.gold:
```
sudo alternatives --set ld /usr/bin/ld.gold
# OR
sudo ln -fs /usr/bin/ld.gold /usr/bin/ld
2013-03-27 00:55:30 +01:00
```
2013-04-02 20:06:52 +02:00
## Vagrant Project Preparation
2013-03-27 00:55:30 +01:00
2014-05-11 14:46:45 -05:00
### Add Box
2013-03-27 00:55:30 +01:00
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. This is just an example of Libvirt CentOS 6.4 box available:
```
2015-05-12 09:38:17 +02:00
vagrant box add fedora21 http://citozin.com/fedora21.box
2015-04-19 11:13:09 +02:00
# or
2015-04-04 22:13:33 +02:00
vagrant box add centos64 http://citozin.com/centos64.box
2013-03-27 00:55:30 +01:00
```
2014-05-11 14:46:45 -05:00
### Create Vagrantfile
2013-05-10 15:11:13 +02:00
And then make a Vagrantfile that looks like the following, filling in your
information where necessary. In example below, VM named test_vm is created from
2014-05-11 14:40:51 -05:00
centos64 box.
2013-03-27 00:55:30 +01:00
2013-04-02 20:06:52 +02:00
```ruby
2013-03-27 00:55:30 +01:00
Vagrant.configure("2") do |config|
config.vm.define :test_vm do |test_vm|
test_vm.vm.box = "centos64"
end
end
```
2013-05-10 15:11:13 +02:00
2014-05-11 14:46:45 -05:00
### Start VM
In prepared project directory, run following command:
```
$ vagrant up --provider=libvirt
```
Vagrant needs to know that we want to use Libvirt and not default VirtualBox.
That's why there is `--provider=libvirt` option specified. Other way to tell
Vagrant to use Libvirt provider is to setup environment variable
2015-04-13 17:30:01 +02:00
2014-05-11 14:46:45 -05:00
`export VAGRANT_DEFAULT_PROVIDER=libvirt` .
### How Project Is Created
Vagrant goes through steps below when creating new project:
1. Connect to Libvirt localy 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.
4. Create and start new domain on Libvirt host.
5. Check for DHCP lease from dnsmasq server.
6. Wait till SSH is available.
7. Sync folders and run Vagrant provisioner on new domain if
setup in Vagrantfile.
### Libvirt Configuration
### Provider Options
2013-03-27 00:55:30 +01:00
2014-06-09 00:12:50 -07:00
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 URI ](http://libvirt.org/uri.html ):
2013-03-27 00:55:30 +01:00
2014-05-10 22:42:38 -05:00
* `driver` - A hypervisor name to access. For now only kvm and qemu are supported.
2013-03-27 00:55:30 +01:00
* `host` - The name of the server, where libvirtd is running.
2015-09-26 20:43:24 +03:00
* `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 address of a started VM otherwise.
2013-03-27 00:55:30 +01:00
* `username` - Username and password to access Libvirt.
* `password` - Password to access Libvirt.
2015-04-16 09:12:19 +02:00
* `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.
2014-03-11 14:47:36 +01:00
* `socket` - Path to the libvirt unix socket (eg: /var/run/libvirt/libvirt-sock)
2014-06-09 00:12:50 -07:00
* `uri` - For advanced usage. Directly specifies what libvirt connection URI vagrant-libvirt should use. Overrides all other connection configuration options.
Connection-independent options:
2013-11-19 19:41:29 +01:00
* `storage_pool_name` - Libvirt storage pool name, where box image and instance snapshots will be stored.
2013-03-27 00:55:30 +01:00
2014-05-11 14:40:51 -05:00
Here is an example of how to set these options.
```ruby
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.host = "example.com"
end
end
```
2013-04-11 17:03:24 +02:00
### Domain Specific Options
2014-01-06 12:31:49 -06:00
* `disk_bus` - The type of disk device to emulate. Defaults to virtio if not set. Possible values are documented in libvirt's [description for _target_ ](http://libvirt.org/formatdomain.html#elementsDisks ).
2015-09-26 20:43:24 +03:00
* `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 ).
2013-04-11 17:03:24 +02:00
* `memory` - Amount of memory in MBytes. Defaults to 512 if not set.
* `cpus` - Number of virtual cpus. Defaults to 1 if not set.
2013-05-10 15:11:13 +02:00
* `nested` - [Enable nested virtualization ](https://github.com/torvalds/linux/blob/master/Documentation/virtual/kvm/nested-vmx.txt ). Default is false.
2015-09-26 20:43:24 +03:00
* `cpu_mode` - [CPU emulation mode ](https://libvirt.org/formatdomain.html#elementsCPU ). Defaults to 'host-model' if not set. Allowed values: host-model, host-passthrough.
2015-08-03 16:24:55 -05:00
* `loader` - Sets path to custom UEFI loader.
2013-09-16 23:26:39 +03:00
* `volume_cache` - Controls the cache mechanism. Possible values are "default", "none", "writethrough", "writeback", "directsync" and "unsafe". [See driver->cache in libvirt documentation ](http://libvirt.org/formatdomain.html#elementsDisks ).
2014-05-06 21:01:43 +01:00
* `kernel` - To launch the guest with a kernel residing on host filesystems. Equivalent to qemu `-kernel` .
* `initrd` - To specify the initramfs/initrd to use for the guest. Equivalent to qemu `-initrd` .
2014-08-06 18:22:57 -06:00
* `random_hostname` - To create a domain name with extra information on the end to prevent hostname conflicts.
2014-05-06 21:01:43 +01:00
* `cmd_line` - Arguments passed on to the guest kernel initramfs or initrd to use. Equivalent to qemu `-append` .
2015-05-07 00:52:32 +09:00
* `graphics_type` - Sets the protocol used to expose the guest display. Defaults to `vnc` . Possible values are "sdl", "curses", "none", "gtk", "vnc" or "spice".
2014-09-29 08:31:23 +02:00
* `graphics_port` - Sets the port for the display protocol to bind to. Defaults to 5900.
2014-09-28 10:29:04 -04:00
* `graphics_ip` - Sets the IP for the display protocol to bind to. Defaults to "127.0.0.0.1".
2014-09-29 08:31:23 +02:00
* `graphics_passwd` - Sets the password for the display protocol. Working for vnc and spice. by default working without passsword.
2015-09-26 20:43:24 +03:00
* `graphics_autoport` - Sets autoport for graphics, libvirt in this case ignores graphics_port value, Defaults to 'yes'. Possible value are "yes" and "no"
2015-03-26 08:07:27 +01:00
* `keymap` - Set keymap for vm. default: en-us
2015-09-26 20:43:24 +03:00
* `video_type` - Sets the graphics card type exposed to the guest. Defaults to "cirrus". [Possible values ](http://libvirt.org/formatdomain.html#elementsVideo ) are "vga", "cirrus", "vmvga", "xen", "vbox", or "qxl".
2014-09-28 10:29:04 -04:00
* `video_vram` - Used by some graphics card types to vary the amount of RAM dedicated to video. Defaults to 9216.
2015-03-21 19:31:45 +01:00
* `machine` - Sets machine type. Equivalent to qemu `-machine` . Use `qemu-system-x86_64 -machine help` to get a list of supported machines.
2015-05-17 21:20:22 +02:00
* `machine_arch` - Sets machine architecture. This helps libvirt to determine the correct emulator type. Possible values depend on your version of qemu. For possible values, see which emulator executable `qemu-system-*` your system provides. Common examples are `aarch64` , `alpha` , `arm` , `cris` , `i386` , `lm32` , `m68k` , `microblaze` , `microblazeel` , `mips` , `mips64` , `mips64el` , `mipsel` , `moxie` , `or32` , `ppc` , `ppc64` , `ppcemb` , `s390x` , `sh4` , `sh4eb` , `sparc` , `sparc64` , `tricore` , `unicore32` , `x86_64` , `xtensa` , `xtensaeb` .
2015-06-29 17:14:13 +01:00
* `machine_virtual_size` - Sets the disk size in GB for the machine overriding the default specified in the box. Allows boxes to defined with a minimal size disk by default and to be grown to a larger size at creation time. Will ignore sizes smaller than the size specified by the box metadata. Note that currently there is no support for automatically resizing the filesystem to take advantage of the larger disk.
2015-08-11 00:39:53 +02:00
* `boot` - Change the boot order and enables the boot menu. Possible options are "hd", "network", "cdrom". Defaults to "hd" with boot menu disabled. When "network" is set without "hd", only all NICs will be tried; see below for more detail.
2015-07-13 06:37:51 -04:00
* `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.
2015-09-26 20:43:24 +03:00
* `uuid` - Force a domain UUID. Defaults to autogenerated value by libvirt if not set.
2014-01-18 10:55:56 +01:00
2013-04-11 17:03:24 +02:00
Specific domain settings can be set for each domain separately in multi-VM
environment. Example below shows a part of Vagrantfile, where specific options
are set for dbserver domain.
```ruby
Vagrant.configure("2") do |config|
config.vm.define :dbserver do |dbserver|
dbserver.vm.box = "centos64"
dbserver.vm.provider :libvirt do |domain|
domain.memory = 2048
domain.cpus = 2
2013-07-24 15:44:30 +02:00
domain.nested = true
2014-01-06 12:31:49 -06:00
domain.volume_cache = 'none'
2013-04-11 17:03:24 +02:00
end
end
2013-05-10 15:11:13 +02:00
# ...
2013-04-11 17:03:24 +02:00
```
2015-06-02 20:31:21 -05:00
The following example shows part of a Vagrantfile that enables the VM to
boot from a network interface first and a hard disk second. This could be
2015-08-03 09:32:56 -04:00
used to run VMs that are meant to be a PXE booted machines. Be aware that
2015-08-11 00:39:53 +02:00
if `hd` is not specified as a boot option, it will never be tried.
2015-06-02 20:31:21 -05:00
```ruby
Vagrant.configure("2") do |config|
config.vm.define :pxeclient do |pxeclient|
pxeclient.vm.box = "centos64"
pxeclient.vm.provider :libvirt do |domain|
domain.boot 'network'
domain.boot 'hd'
end
end
# ...
```
2015-09-26 20:43:24 +03:00
#### Reload behavior
On vagrant reload the following domain specific attributes are updated in defined domain:
* `disk_bus` - Is updated only on disks. It skips cdroms.
* `nic_model_type` - Updated.
* `memory` - Updated.
* `cpus` - Updated.
* `nested` - Updated.
* `cpu_mode` - Updated. Pay attention that custom mode is not supported.
* `graphics_type` - Updated.
* `graphics_port` - Updated.
* `graphics_ip` - Updated.
* `graphics_passwd` - Updated.
* `graphics_autoport` - Updated.
* `keymap` - Updated.
* `video_type` - Updated.
* `video_vram` - Updated.
2013-03-27 00:55:30 +01:00
## Networks
2013-05-10 15:11:13 +02:00
Networking features in the form of `config.vm.network` support private networks
2015-07-11 10:49:00 -04:00
concept. It supports both the virtual network switch routing types and the point to
2015-08-03 09:32:56 -04:00
point Guest OS to Guest OS setting using UDP/Mcast/TCP tunnel interfaces.
2015-07-11 10:49:00 -04:00
http://wiki.libvirt.org/page/VirtualNetworking
2015-08-03 09:32:56 -04:00
2015-07-11 10:49:00 -04:00
https://libvirt.org/formatdomain.html#elementsNICSTCP
2013-09-10 00:12:24 -07:00
2015-08-03 09:32:56 -04:00
http://libvirt.org/formatdomain.html#elementsNICSMulticast
http://libvirt.org/formatdomain.html#elementsNICSUDP _(in libvirt v1.2.20 and higher)_
2013-09-10 00:12:24 -07:00
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.
http://www.libvirt.org/formatdomain.html#elementsNICSDirect
2013-05-10 15:11:13 +02:00
2015-07-11 10:49:00 -04:00
2013-05-10 15:11:13 +02:00
An examples of network interface definitions:
```ruby
2015-07-11 10:49:00 -04:00
# Private network using virtual network switching
2013-05-10 15:11:13 +02:00
config.vm.define :test_vm1 do |test_vm1|
2013-09-17 00:23:24 +03:00
test_vm1.vm.network :private_network, :ip => "10.20.30.40"
2013-05-10 15:11:13 +02:00
end
2013-09-10 00:12:24 -07:00
2015-07-11 10:49:00 -04:00
# Private network. Point to Point between 2 Guest OS using a TCP tunnel
# Guest 1
config.vm.define :test_vm1 do |test_vm1|
test_vm1.vm.network :private_network,
2015-08-03 09:32:56 -04:00
:libvirt__tunnel_type => 'server',
2015-07-11 10:49:00 -04:00
# default is 127.0.0.1 if omitted
2015-08-03 09:32:56 -04:00
# :libvirt__tunnel_ip => '127.0.0.1',
:libvirt__tunnel_port => '11111'
2015-07-11 10:49:00 -04:00
# Guest 2
2015-07-11 10:53:23 -04:00
config.vm.define :test_vm2 do |test_vm2|
2015-07-11 10:55:21 -04:00
test_vm2.vm.network :private_network,
2015-08-03 09:32:56 -04:00
:libvirt__tunnel_type => 'client',
2015-07-11 10:49:00 -04:00
# default is 127.0.0.1 if omitted
2015-08-03 09:32:56 -04:00
# :libvirt__tunnel_ip => '127.0.0.1',
:libvirt__tunnel_port => '11111'
2015-07-11 10:49:00 -04:00
2013-09-10 00:12:24 -07:00
# Public Network
config.vm.define :test_vm1 do |test_vm1|
2015-04-09 07:50:28 +02:00
test_vm1.vm.network :public_network,
:dev => "virbr0",
:mode => "bridge",
:type => "bridge"
2013-09-10 00:12:24 -07:00
end
2013-05-10 15:11:13 +02:00
```
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.
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
to the internet (if hypervisor can). And by default, DHCP is offering addresses
on newly created networks.
2013-09-10 00:12:24 -07:00
The second interface is created and bridged into the physical device 'eth0'.
This mechanism uses the macvtap Kernel driver and therefore does not require
an existing bridge device. This configuration assumes that DHCP and DNS services
are being provided by the public network. This public interface should be reachable
2013-09-17 00:23:24 +03:00
by anyone with access to the public network.
2013-09-10 00:12:24 -07:00
2013-05-10 15:11:13 +02:00
### Private Network Options
2013-09-10 00:12:24 -07:00
*Note: These options are not applicable to public network interfaces.*
2013-05-10 15:11:13 +02:00
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,
network 'default' is used.
* `:libvirt__netmask` - Used only together with `:ip` option. Default is
'255.255.255.0'.
2015-05-06 19:51:26 +02:00
* `:libvirt__host_ip` - Adress to use for the host (not guest).
Default is first possible address (after network address).
2013-05-10 15:11:13 +02:00
* `:libvirt__dhcp_enabled` - If DHCP will offer addresses, or not. Used only
when creating new network. Default is true.
2015-05-06 19:51:26 +02:00
* `:libvirt__dhcp_start` - First address given out via DHCP.
Default is third address in range (after network name and gateway).
* `:libvirt__dhcp_stop` - Last address given out via DHCP.
Default is last possible address in range (before broadcast address).
2015-04-17 16:59:16 +10:00
* `:libvirt__dhcp_bootp_file` - The file to be used for the boot image.
Used only when dhcp is enabled.
* `:libvirt__dhcp_bootp_server` - The server that runs the DHCP server.
Used only when dhcp is enabled.By default is the same host that runs the DHCP server.
2013-05-10 15:11:13 +02:00
* `:libvirt__adapter` - Number specifiyng sequence number of interface.
2015-04-09 08:19:31 +02:00
* `:libvirt__forward_mode` - Specify one of `veryisolated` , `none` , `nat` or `route` options.
2013-07-24 15:44:30 +02:00
This option is used only when creating new network. Mode `none` will create
isolated network without NATing or routing outside. You will want to use
NATed forwarding typically to reach networks outside of hypervisor. Routed
forwarding is typically useful to reach other networks within hypervisor.
2015-04-09 08:19:31 +02:00
`veryisolated` described [here ](https://libvirt.org/formatnetwork.html#examplesNoGateway ).
2013-07-24 15:44:30 +02:00
By default, option `nat` is used.
* `:libvirt__forward_device` - Name of interface/device, where network should
be forwarded (NATed or routed). Used only when creating new network. By
default, all physical interfaces are used.
2015-08-03 09:32:56 -04:00
* `:libvirt__tunnel_type` - Set to 'udp' if using UDP unicast tunnel mode (libvirt v1.2.20 or higher).
Set this to either "server" or "client" for tcp tunneling. Set this to 'mcast' if using multicast
tunneling. This configuration type uses tunnels to
2015-07-11 10:49:00 -04:00
generate point to point connections between Guests. Useful for Switch VMs like
2015-08-03 09:32:56 -04:00
Cumulus Linux. No virtual switch setting like "libvirt__network_name" applies with
2015-07-11 10:49:00 -04:00
tunnel interfaces and will be ignored if configured.
2015-08-03 09:32:56 -04:00
* `: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 `<source address="XXX">` of the
interface xml configuration.
* `:libvirt__tunnel_port` - Sets the source port the tcp/udp/mcast tunnel
with use. This port information is placed in the `<source port=XXX/>` section of
interface xml configuration.
* `:libvirt__tunnel_local_port` - Sets the local port used by the udp tunnel
interface type. It populates the port field in the `<local port=XXX">` section of the
interface xml configuration. _(This feature only works in 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 `<local address=XXX">` section of
the interface xml configuration. _(This feature only works in libvirt 1.2.20 and higher)_
2013-09-17 00:23:24 +03:00
* `:mac` - MAC address for the interface.
2015-04-14 22:23:44 +02:00
* `: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
2013-03-27 00:55:30 +01:00
2015-04-01 14:49:35 +02:00
When the option `:libvirt__dhcp_enabled` is to to 'false' it shouldn't matter
whether the virtual network contains a DHCP server or not and vagrant-libvirt
should not fail on it. The only situation where vagrant-libvirt should fail
is when DHCP is requested but isn't configured on a matching already existing
virtual network.
2013-09-10 22:45:40 -07:00
### Public Network Options
2014-05-06 21:01:43 +01:00
* `:dev` - Physical device that the public interface should use. Default is 'eth0'.
2013-09-10 22:45:40 -07:00
* `:mode` - The mode in which the public interface should operate in. Supported
modes are available from the [libvirt documentation ](http://www.libvirt.org/formatdomain.html#elementsNICSDirect ).
Default mode is 'bridge'.
2015-04-09 07:50:28 +02:00
* `:type` - is type of interface.(`<interface type="#{@type}">` )
2013-09-17 00:23:24 +03:00
* `:mac` - MAC address for the interface.
2014-11-19 14:22:41 +09:00
* `:ovs` - Support to connect to an open vSwitch bridge device. Default is 'false'.
2013-09-10 22:45:40 -07:00
2014-01-20 15:55:25 -06:00
### Management 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. 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 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'.
2013-03-27 00:55:30 +01:00
2014-01-20 15:55:25 -06:00
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. But we do know the MAC address of the virtual machine's interface on
the management network. Libvirt is closely connected with dnsmasq, which acts as
a DHCP server. dnsmasq writes lease information in the `/var/lib/libvirt/dnsmasq`
directory. Vagrant-libvirt looks for the MAC address in this file and extracts
the corresponding IP address.
2013-03-27 00:55:30 +01:00
2014-05-11 14:40:51 -05:00
## Additional Disks
You can create and attach additional disks to a VM via `libvirt.storage :file` . It has a number of options:
* `path` - Location of the disk image. If unspecified, a path is automtically chosen in the same storage pool as the VMs primary disk.
* `device` - Name of the device node the disk image will have in the VM, e.g. *vdb* . If unspecified, the next available device is chosen.
* `size` - Size of the disk image. If unspecified, defaults to 10G.
* `type` - Type of disk image to create. Defaults to *qcow2* .
2014-10-28 21:31:06 +02:00
* `bus` - Type of bus to connect device to. Defaults to *virtio* .
2014-10-26 23:47:50 +00:00
* `cache` - Cache mode to use, e.g. `none` , `writeback` , `writethrough` (see the [libvirt documentation for possible values ](http://libvirt.org/formatdomain.html#elementsDisks ) or [here ](https://www.suse.com/documentation/sles11/book_kvm/data/sect1_chapter_book_kvm.html ) for a fuller explanation). Defaults to *default* .
2015-08-25 10:44:16 -04:00
* `allow_existing` - Set to true if you want to allow the VM to use a pre-existing disk. This is useful for sharing disks between VMs, e.g. in order to simulate shared SAN storage. Shared disks removed only manually. If not exists - will created. If exists - using existed.
2014-05-11 14:40:51 -05:00
The following example creates two additional disks.
```ruby
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.storage :file, :size => '20G'
libvirt.storage :file, :size => '40G', :type => 'raw'
end
end
```
2015-04-10 15:42:35 -05:00
## CDROMs
2015-04-10 15:45:55 -05:00
You can attach up to four (4) CDROMs to a VM via `libvirt.storage :file, :device => :cdrom` . Available options are:
2015-04-10 15:42:35 -05:00
* `path` - The path to the iso to be used for the CDROM drive.
* `dev` - The device to use (`hda` , `hdb` , `hdc` , or `hdd` ). This will be automatically determined if unspecified.
* `bus` - The bus to use for the CDROM drive. Defaults to `ide`
The following example creates three CDROM drives in the VM:
```ruby
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.storage :file, :device => :cdrom, :path => '/path/to/iso1.iso'
libvirt.storage :file, :device => :cdrom, :path => '/path/to/iso2.iso'
libvirt.storage :file, :device => :cdrom, :path => '/path/to/iso3.iso'
end
end
```
2015-08-05 10:37:19 -05:00
## Input
2015-08-05 10:49:12 -05:00
You can specify multiple inputs to the VM via `libvirt.input` . Available options are
2015-08-05 10:37:19 -05:00
listed below. Note that both options are required:
* `type` - The type of the input
* `bus` - The bust of the input
```ruby
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
# this is the default
# libvirt.input :type => "mouse", :bus => "ps2"
# very useful when having mouse issues when viewing VM via VNC
2015-08-05 10:38:35 -05:00
libvirt.input :type => "tablet", :bus => "usb"
2015-08-05 10:37:19 -05:00
end
end
```
2015-08-10 17:10:23 +02:00
## No box and PXE boot
There is support for PXE booting VMs with no disks as well as PXE booting VMs with blank disks. There are some limitations:
2015-08-14 14:33:01 +02:00
* Requires Vagrant 1.6.0 or newer
2015-08-10 17:10:23 +02:00
* No provisioning scripts are ran
* No network configuration is being applied to the VM
* No SSH connection can be made
2015-08-03 09:32:56 -04:00
* ```vagrant halt` `` will only work cleanly if the VM handles ACPI shutdown signals
2015-08-10 17:10:23 +02:00
In short, VMs without a box can be created, halted and destroyed but all other functionality cannot be used.
An example for a PXE booted VM with no disks whatsoever:
2015-09-25 15:36:24 +03:00
```ruby
2015-08-10 17:10:23 +02:00
Vagrant.configure("2") do |config|
config.vm.define :pxeclient do |pxeclient|
pxeclient.vm.provider :libvirt do |domain|
domain.boot 'network'
end
end
2015-09-25 15:36:24 +03:00
end
```
2015-08-10 17:10:23 +02:00
2015-09-25 15:36:24 +03:00
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:
2015-08-11 00:39:53 +02:00
2015-09-25 15:36:24 +03:00
```ruby
2015-08-11 00:39:53 +02:00
Vagrant.configure("2") do |config|
config.vm.define :pxeclient do |pxeclient|
pxeclient.vm.provider :libvirt do |domain|
domain.storage :file, :size => '100G', :type => 'qcow2'
domain.boot 'network'
domain.boot 'hd'
end
end
2015-09-25 15:36:24 +03:00
end
```
2015-08-11 00:39:53 +02:00
2013-07-24 15:44:30 +02:00
## SSH Access To VM
2014-09-28 14:51:33 -05:00
vagrant-libvirt supports vagrant's [standard ssh settings ](https://docs.vagrantup.com/v2/vagrantfile/ssh_settings.html ).
2013-07-24 15:44:30 +02:00
2014-01-24 07:48:00 -08:00
## Forwarded Ports
2015-03-26 08:07:27 +01:00
vagrant-libvirt supports Forwarded Ports via ssh port forwarding. Please note that due to a well known limitation only the TCP protocol is supported. For each `forwarded_port` directive you specify in your Vagrantfile, vagrant-libvirt will maintain an active ssh process for the lifetime of the VM.
2014-01-24 07:48:00 -08:00
2014-09-16 18:01:46 +02:00
vagrant-libvirt supports an additional `forwarded_port` option
`gateway_ports` which defaults to `false` , but can be set to `true` if
you want the forwarded port to be accessible from outside the Vagrant
host. In this case you should also set the `host_ip` option to `'*'`
since it defaults to `'localhost'` .
2013-03-27 00:55:30 +01:00
## Synced Folders
2014-05-03 17:14:15 -05:00
vagrant-libvirt supports bidirectional synced folders via nfs or 9p and
unidirectional via rsync. The default is nfs. Vagrant automatically syncs
the project folder on the host to */vagrant* in the guest. You can also
configure additional synced folders.
2013-03-27 00:55:30 +01:00
2014-05-03 17:14:15 -05:00
You can change the synced folder type for */vagrant* by explicity configuring
it an setting the type, e.g.
config.vm.synced_folder './', '/vagrant', type: 'rsync'
2013-03-27 00:55:30 +01:00
2015-05-17 19:47:07 +02:00
or
2015-05-17 10:34:58 +02:00
config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "squash", owner: "vagrant"
2013-03-27 00:55:30 +01:00
2015-05-18 07:48:39 +02:00
**SECURITY NOTE:** for remote libvirt, nfs synced folders requires a bridged public network interface and you must connect to libvirt via ssh.
2015-05-18 11:46:04 +08:00
2014-09-28 10:29:04 -04:00
## Customized Graphics
vagrant-libvirt supports customizing the display and video settings of the
managed guest. This is probably most useful for VNC-type displays with multiple
guests. It lets you specify the exact port for each guest to use deterministically.
Here is an example of using custom display options:
```ruby
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.graphics_port = 5901
libvirt.graphics_ip = '0.0.0.0'
libvirt.video_type = 'qxl'
end
end
```
2013-05-14 01:16:28 +02:00
2013-04-02 20:06:52 +02:00
## Box Format
You can view an example box in the [example_box/directory ](https://github.com/pradels/vagrant-libvirt/tree/master/example_box ). That directory also contains instructions on how to build a box.
The box is a tarball containing:
* qcow2 image file named `box.img` .
* `metadata.json` file describing box image (provider, virtual_size, format).
* `Vagrantfile` that does default settings for the provider-specific configuration for this provider.
2015-04-09 08:24:42 +02:00
## Create Box
2015-04-17 16:47:38 +02:00
To create a vagrant-libvirt box from a qcow2 image, run `create_box.sh` (located in the tools directory):
2015-04-09 08:24:42 +02:00
2015-04-17 16:47:38 +02:00
```$ create_box.sh ubuntu14.qcow2` ``
2015-04-09 08:24:42 +02:00
2015-04-17 16:47:38 +02:00
You can also create a box by using [Packer ](https://packer.io ). Packer templates for use with vagrant-libvirt are available at https://github.com/jakobadam/packer-qemu-templates. After cloning that project you can build a vagrant-libvirt box by running:
2015-04-09 08:24:42 +02:00
2015-04-17 16:47:38 +02:00
``` ~/packer-qemu-templates/ubuntu$ packer build ubuntu-14.04-server-amd64-vagrant.json` ``
2015-04-09 08:24:42 +02:00
2013-03-27 00:55:30 +01:00
## Development
To work on the `vagrant-libvirt` plugin, clone this repository out, and use
[Bundler ](http://gembundler.com ) to get the dependencies:
```
2013-04-02 20:06:52 +02:00
$ git clone https://github.com/pradels/vagrant-libvirt.git
$ cd vagrant-libvirt
$ bundle install
2013-03-27 00:55:30 +01:00
```
Once you have the dependencies, verify the unit tests pass with `rake` :
```
$ bundle exec rake
```
If those pass, you're ready to start developing the plugin. You can test
the plugin without installing it into your Vagrant environment by just
creating a `Vagrantfile` in the top level of this directory (it is gitignored)
2013-04-10 17:34:09 +02:00
that uses it. Don't forget to add following line at the beginning of your
`Vagrantfile` while in development mode:
```ruby
Vagrant.require_plugin "vagrant-libvirt"
```
Now you can use bundler to execute Vagrant:
2013-03-27 00:55:30 +01:00
```
$ bundle exec vagrant up --provider=libvirt
```
2013-12-10 16:43:26 +01:00
IMPORTANT NOTE: bundle is crucial. You need to use bundled vagrant.
2013-04-02 20:06:52 +02:00
## Contributing
2014-05-06 21:01:43 +01:00
1. Fork it.
2. Create your feature branch (`git checkout -b my-new-feature` ).
3. Commit your changes (`git commit -am 'Add some feature'` ).
4. Push to the branch (`git push origin my-new-feature` ).
5. Create new Pull Request.