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

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

Overview

sets VM hostname via the API

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ SetHostname

Returns a new instance of SetHostname.


9
10
11
12
# File 'lib/vagrant-skytap/action/set_hostname.rb', line 9

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

Instance Method Details

#call(env) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vagrant-skytap/action/set_hostname.rb', line 14

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

  @app.call(env)
end