Class: VpnChoice

Inherits:
Object show all
Defined in:
lib/vagrant-skytap/api/vpn.rb

Overview

TODO:NLA Move this to another class, properly namespaced.

Defined Under Namespace

Classes: AttachmentExecution, ConnectAttachmentExecution, CreateAttachmentExecution, UseAttachmentExecution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, vpn, vm) ⇒ VpnChoice

Returns a new instance of VpnChoice.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/vagrant-skytap/api/vpn.rb', line 9

def initialize(env, vpn, vm)
  @env = env
  @vpn = vpn
  @vm = vm
  @iface = vm.interfaces.select(&:network).tap do |ifaces|
    unless vpn.nat_enabled?
      ifaces.select! {|i| vpn.subsumes?(i.network) }
    end
  end.first
  @execution = AttachmentExecution.make(env, vpn, iface)
end

Instance Attribute Details

#attachmentObject (readonly)

Returns the value of attribute attachment.



7
8
9
# File 'lib/vagrant-skytap/api/vpn.rb', line 7

def attachment
  @attachment
end

#envObject (readonly)

Returns the value of attribute env.



7
8
9
# File 'lib/vagrant-skytap/api/vpn.rb', line 7

def env
  @env
end

#executionObject (readonly)

Returns the value of attribute execution.



7
8
9
# File 'lib/vagrant-skytap/api/vpn.rb', line 7

def execution
  @execution
end

#ifaceObject (readonly)

Returns the value of attribute iface.



7
8
9
# File 'lib/vagrant-skytap/api/vpn.rb', line 7

def iface
  @iface
end

#vmObject (readonly)

Returns the value of attribute vm.



7
8
9
# File 'lib/vagrant-skytap/api/vpn.rb', line 7

def vm
  @vm
end

#vpnObject (readonly)

Returns the value of attribute vpn.



7
8
9
# File 'lib/vagrant-skytap/api/vpn.rb', line 7

def vpn
  @vpn
end

Instance Method Details

#chooseObject



31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-skytap/api/vpn.rb', line 31

def choose
  execution.execute

  @iface = vm.reload.interfaces.detect{|i| i.id == iface.id }
  host = iface.address_for(vpn)
  port = 22 #TODO:NLA Use constant

  [host, port]
end

#to_sObject



21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-skytap/api/vpn.rb', line 21

def to_s
  "#{execution.verb} VPN: #{vpn.name}".tap do |ret|
    if vpn.nat_enabled?
      ret << " (NAT-enabled)"
    else
      ret << " (local subnet: #{vpn.local_subnet})"
    end
  end
end

#valid?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/vagrant-skytap/api/vpn.rb', line 41

def valid?
  true
end