From d78d8969098bbe466d8381a90914a799bb563485 Mon Sep 17 00:00:00 2001 From: Erik van Pienbroek Date: Wed, 7 Sep 2016 17:57:08 +0200 Subject: [PATCH] Add disk property 'shareable' To simulate shared SAN storage an additional libvirt disk property needs to be set which disables caching. Also updated the documentation to document this new property and added an example on how to simulate shared SAN storage Closes #648 --- README.md | 15 ++++++++++++--- lib/vagrant-libvirt/action/create_domain.rb | 3 ++- lib/vagrant-libvirt/config.rb | 1 + lib/vagrant-libvirt/templates/domain.xml.erb | 3 +++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6a5f4d4..ea540ec 100644 --- a/README.md +++ b/README.md @@ -591,9 +591,9 @@ It has a number of options: [here](https://www.suse.com/documentation/sles11/book_kvm/data/sect1_chapter_book_kvm.html) for a fuller explanation). Defaults to *default*. * `allow_existing` - Set to true if you want to allow the VM to use a - pre-existing disk. This is useful for sharing disks between VMs, e.g. in - order to simulate shared SAN storage. Shared disks removed only manually. If - not exists - will created. If exists - using existed. + pre-existing disk. If the disk doesn't exist it will be created. + Disks with this option set to true need to be removed manually. +* `shareable` - Set to true if you want to simulate shared SAN storage. The following example creates two additional disks. @@ -606,6 +606,15 @@ Vagrant.configure("2") do |config| end ``` +For shared SAN storage to work the following example can be used: +```ruby +Vagrant.configure("2") do |config| + config.vm.provider :libvirt do |libvirt| + libvirt.storage :file, :size => '20G', :path => 'my_shared_disk.img', :allow_existing => true, :shareable => true, :type => 'raw' + end +end +``` + ### Reload behavior On `vagrant reload` the following additional disk attributes are updated in diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 0b1fe88..308b947 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -191,7 +191,8 @@ module VagrantPlugins @disks.each do |disk| msg = " -- Disk(#{disk[:device]}): #{disk[:absolute_path]}" - msg += ' (shared. Remove only manually)' if disk[:allow_existing] + msg += ' Shared' if disk[:shareable] + msg += ' (Remove only manually)' if disk[:allow_existing] msg += ' Not created - using existed.' if disk[:preexisting] env[:ui].info(msg) end diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 09c1e29..49802a4 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -376,6 +376,7 @@ module VagrantPlugins :bus => options[:bus], :cache => options[:cache] || 'default', :allow_existing => options[:allow_existing], + :shareable => options[:shareable], } @disks << disk # append diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index d35a595..bb572e3 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -75,6 +75,9 @@ + <% if d[:shareable] %> + + <% end %> <%# this will get auto generated by libvirt
-%>