Class: VagrantPlugins::ProfitBricks::Action::Reboot

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-profitbricks/action/reboot_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ Reboot

Returns a new instance of Reboot.



7
8
9
10
# File 'lib/vagrant-profitbricks/action/reboot_server.rb', line 7

def initialize(app, _env)
  @app = app
  @logger = Log4r::Logger.new('vagrant_profitbricks::action::stopping_server')
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
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
# File 'lib/vagrant-profitbricks/action/reboot_server.rb', line 12

def call(env)
  compute = env[:profitbricks_compute]
  server_id = env[:machine].id
  datacenter_id = env[:machine].provider_config.datacenter_id

  server = begin
             compute.servers.get(datacenter_id, server_id)
           rescue
             nil
           end
  if server.nil?
    @logger.warn "Unable to find server #{server_id}..."
    env[:ui].warn(I18n.t('vagrant_profitbricks.errors.server_not_found'))
    env[:machine].id = nil
  else
    @logger.info "Rebooting server #{server_id}..."
    env[:ui].info(I18n.t('vagrant_profitbricks.rebooting_server'))
  end
  if server.reboot
    30.times do |_t|
      begin
        s = compute.servers.get(datacenter_id, server_id)
        break if s.vm_state == 'RUNNING'
        sleep 10
      end
    end
  end

  @app.call(env)
end