Class: Zt::Importers::NodeImporter
- Inherits:
-
BaseImporter
- Object
- BaseImporter
- Zt::Importers::NodeImporter
- Defined in:
- lib/zt/importers/node_importer.rb
Instance Attribute Summary
Attributes inherited from BaseImporter
Instance Method Summary collapse
Methods inherited from BaseImporter
Constructor Details
This class inherits a constructor from Zt::Importers::BaseImporter
Instance Method Details
#import ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zt/importers/node_importer.rb', line 8 def import output = {} hostnames = {} memberships = {} # normalise data nodes.each_key do |network_id| net = nodes[network_id] normalised_nodes = net.map do |node| { node_id: node['nodeId'], node_name: node['name'], node_addr: node['config']['ipAssignments'], node_authed: node['config']['authorized'] } end normalised_nodes.each do |n| hostnames[n[:node_id]] = [] unless hostnames.key?(n[:node_id]) memberships[n[:node_id]] = [] unless memberships.key?(n[:node_id]) hostnames[n[:node_id]].append(n[:node_name]) memberships[n[:node_id]].append([network_id, n[:node_addr]]) n.delete(:node_addr) output[n[:node_id]] = {} unless output.key?(n[:node_id]) output[n[:node_id]][:remote] = n output[n[:node_id]][:local] = {} end output.each_key do |k| output[k][:remote][:node_name] = hostnames[k].max_by do |i| hostnames[k].count(i) end memberships[k].each do |m| output[k][:local][:networks] = {} unless output[k][:local].key? :networks output[k][:local][:networks][m[0]] = m[1] end end end { nodes: output } end |