Class: Zt::Importers::NetworkImporter

Inherits:
BaseImporter show all
Defined in:
lib/zt/importers/network_importer.rb

Instance Attribute Summary

Attributes inherited from BaseImporter

#networks, #nodes

Instance Method Summary collapse

Methods inherited from BaseImporter

#initialize

Constructor Details

This class inherits a constructor from Zt::Importers::BaseImporter

Instance Method Details

#importObject



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
# File 'lib/zt/importers/network_importer.rb', line 9

def import
  output = {}
  # normalise data
  normalised_networks = networks.map do |n|
    {
      network_id: n['id'],
      network_name: n['config']['name'],
      network_description: n['description'],
      network_total_members: n['totalMemberCount'],
      network_authorized_members: n['authorizedMemberCount'],
      network_pending_members:
        (n['totalMemberCount'] - n['authorizedMemberCount'])
    }
  end
  domains_conf = Zt::Conf.instance.conf.domains
  normalised_networks.each do |n|
    zone = if domains_conf.key? n[:network_id]
             if n[:network_id].empty?
               qualify(n[:network_id])
             else
               qualify(domains_conf[n[:network_id]])
             end
           else
             qualify(n[:network_name])
           end
    output[n[:network_id]] = {} unless output.key?(n[:network_id])
    output[n[:network_id]][:remote] = n
    output[n[:network_id]][:local] = {
      dns_zone: zone
    }
  end
  {
    networks: output
  }
end