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

Instance Method Details

#first_ipv4Object

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_ipv6Object

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

#fqdnObject

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

#hostnameObject 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_addrsObject

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