Class: VagrantPlugins::Skytap::API::Network

Inherits:
Resource show all
Includes:
Connectable
Defined in:
lib/vagrant-skytap/api/network.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#attrs, #env

Instance Method Summary collapse

Methods included from Connectable

#choice_for_setup

Methods inherited from Resource

#delete, #reload, rest_name, short_name, #update

Methods included from SpecifiedAttributes

#get_api_attribute, included

Constructor Details

#initialize(attrs, environment, env) ⇒ Network

Returns a new instance of Network.



39
40
41
42
# File 'lib/vagrant-skytap/api/network.rb', line 39

def initialize(attrs, environment, env)
  super
  @environment = environment
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



35
36
37
# File 'lib/vagrant-skytap/api/network.rb', line 35

def environment
  @environment
end

Instance Method Details

#attachment_for(vpn) ⇒ Object



64
65
66
67
# File 'lib/vagrant-skytap/api/network.rb', line 64

def attachment_for(vpn)
  vpn = vpn.id unless vpn.is_a?(String)
  vpn_attachments.detect {|att| att.vpn['id'] == vpn}
end

#connect_to_network(other_network) ⇒ Object

Connects to a network in another environment via an ICNR tunnel.

Parameters:

  • other_network (API::Network)

    The network to connect to.



97
98
99
100
101
# File 'lib/vagrant-skytap/api/network.rb', line 97

def connect_to_network(other_network)
  API::Tunnel.create!(env, self, other_network)
  updated_network = environment.reload.networks.find{|n| n.id == id}
  refresh(updated_network.attrs)
end

#connected_to_network?(other_network) ⇒ Boolean

Indicates whether an ICNR tunnel exists between this network and the given network in another environment. (For networks within the same environment, check the environment’s #routable? flag instead.)

Returns:

  • (Boolean)


108
109
110
111
112
# File 'lib/vagrant-skytap/api/network.rb', line 108

def connected_to_network?(other_network)
  tunnels.any? do |tunnel|
    tunnel.target_network.id == other_network.id || tunnel.source_network.id == other_network.id
  end
end

#connection_choice_classObject



114
115
116
117
# File 'lib/vagrant-skytap/api/network.rb', line 114

def connection_choice_class
  require "vagrant-skytap/connection/tunnel_choice"
  Class.const_get("VagrantPlugins::Skytap::Connection::TunnelChoice")
end

#nat_enabled?Boolean

Indicates whether this network is NAT-enabled.

Returns:

  • (Boolean)


72
73
74
# File 'lib/vagrant-skytap/api/network.rb', line 72

def nat_enabled?
  nat_subnet.present?
end

#refresh(attrs) ⇒ Object



48
49
50
51
52
# File 'lib/vagrant-skytap/api/network.rb', line 48

def refresh(attrs)
  @vpn_attachments = nil
  @tunnels = nil
  super
end

#subnetObject



60
61
62
# File 'lib/vagrant-skytap/api/network.rb', line 60

def subnet
  Util::Subnet.new(get_api_attribute('subnet'))
end

#tunnelable?Boolean

Indicates whether networks in other environments may connect to this one.

Returns:

  • (Boolean)


80
81
82
# File 'lib/vagrant-skytap/api/network.rb', line 80

def tunnelable?
  get_api_attribute('tunnelable')
end

#tunnelsObject

The set of ICNR tunnels connecting this network to networks in other environments.



88
89
90
91
92
# File 'lib/vagrant-skytap/api/network.rb', line 88

def tunnels
  @tunnels ||= (get_api_attribute('tunnels') || []).collect do |tunnel_attrs|
    Tunnel.new(tunnel_attrs, env)
  end
end

#urlObject



44
45
46
# File 'lib/vagrant-skytap/api/network.rb', line 44

def url
  "/configurations/#{environment.id}/networks/#{id}"
end

#vpn_attachmentsObject



54
55
56
57
58
# File 'lib/vagrant-skytap/api/network.rb', line 54

def vpn_attachments
  @vpn_attachments ||= (get_api_attribute('vpn_attachments') || []).collect do |att_attrs|
    VpnAttachment.new(att_attrs, self, env)
  end
end