From 07dbb907bd6a976883711209c6dc6043e978e13a Mon Sep 17 00:00:00 2001 From: Michal Sylwester Date: Mon, 30 Jan 2017 17:06:31 +0100 Subject: [PATCH] Allow custom name for disk device This is needed for example for xen in full virtualisation mode as it won't allow the default vda --- README.md | 4 ++++ lib/vagrant-libvirt/action/create_domain.rb | 1 + lib/vagrant-libvirt/config.rb | 3 +++ lib/vagrant-libvirt/templates/domain.xml.erb | 2 +- spec/support/environment_helper.rb | 2 +- spec/unit/templates/domain_spec.rb | 1 + 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 960514b..e80ffd0 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,10 @@ end _target_](http://libvirt.org/formatdomain.html#elementsDisks). NOTE: this option applies only to disks associated with a box image. To set the bus type on additional disks, see the [Additional Disks](#additional-disks) section. +* `disk_device` - The disk device to emulate. Defaults to vda if not + set, which should be fine for paravirtualized guests, but some fully + virtualized guests may require hda. NOTE: this option also applies only to + disks associated with a box image. * `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 diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 750b3ce..ece8649 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -42,6 +42,7 @@ module VagrantPlugins @machine_type = config.machine_type @machine_arch = config.machine_arch @disk_bus = config.disk_bus + @disk_device = config.disk_device @nested = config.nested @memory_size = config.memory.to_i * 1024 @management_network_mac = config.management_network_mac diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 939dd02..9cf6886 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -71,6 +71,7 @@ module VagrantPlugins attr_accessor :machine_arch attr_accessor :machine_virtual_size attr_accessor :disk_bus + attr_accessor :disk_device attr_accessor :nic_model_type attr_accessor :nested attr_accessor :volume_cache @@ -170,6 +171,7 @@ module VagrantPlugins @machine_arch = UNSET_VALUE @machine_virtual_size = UNSET_VALUE @disk_bus = UNSET_VALUE + @disk_device = UNSET_VALUE @nic_model_type = UNSET_VALUE @nested = UNSET_VALUE @volume_cache = UNSET_VALUE @@ -569,6 +571,7 @@ module VagrantPlugins @machine_arch = nil if @machine_arch == UNSET_VALUE @machine_virtual_size = nil if @machine_virtual_size == UNSET_VALUE @disk_bus = 'virtio' if @disk_bus == UNSET_VALUE + @disk_device = 'vda' if @disk_device == UNSET_VALUE @nic_model_type = 'virtio' if @nic_model_type == UNSET_VALUE @nested = false if @nested == UNSET_VALUE @volume_cache = 'default' if @volume_cache == UNSET_VALUE diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index e4a270a..ade0914 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -74,7 +74,7 @@ <%# we need to ensure a unique target dev -%> - + <% end %> <%# additional disks -%> diff --git a/spec/support/environment_helper.rb b/spec/support/environment_helper.rb index 5cebb86..4d3c94c 100644 --- a/spec/support/environment_helper.rb +++ b/spec/support/environment_helper.rb @@ -18,7 +18,7 @@ class EnvironmentHelper 1024 end - %w(cpus cpu_mode loader boot_order machine_type disk_bus nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms driver).each do |name| + %w(cpus cpu_mode loader boot_order machine_type disk_bus disk_device nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms driver).each do |name| define_method(name.to_sym) do nil end diff --git a/spec/unit/templates/domain_spec.rb b/spec/unit/templates/domain_spec.rb index d79e433..215339c 100644 --- a/spec/unit/templates/domain_spec.rb +++ b/spec/unit/templates/domain_spec.rb @@ -36,6 +36,7 @@ describe 'templates/domain' do domain.instance_variable_set('@domain_volume_path', '/var/lib/libvirt/images/test.qcow2') domain.instance_variable_set('@domain_volume_cache', 'unsafe') domain.disk_bus = 'ide' + domain.disk_device = 'vda' domain.storage(:file, path: 'test-disk1.qcow2') domain.storage(:file, path: 'test-disk2.qcow2') domain.disks.each do |disk|