Class: VagrantPlugins::Skytap::Action::SetHostname

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

Overview

sets VM hostname via the API

Instance Method Summary collapse

Methods included from ActionHelpers

#current_vm

Constructor Details

#initialize(app, env) ⇒ SetHostname



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

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

Instance Method Details

#call(env) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vagrant-skytap/action/set_hostname.rb', line 39

def call(env)
  if hostname = env[:machine].config.vm.hostname
    if vm = current_vm(env)
      if nic = vm.interfaces.first
        if hostname != nic.get_api_attribute('hostname')
          @logger.info("Updating hostname: #{hostname}")
          nic.update(hostname: hostname)
        end
      end
    end
  end

  @app.call(env)
end