From d82c1a3f95f7f680776479856a6d16ea95b307e3 Mon Sep 17 00:00:00 2001 From: James Johnson Date: Wed, 5 Aug 2015 10:37:19 -0500 Subject: [PATCH 1/5] Can now specify inputs for the VM. E.g. ```ruby Vagrant.configure("2") do |config| config.vm.provider :libvirt do |libvirt| # very useful when having mouse issues when viewing VMs via VNC libvirt.input :type => "tablet", :bus => "usb" end end ``` --- README.md | 20 ++++++++++++++++ lib/vagrant-libvirt/action/create_domain.rb | 6 +++++ lib/vagrant-libvirt/config.rb | 24 +++++++++++++++++++- lib/vagrant-libvirt/templates/domain.xml.erb | 6 ++++- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5a6fd9b..4e31291 100644 --- a/README.md +++ b/README.md @@ -333,6 +333,26 @@ Vagrant.configure("2") do |config| end ``` +## Input + +You can multiple inputs to the VM via `libvirt.input`. Available options are +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 + libvirt.input :type => "tablet", :bus => "usb" + end +end +``` + ## SSH Access To VM vagrant-libvirt supports vagrant's [standard ssh settings](https://docs.vagrantup.com/v2/vagrantfile/ssh_settings.html). diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index acf5e18..d4ad3b9 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -58,6 +58,9 @@ module VagrantPlugins @disks = config.disks @cdroms = config.cdroms + # Input + @inputs = config.inputs + config = env[:machine].provider_config @domain_type = config.driver @@ -133,6 +136,9 @@ module VagrantPlugins @cdroms.each do |cdrom| env[:ui].info(" -- CDROM(#{cdrom[:dev]}): #{cdrom[:path]}") end + @inputs.each do |input| + env[:ui].info(" -- INPUT(type=#{input[:type]}, bus=#{input[:bus]})") + end env[:ui].info(" -- Command line : #{@cmd_line}") # Create libvirt domain. diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 70c6758..ebcf60e 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -76,6 +76,9 @@ module VagrantPlugins attr_accessor :disks attr_accessor :cdroms + # Inputs + attr_accessor :inputs + def initialize @uri = UNSET_VALUE @driver = UNSET_VALUE @@ -113,7 +116,10 @@ module VagrantPlugins # Storage @disks = [] - @cdroms = [] + @cdroms = [] + + # Inputs + @inputs = UNSET_VALUE end def _get_device(disks) @@ -147,6 +153,21 @@ module VagrantPlugins raise "Only four cdroms may be attached at a time" end + def input(options={}) + if options[:type] == nil or options[:bus] == nil: + raise "Input type AND bus must be specified" + end + + if @inputs == UNSET_VALUE + @inputs = [] + end + + @inputs.push({ + :type => options[:type], + :bus => options[:bus] + }) + end + # NOTE: this will run twice for each time it's needed- keep it idempotent def storage(storage_type, options={}) if storage_type == :file @@ -297,6 +318,7 @@ module VagrantPlugins # Storage @disks = [] if @disks == UNSET_VALUE @cdroms = [] if @cdroms == UNSET_VALUE + @inputs = [{:type => "mouse", :bus => "ps2"}] if @inputs == UNSET_VALUE end def validate(machine) diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 3f06c78..89520ab 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -63,7 +63,11 @@ - + + <% @inputs.each do |input| %> + + <% end %> + <%# Video device -%> />