Module: DockDriver::Template::Network
- Included in:
- DockDriver::Template
- Defined in:
- lib/dock_driver/template/network.rb
Overview
Adds network-related methods to the DockDriver::Template DSL.
Instance Method Summary collapse
-
#first_ipv4 ⇒ Object
Return the first non-localhost IPv4 address.
-
#first_ipv6 ⇒ Object
Return the first non-localhost IPv6 address.
-
#fqdn ⇒ Object
Returns the current FQDN of this host.
-
#hostname ⇒ Object
(also: #host)
Returns the short hostname of this host.
-
#ip_addrs ⇒ Object
Returns a list of all non-localhost IP addresses.
Instance Method Details
#first_ipv4 ⇒ Object
Return the first non-localhost IPv4 address. Example:
<%= first_ipv4 %> => 10.5.4.3
44 45 46 |
# File 'lib/dock_driver/template/network.rb', line 44 def first_ipv4 return self.ip_addrs.select { |a| a.ipv4? }.first.ip_address end |
#first_ipv6 ⇒ Object
Return the first non-localhost IPv6 address. Example:
<%= first_ipv4 %> => 20a3::2
53 54 55 |
# File 'lib/dock_driver/template/network.rb', line 53 def first_ipv6 return self.ip_addrs.select { |a| a.ipv6? }.first.ip_address end |
#fqdn ⇒ Object
Returns the current FQDN of this host. Example:
<%= fqdn %> => grumpus.somenet.org
12 13 14 |
# File 'lib/dock_driver/template/network.rb', line 12 def fqdn return Socket.gethostbyname(Socket.gethostname).first end |
#hostname ⇒ Object Also known as: host
Returns the short hostname of this host. Example:
<%= host %> => grumpus
<%= hostname %> => grumpus
22 23 24 |
# File 'lib/dock_driver/template/network.rb', line 22 def hostname return Socket.gethostname end |
#ip_addrs ⇒ Object
Returns a list of all non-localhost IP addresses. Example:
<%= ip_addrs %> => 10.5.4.3 10.4.3.2 20a3::2
33 34 35 36 37 |
# File 'lib/dock_driver/template/network.rb', line 33 def ip_addrs return Socket.ip_address_list.reject do |a| a.ip_address.match /^(fe80|127\.|::1)/ end end |