Class: VagrantPlugins::Cloudstack::Action::StopInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-cloudstack/action/stop_instance.rb

Overview

This stops the running instance.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ StopInstance

Returns a new instance of StopInstance.



8
9
10
11
# File 'lib/vagrant-cloudstack/action/stop_instance.rb', line 8

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new("vagrant_cloudstack::action::stop_instance")
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vagrant-cloudstack/action/stop_instance.rb', line 13

def call(env)
  server = env[:cloudstack_compute].servers.get(env[:machine].id)

  if env[:machine].state.id == :stopped
    env[:ui].info(I18n.t("vagrant_cloudstack.already_status", :status => env[:machine].state.id))
  else
    env[:ui].info(I18n.t("vagrant_cloudstack.stopping"))
    server.stop({'force' => !!env[:force_halt]})
  end

  @app.call(env)
end