Merge pull request #470 from mkutsevol/issue_411

Issue 411
This commit is contained in:
Dmitry Vasilets 2015-09-29 20:32:20 +02:00
commit 15d12d1053
6 changed files with 62 additions and 3 deletions

View File

@ -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. * `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. * `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. * `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 Specific domain settings can be set for each domain separately in multi-VM

View File

@ -28,6 +28,11 @@ module VagrantPlugins
end end
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) domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
if env[:machine].provider_config.disks.empty? if env[:machine].provider_config.disks.empty?

View File

@ -11,8 +11,29 @@ module VagrantPlugins
def call(env) def call(env)
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
raise Errors::NoDomainError if domain == nil 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) @app.call(env)
end end
end end

View File

@ -16,7 +16,14 @@ module VagrantPlugins
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
raise Errors::NoDomainError if domain == nil 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.") @logger.info("Machine #{env[:machine].id} is resumed.")
@app.call(env) @app.call(env)

View File

@ -17,7 +17,19 @@ module VagrantPlugins
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
raise Errors::NoDomainError if domain == nil 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 ") @logger.info("Machine #{env[:machine].id} is suspended ")
@app.call(env) @app.call(env)

View File

@ -90,6 +90,9 @@ module VagrantPlugins
# Inputs # Inputs
attr_accessor :inputs attr_accessor :inputs
# Suspend mode
attr_accessor :suspend_mode
def initialize def initialize
@uri = UNSET_VALUE @uri = UNSET_VALUE
@driver = UNSET_VALUE @driver = UNSET_VALUE
@ -140,6 +143,9 @@ module VagrantPlugins
# Inputs # Inputs
@inputs = UNSET_VALUE @inputs = UNSET_VALUE
# Suspend mode
@suspend_mode = UNSET_VALUE
end end
def boot(device) def boot(device)
@ -354,7 +360,13 @@ module VagrantPlugins
# Storage # Storage
@disks = [] if @disks == UNSET_VALUE @disks = [] if @disks == UNSET_VALUE
@cdroms = [] if @cdroms == UNSET_VALUE @cdroms = [] if @cdroms == UNSET_VALUE
# Inputs
@inputs = [{:type => "mouse", :bus => "ps2"}] if @inputs == UNSET_VALUE @inputs = [{:type => "mouse", :bus => "ps2"}] if @inputs == UNSET_VALUE
# Suspend mode
@suspend_mode = "pause" if @suspend_mode == UNSET_VALUE
end end
def validate(machine) def validate(machine)