Class: VagrantPlugins::Skytap::Connection::TunnelChoice

Inherits:
Choice
  • Object
show all
Defined in:
lib/vagrant-skytap/connection/tunnel_choice.rb

Defined Under Namespace

Classes: CreateAndUseExecution, TunnelExecution, UseExecution

Instance Attribute Summary collapse

Attributes inherited from Choice

#env, #execution, #iface, #validation_error_message

Instance Method Summary collapse

Methods inherited from Choice

#to_s

Constructor Details

#initialize(env, host_network, iface) ⇒ TunnelChoice

Returns a new instance of TunnelChoice.



35
36
37
38
39
40
41
# File 'lib/vagrant-skytap/connection/tunnel_choice.rb', line 35

def initialize(env, host_network, iface)
  @env = env
  @iface = iface
  @host_network = host_network
  @guest_network = iface.network
  @execution = TunnelExecution.make(env, iface, host_network)
end

Instance Attribute Details

#guest_networkObject (readonly)

Returns the value of attribute guest_network.



33
34
35
# File 'lib/vagrant-skytap/connection/tunnel_choice.rb', line 33

def guest_network
  @guest_network
end

#host_networkObject (readonly)

Returns the value of attribute host_network.



33
34
35
# File 'lib/vagrant-skytap/connection/tunnel_choice.rb', line 33

def host_network
  @host_network
end

Instance Method Details

#chooseObject



43
44
45
46
47
48
49
# File 'lib/vagrant-skytap/connection/tunnel_choice.rb', line 43

def choose
  execution.execute
  @iface = iface.vm.reload.get_interface_by_id(iface.id)
  @host_network = host_network.environment.reload.networks.find{|n| n.id == host_network.id}
  nat_address = iface.nat_address_for_network(host_network)
  [nat_address, DEFAULT_PORT]
end

#valid?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/vagrant-skytap/connection/tunnel_choice.rb', line 51

def valid?
  @validation_error_message = nil

  unless host_network.tunnelable? && host_network.nat_enabled?
    @validation_error_message = I18n.t("vagrant_skytap.connections.tunnel.errors.host_network_not_connectable")
    return false
  end

  unless guest_network.nat_enabled?
    if guest_network.subnet.overlaps?(host_network.subnet)
      @validation_error_message = I18n.t("vagrant_skytap.connections.tunnel.errors.guest_network_overlaps",
                                         guest_subnet: guest_network.subnet, host_subnet: host_network.subnet,
                                         environment_url: iface.vm.environment.url)
      return false
    end
  end

  true
end