Class: VagrantPlugins::DigitalOcean::Actions::Rebuild

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::Retryable, Helpers::Client
Defined in:
lib/vagrant-digitalocean/actions/rebuild.rb

Instance Method Summary collapse

Methods included from Helpers::Client

#client

Constructor Details

#initialize(app, env) ⇒ Rebuild

Returns a new instance of Rebuild.



10
11
12
13
14
15
# File 'lib/vagrant-digitalocean/actions/rebuild.rb', line 10

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

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vagrant-digitalocean/actions/rebuild.rb', line 17

def call(env)

  # submit rebuild request
  result = @client.post("/v2/droplets/#{@machine.id}/actions", {
    :type => 'rebuild',
    :image => @machine.provider_config.image
  })

  # wait for request to complete
  env[:ui].info I18n.t('vagrant_digital_ocean.info.rebuilding')
  @client.wait_for_event(env, result['action']['id'])

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

  # wait for ssh to be ready
  switch_user = @machine.provider_config.setup?
  user = @machine.config.ssh.username
  @machine.config.ssh.username = 'root' if switch_user

  retryable(:tries => 120, :sleep => 10) do
    next if env[:interrupted]
    raise 'not ready' if !@machine.communicate.ready?
  end

  @machine.config.ssh.username = user

  @app.call(env)
end