Class: Zt::Exporters::HostsFileExporter

Inherits:
BaseExporter show all
Defined in:
lib/zt/exporters/hosts_file_exporter.rb

Instance Attribute Summary

Attributes inherited from BaseExporter

#data

Instance Method Summary collapse

Methods inherited from BaseExporter

#initialize

Constructor Details

This class inherits a constructor from Zt::Exporters::BaseExporter

Instance Method Details

#exportObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zt/exporters/hosts_file_exporter.rb', line 9

def export
  # process the normalised Hash @data and return a String and a Block
  # defining what to do with the String
  conf = Zt::Conf.instance.conf
  output = ''
  conf.nodes.each_key do |node_id|
    node = conf.nodes[node_id]
    node_nets = node[:local][:networks]
    node_nets.each_key do |net_id|
      net_zone = conf.networks[net_id][:local][:dns_zone]
      node_name = node[:remote][:node_name]
      node_addrs = node[:local][:networks][net_id]
      node_addrs.each do |node_addr|
        output += "#{node_addr}\t\t#{node_name}.#{net_zone}\n"
      end
    end
  end
  "# BEGIN zt\n" + output.lines.sort_by do |a|
    a.split[1]
  end.join + "# END zt\n"
end