Class: VagrantPlugins::Skytap::API::Network
- Includes:
- Connectable
- Defined in:
- lib/vagrant-skytap/api/network.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Attributes inherited from Resource
Instance Method Summary collapse
- #attachment_for(vpn) ⇒ Object
-
#connect_to_network(other_network) ⇒ Object
Connects to a network in another environment via an ICNR tunnel.
-
#connected_to_network?(other_network) ⇒ Boolean
Indicates whether an ICNR tunnel exists between this network and the given network in another environment.
- #connection_choice_class ⇒ Object
-
#initialize(attrs, environment, env) ⇒ Network
constructor
A new instance of Network.
-
#nat_enabled? ⇒ Boolean
Indicates whether this network is NAT-enabled.
- #refresh(attrs) ⇒ Object
- #subnet ⇒ Object
-
#tunnelable? ⇒ Boolean
Indicates whether networks in other environments may connect to this one.
-
#tunnels ⇒ Object
The set of ICNR tunnels connecting this network to networks in other environments.
- #url ⇒ Object
- #vpn_attachments ⇒ Object
Methods included from Connectable
Methods inherited from Resource
#delete, #reload, rest_name, short_name, #update
Methods included from SpecifiedAttributes
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
#environment ⇒ Object (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 (vpn) vpn = vpn.id unless vpn.is_a?(String) .detect {|att| att.vpn['id'] == vpn} end |
#connect_to_network(other_network) ⇒ Object
Connects to a network in another environment via an ICNR tunnel.
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.)
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_class ⇒ Object
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.
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 |
#subnet ⇒ Object
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.
80 81 82 |
# File 'lib/vagrant-skytap/api/network.rb', line 80 def tunnelable? get_api_attribute('tunnelable') end |
#tunnels ⇒ Object
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 |
#url ⇒ Object
44 45 46 |
# File 'lib/vagrant-skytap/api/network.rb', line 44 def url "/configurations/#{environment.id}/networks/#{id}" end |
#vpn_attachments ⇒ Object
54 55 56 57 58 |
# File 'lib/vagrant-skytap/api/network.rb', line 54 def @vpn_attachments ||= (get_api_attribute('vpn_attachments') || []).collect do |att_attrs| VpnAttachment.new(att_attrs, self, env) end end |