Class: VagrantPlugins::ProviderKvm::Action::Suspend

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-kvm/action/suspend.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Suspend

Returns a new instance of Suspend.



5
6
7
# File 'lib/vagrant-kvm/action/suspend.rb', line 5

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vagrant-kvm/action/suspend.rb', line 9

def call(env)
  if env[:machine].provider.state.id == :running
    env[:ui].info I18n.t("vagrant.actions.vm.suspend.suspending")
    if env[:machine].provider_config.force_suspend
      env[:machine].provider.driver.suspend
    elsif  env[:machine].provider.driver.can_save?
      env[:machine].provider.driver.save
    else
      env[:ui].warn ("Suspend is not supported. use pause instead.")
      env[:machine].provider.driver.suspend
    end
  end

  @app.call(env)
end