Class: Vmpooler::Dns

Inherits:
Object
  • Object
show all
Defined in:
lib/vmpooler/dns.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_dns_plugin_class_by_name(config, name) ⇒ String

Returns the plugin class for the specified dns config by name

Parameters:

  • config (Object)

    The entire VMPooler config object

  • name (Symbol)

    The name of the dns config key to get the dns class

Returns:

  • (String)

    The plugin class for the specifid dns config



21
22
23
24
25
26
27
28
29
30
# File 'lib/vmpooler/dns.rb', line 21

def self.get_dns_plugin_class_by_name(config, name)
  dns_configs = config[:dns_configs].keys
  plugin_class = ''

  dns_configs.map do |dns_config_name|
    plugin_class = config[:dns_configs][dns_config_name]['dns_class'] if dns_config_name.to_s == name
  end

  plugin_class
end

.get_dns_plugin_config_classes(config) ⇒ Object

Returns a list of DNS plugin classes specified in the vmpooler configuration

Parameters:

  • config (Object)

    The entire VMPooler config object

Returns:

  • nil || [Array<String>] A list of DNS plugin classes



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/vmpooler/dns.rb', line 62

def self.get_dns_plugin_config_classes(config)
  return nil unless config[:dns_configs]

  dns_configs = config[:dns_configs].keys
  dns_plugins = dns_configs.map do |dns_config_name|
    if config[:dns_configs][dns_config_name] && config[:dns_configs][dns_config_name]['dns_class']
      config[:dns_configs][dns_config_name]['dns_class'].to_s
    else
      dns_config_name.to_s
    end
  end.compact.uniq

  # dynamic-dns is not actually a class, it's just used as a value to denote
  # that dynamic dns is used so no loading or record management is needed
  dns_plugins.delete('dynamic-dns')

  dns_plugins
end

.get_dns_plugin_domain_by_name(config, name) ⇒ String

Returns the plugin domain for the specified dns config by name

Parameters:

  • config (Object)

    The entire VMPooler config object

  • name (Symbol)

    The name of the dns config key to get the dns domain

Returns:

  • (String)

    The domain for the specifid dns config



51
52
53
54
55
56
# File 'lib/vmpooler/dns.rb', line 51

def self.get_dns_plugin_domain_by_name(config, name)
  dns_configs = config[:dns_configs].keys
  dns_configs.map do |dns_config_name|
    return config[:dns_configs][dns_config_name]['domain'] if dns_config_name.to_s == name
  end
end

.get_domain_for_pool(config, pool_name) ⇒ String

Returns the domain for the specified pool

Parameters:

  • config (String)
    • the full config structure

  • pool_name (String)
    • the name of the pool

Returns:

  • (String)
    • domain name for pool, which is set via reference to the dns_configs block



37
38
39
40
41
42
43
44
# File 'lib/vmpooler/dns.rb', line 37

def self.get_domain_for_pool(config, pool_name)
  pool = config[:pools].find { |p| p['name'] == pool_name }
  pool_dns_config = pool['dns_plugin']
  dns_configs = config[:dns_configs].keys
  dns_configs.map do |dns_config_name|
    return config[:dns_configs][dns_config_name]['domain'] if dns_config_name.to_s == pool_dns_config
  end
end

.load_by_name(names) ⇒ Object

Load one or more VMPooler DNS plugin gems by name

Parameters:

  • names (Array<String>)

    The list of gem names to load



10
11
12
13
14
# File 'lib/vmpooler/dns.rb', line 10

def self.load_by_name(names)
  names = Array(names)
  instance = new
  names.map { |name| instance.load_from_gems(name) }.flatten
end

Instance Method Details

#load_from_gems(name = nil) ⇒ String

Load a single DNS plugin gem by name

Parameters:

  • name (String) (defaults to: nil)

    The name of the DNS plugin gem to load

Returns:

  • (String)

    The full require path to the specified gem



85
86
87
88
89
# File 'lib/vmpooler/dns.rb', line 85

def load_from_gems(name = nil)
  require_path = "vmpooler/dns/#{name.gsub('-', '/')}"
  require require_path
  require_path
end