Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle "paused" VM state for up and halt actions #295

Merged
merged 1 commit into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions lib/vagrant-parallels/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,8 @@ def self.action_halt
next
end

b1.use Call, IsState, :suspended do |env2, b2|
if env2[:result]
b2.use Resume
end
end
# Resume/Unpause the VM if needed.
b1.use Resume

b1.use Call, GracefulHalt, :stopped, :running do |env2, b2|
if !env2[:result]
Expand Down Expand Up @@ -285,14 +282,22 @@ def self.action_start

b1.use Call, IsState, :suspended do |env2, b2|
if env2[:result]
# The VM is suspended, so just resume it
# The VM is suspended, go to resume
b2.use action_resume
next
end

# The VM is not saved, so we must have to boot it up
# like normal. Boot!
b2.use action_boot
b2.use Call, IsState, :paused do |env3, b3|
if env3[:result]
# The VM is paused, just run the Resume action to unpause it
b3.use Resume
next
end

# The VM is not suspended or paused, so we must have to
# boot it up like normal. Boot!
b3.use action_boot
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/vagrant-parallels/action/resume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ def initialize(app, env)
def call(env)
current_state = env[:machine].state.id

# Driver method "resume" works for suspended and paused state as well
if current_state == :suspended
env[:ui].info I18n.t('vagrant.actions.vm.resume.resuming')
env[:machine].provider.driver.resume
elsif current_state == :paused
env[:ui].info I18n.t('vagrant.actions.vm.resume.unpausing')
env[:machine].provider.driver.resume
end

@app.call(env)
Expand Down