Class: VagrantPlugins::Skytap::Action::GetHostVM

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-skytap/action/get_host_vm.rb

Overview

If Vagrant is running in a Skytap VM, retrieve the VM’s metadata, instantiate the VM, and store the result in env. The request does not go through the REST API, so it can be made without an api token.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ GetHostVM

Returns a new instance of GetHostVM.



33
34
35
36
# File 'lib/vagrant-skytap/action/get_host_vm.rb', line 33

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new("vagrant_skytap::action::get_host_metadata")
end

Instance Method Details

#call(env) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vagrant-skytap/action/get_host_vm.rb', line 38

def call(env)
  unless env[:vagrant_host_vm]
    if ( = env[:machine].provider.)
      # The environment will be lazy loaded
      env[:vagrant_host_vm] = vm = API::Vm.new(, nil, env)
      @logger.info("Running Vagrant in a Skytap VM. ID: #{vm.try(:id)}")
    end
  end

  @app.call(env)
end