Class: Vagrant::Action::Builtin::CloudInitWait

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/builtin/cloud_init_wait.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ CloudInitWait

Returns a new instance of CloudInitWait.


6
7
8
9
# File 'lib/vagrant/action/builtin/cloud_init_wait.rb', line 6

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new("vagrant::action::builtin::cloudinitwait")
end

Instance Method Details

#call(env) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant/action/builtin/cloud_init_wait.rb', line 11

def call(env)
  machine = env[:machine]
  cloud_init_wait_cmd = "cloud-init status --wait"
  if !machine.config.vm.cloud_init_configs.empty?
    if machine.communicate.test("command -v cloud-init")
      env[:ui].output(I18n.t("vagrant.cloud_init_waiting"))
      result = machine.communicate.sudo(cloud_init_wait_cmd, error_check: false)
      if result != 0
        raise Vagrant::Errors::CloudInitCommandFailed, cmd: cloud_init_wait_cmd, guest_name: machine.name
      end
    else
      raise Vagrant::Errors::CloudInitNotFound, guest_name: machine.name
    end
  end
  @app.call(env)
end