Class: VagrantPlugins::Skytap::Connection::VpnChoice

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

Defined Under Namespace

Classes: AttachConnectAndUseExecution, ConnectAndUseExecution, UseExecution, VPNAttachmentExecution

Instance Attribute Summary collapse

Attributes inherited from Choice

#env, #execution, #iface, #validation_error_message

Instance Method Summary collapse

Methods inherited from Choice

#to_s, #valid?

Constructor Details

#initialize(env, vpn, vm) ⇒ VpnChoice

Returns a new instance of VpnChoice.



32
33
34
35
36
37
38
# File 'lib/vagrant-skytap/connection/vpn_choice.rb', line 32

def initialize(env, vpn, vm)
  @env = env
  @vpn = vpn
  @vm = vm
  @iface = select_interface(vm, vpn)
  @execution = VPNAttachmentExecution.make(env, iface, vpn)
end

Instance Attribute Details

#attachmentObject (readonly)

Returns the value of attribute attachment.



30
31
32
# File 'lib/vagrant-skytap/connection/vpn_choice.rb', line 30

def attachment
  @attachment
end

#vmObject (readonly)

Returns the value of attribute vm.



30
31
32
# File 'lib/vagrant-skytap/connection/vpn_choice.rb', line 30

def vm
  @vm
end

#vpnObject (readonly)

Returns the value of attribute vpn.



30
31
32
# File 'lib/vagrant-skytap/connection/vpn_choice.rb', line 30

def vpn
  @vpn
end

Instance Method Details

#chooseObject



55
56
57
58
59
60
# File 'lib/vagrant-skytap/connection/vpn_choice.rb', line 55

def choose
  execution.execute
  @iface = vm.reload.get_interface_by_id(iface.id)
  host = iface.address_for(vpn)
  [host, DEFAULT_PORT]
end

#select_interface(vm, vpn) ⇒ API::Interface

Finds an interface on the guest VM which is connected to a network which lies inside the VPN’s subnet. If the VPN is NAT enabled, this method simply returns the first interface.

Parameters:

  • vm (API::Vm)

    The guest VM

  • vpn (API::Vpn)

    The VPN this VpnChoice will connect to

Returns:



47
48
49
50
51
52
53
# File 'lib/vagrant-skytap/connection/vpn_choice.rb', line 47

def select_interface(vm, vpn)
  vm.interfaces.select(&:network).tap do |ifaces|
    unless vpn.nat_enabled?
      ifaces.select! {|i| vpn.subsumes?(i.network) }
    end
  end.first
end