Class: VagrantPlugins::OneCloud::Actions::PowerOn

Inherits:
Object
  • Object
show all
Includes:
Helpers::Client
Defined in:
lib/vagrant-1cloud/actions/power_on.rb

Instance Method Summary collapse

Methods included from Helpers::Client

#client

Constructor Details

#initialize(app, env) ⇒ PowerOn

Returns a new instance of PowerOn.



9
10
11
12
13
14
# File 'lib/vagrant-1cloud/actions/power_on.rb', line 9

def initialize(app, env)
  @app = app
  @machine = env[:machine]
  @client = client
  @logger = Log4r::Logger.new('vagrant::onecloud::power_on')
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-1cloud/actions/power_on.rb', line 16

def call(env)
  # submit power on droplet request
  result = @client.post("/server/#{@machine.id}/action", {
    :Type => 'PowerOn'
  })

  # wait for request to complete
  env[:ui].info I18n.t('vagrant_1cloud.info.powering_on')
  @client.wait_for_event(env, @machine.id, result['body']['ID'])

  # refresh droplet state with provider
  Provider.droplet(@machine, :refresh => true)

  user = @machine.config.ssh.username
  @machine.config.ssh.username = 'root'

  # wait for ssh to be ready
  env[:ui].info I18n.t('vagrant_1cloud.info.ssh')
  @client.wait_for_ssh(env, 3, 30)

  @machine.config.ssh.username = user

  @app.call(env)
end