Class: VagrantPlugins::Utm::Action::IpAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_utm/action/ip_address.rb

Overview

Action to get IP address of machine.

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ IpAddress

Returns a new instance of IpAddress.



8
9
10
# File 'lib/vagrant_utm/action/ip_address.rb', line 8

def initialize(app, _env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

rubocop:disable Metrics/AbcSize



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant_utm/action/ip_address.rb', line 12

def call(env) # rubocop:disable Metrics/AbcSize
  # Get IP address of the machine.
  env[:ui].warn I18n.t("vagrant_utm.actions.vm.ip_address.reading")
  guest_ips = env[:machine].provider.driver.read_guest_ip

  if guest_ips.empty?
    # Inform user that no IP address was found.
    env[:ui].warn I18n.t("vagrant_utm.actions.vm.ip_address.not_found")
  else
    # Show IP address of the machine.
    env[:ui].info I18n.t("vagrant_utm.actions.vm.ip_address.show")
    guest_ips.each do |ip|
      env[:ui].info "  #{ip}"
    end
  end

  @app.call(env)
end