Class: ConfCtl::Cli::GenData

Inherits:
Command
  • Object
show all
Defined in:
lib/confctl/cli/gen_data.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #gopts, #opts

Instance Method Summary collapse

Methods inherited from Command

#ask_action, #ask_confirmation, #ask_confirmation!, #initialize, #require_args!, run, #run_method, #use_color?, #use_pager?

Constructor Details

This class inherits a constructor from ConfCtl::Cli::Command

Instance Method Details

#vpsadmin_allObject



7
8
9
10
# File 'lib/confctl/cli/gen_data.rb', line 7

def vpsadmin_all
  vpsadmin_containers
  vpsadmin_network
end

#vpsadmin_containersObject



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
# File 'lib/confctl/cli/gen_data.rb', line 12

def vpsadmin_containers
  api = vpsadmin_client

  machines = ConfCtl::MachineList.new
  data = {}

  machines.each_value do |m|
    next if m['container'].nil?

    ct = api.vps.show(
      m['container.id'],
      meta: { includes: 'node__location__environment' }
    )

    ct_fqdn = [
      m['host.name'],
      m['host.location'],
      m['host.domain']
    ].compact.join('.')

    data[ct_fqdn] = {
      node: {
        id: ct.node.id,
        name: ct.node.name,
        location: ct.node.location.domain,
        domain: ct.node.location.environment.domain,
        fqdn: "#{ct.node.domain_name}.#{ct.node.location.environment.domain}"
      }
    }
  end

  update_file('vpsadmin/containers.nix') do |f|
    f.puts(ConfCtl::NixFormat.to_nix(data))
  end
end

#vpsadmin_networkObject



48
49
50
# File 'lib/confctl/cli/gen_data.rb', line 48

def vpsadmin_network
  vpsadmin_network_containers
end

#vpsadmin_network_containersObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/confctl/cli/gen_data.rb', line 52

def vpsadmin_network_containers
  api = vpsadmin_client
  networks = api.network.list
  data = {}

  [4, 6].each do |ip_v|
    data["ipv#{ip_v}"] = networks.select { |net| net.ip_version == ip_v }.map do |net|
      { address: net.address, prefix: net.prefix }
    end
  end

  update_file('vpsadmin/networks/containers.nix') do |f|
    f.puts(ConfCtl::NixFormat.to_nix(data))
  end
end