Class: VagrantPlugins::Filoo::Action::StopInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_filoo/action/stop_instance.rb

Overview

This starts a stopped instance.

Constant Summary collapse

STOP_RESOURCE =
"/vserver/stop"
STOP_INSTANCE_TIMEOUT =
60

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ StopInstance

Returns a new instance of StopInstance.



10
11
12
13
14
# File 'lib/vagrant_filoo/action/stop_instance.rb', line 10

def initialize(app, env)
  @app    = app
  @baseUrl =env[:machine].provider_config.filoo_api_entry_point
  @apiKey = env[:machine].provider_config.filoo_api_key
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant_filoo/action/stop_instance.rb', line 16

def call(env)
  if env[:machine].state.id == :stopped
    env[:ui].info(I18n.t("vagrant_filoo.already_status", :status => env[:machine].state.id))
  else
    vmid = env[:machine].id
    env[:ui].info("Halt machine #{vmid}")
    env[:result] = VagrantPlugins::Filoo::CloudCompute::stopInstance vmid, @baseUrl, @apiKey
    env[:ui].info("Machine #{vmid} successfully halted, new state:")
    env[:ui].info(
     "#{JSON.pretty_generate(env[:result]).gsub!('{','').gsub!('}','').gsub!('"','').gsub!(',','').gsub!('[','').gsub!(']','')}")
  end      
  @app.call(env)
end