diff --git a/README.md b/README.md index eec14df..92679ce 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,8 @@ end * `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. * `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. * `uuid` - Force a domain UUID. Defaults to autogenerated value by libvirt if not set. +* `suspend_mode` - What is done on vagrant suspend. Possible values: 'pause', 'managedsave'. Pause mode executes a la `virsh suspend`, which just pauses execution of a VM, not freeing resources. Managed save mode does a la `virsh managedsave` which frees resources suspending a domain. + Specific domain settings can be set for each domain separately in multi-VM diff --git a/lib/vagrant-libvirt/action/destroy_domain.rb b/lib/vagrant-libvirt/action/destroy_domain.rb index 52caa18..50e7f71 100644 --- a/lib/vagrant-libvirt/action/destroy_domain.rb +++ b/lib/vagrant-libvirt/action/destroy_domain.rb @@ -28,6 +28,11 @@ module VagrantPlugins end end + # must remove managed saves + if libvirt_domain.has_managed_save? + libvirt_domain.managed_save_remove + end + domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) if env[:machine].provider_config.disks.empty? diff --git a/lib/vagrant-libvirt/action/is_suspended.rb b/lib/vagrant-libvirt/action/is_suspended.rb index b5bf3d0..0a4db47 100644 --- a/lib/vagrant-libvirt/action/is_suspended.rb +++ b/lib/vagrant-libvirt/action/is_suspended.rb @@ -11,8 +11,29 @@ module VagrantPlugins def call(env) domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) raise Errors::NoDomainError if domain == nil - env[:result] = domain.state.to_s == 'paused' + config = env[:machine].provider_config + libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id) + if config.suspend_mode == 'managedsave' + if libvirt_domain.has_managed_save? + env[:result] = libvirt_domain.has_managed_save? + else + env[:result] = domain.state.to_s == 'paused' + if env[:result] + env[:ui].warn('One time switching to pause suspend mode, found a paused VM.') + config.suspend_mode = 'pause' + end + end + else + if libvirt_domain.has_managed_save? + env[:ui].warn('One time switching to managedsave suspend mode, state found.') + env[:result] = true + config.suspend_mode = 'managedsave' + else + env[:result] = domain.state.to_s == 'paused' + end + end + @app.call(env) end end diff --git a/lib/vagrant-libvirt/action/resume_domain.rb b/lib/vagrant-libvirt/action/resume_domain.rb index 1f0dc84..2a145ba 100644 --- a/lib/vagrant-libvirt/action/resume_domain.rb +++ b/lib/vagrant-libvirt/action/resume_domain.rb @@ -16,7 +16,14 @@ module VagrantPlugins domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) raise Errors::NoDomainError if domain == nil - domain.resume + libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id) + config = env[:machine].provider_config + if config.suspend_mode == 'managedsave' + domain.start + else + domain.resume + end + @logger.info("Machine #{env[:machine].id} is resumed.") @app.call(env) diff --git a/lib/vagrant-libvirt/action/suspend_domain.rb b/lib/vagrant-libvirt/action/suspend_domain.rb index 60027c4..7a92374 100644 --- a/lib/vagrant-libvirt/action/suspend_domain.rb +++ b/lib/vagrant-libvirt/action/suspend_domain.rb @@ -17,7 +17,19 @@ module VagrantPlugins domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) raise Errors::NoDomainError if domain == nil - domain.suspend + config = env[:machine].provider_config + if config.suspend_mode == 'managedsave' + libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id) + begin + libvirt_domain.managed_save + rescue => e + env[:ui].error("Error doing a managed save for domain. It may have entered a paused state. + Check the output of `virsh managedsave DOMAIN_NAME --verbose` on the VM host, error: #{e.message}") + end + else + domain.suspend + end + @logger.info("Machine #{env[:machine].id} is suspended ") @app.call(env) diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 7451f8a..9a38a1d 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -90,6 +90,9 @@ module VagrantPlugins # Inputs attr_accessor :inputs + # Suspend mode + attr_accessor :suspend_mode + def initialize @uri = UNSET_VALUE @driver = UNSET_VALUE @@ -140,6 +143,9 @@ module VagrantPlugins # Inputs @inputs = UNSET_VALUE + + # Suspend mode + @suspend_mode = UNSET_VALUE end def boot(device) @@ -354,7 +360,13 @@ module VagrantPlugins # Storage @disks = [] if @disks == UNSET_VALUE @cdroms = [] if @cdroms == UNSET_VALUE + + # Inputs @inputs = [{:type => "mouse", :bus => "ps2"}] if @inputs == UNSET_VALUE + + # Suspend mode + @suspend_mode = "pause" if @suspend_mode == UNSET_VALUE + end def validate(machine)