class Pec::Command::Hosts

Public Class Methods

after_do() click to toggle source
# File lib/pec/command/hosts.rb, line 34
def self.after_do
  m = "# " + ("-" * 16)
  n = ("-" * 17)
  puts m + " pec end " + n
end
before_do() click to toggle source
# File lib/pec/command/hosts.rb, line 29
def self.before_do
  @_error = nil
  puts "# ------ #{Date.today.strftime("%Y%m%d%H%M%S")} pec add start ------"
end
ip_addresses(server) click to toggle source
# File lib/pec/command/hosts.rb, line 15
def self.ip_addresses(server)
  server.addresses.map do |ethers|
    ethers[1].map do |ether|
      ether["addr"]
    end
  end.flatten
end
private_ip?(target) click to toggle source
# File lib/pec/command/hosts.rb, line 23
def self.private_ip?(target)
  ::IPAddr.new("10.0.0.0/8").include?(target) ||
  ::IPAddr.new("172.16.0.0/12").include?(target) ||
  ::IPAddr.new("192.168.0.0/16").include?(target)
end
task(server, config) click to toggle source
# File lib/pec/command/hosts.rb, line 4
def self.task(server, config)
  ip_addresses(server).each do |i|
    host_name = private_ip?(i) ? "#{config.name}.lan" : config.name
    puts sprintf(
      "%-15s %-35s",
      i,
      host_name,
    )
  end if server
end