Class: Wamupd::MainSettings
- Inherits:
-
Object
- Object
- Wamupd::MainSettings
- Includes:
- Singleton
- Defined in:
- lib/wamupd/main_settings.rb
Overview
Simple singleton for storing app-side configuration-type things
Instance Attribute Summary collapse
-
#dns_port ⇒ Object
readonly
Port to use when talking to the DNS server.
-
#dns_server ⇒ Object
readonly
DNS server to try and update.
-
#dnssec_key_name ⇒ Object
readonly
DNSSEC key name (if nil, do not use DNSSEC).
-
#dnssec_key_value ⇒ Object
readonly
DNSSEC key value (usually, a HMAC-MD5 private key).
-
#hostname ⇒ Object
readonly
The current hostname, or, if present, the host name desired from the YAML.
-
#ipv4 ⇒ Object
readonly
Current IPv4 address.
-
#ipv6 ⇒ Object
readonly
Current IPv6 address.
-
#max_dns_response_time ⇒ Object
readonly
Maximum time to wait for DNS.
-
#priority ⇒ Object
readonly
Default priority of SRV records.
-
#sleep_time ⇒ Object
readonly
Minimum time to sleep between lease renewal checks.
-
#ttl ⇒ Object
readonly
Default TTL of records.
-
#weight ⇒ Object
readonly
Default weight of SRV records.
-
#zone ⇒ Object
readonly
Zone.
Instance Method Summary collapse
-
#clear ⇒ Object
Reset the MainSettings.
-
#get_ip_addresses ⇒ Object
Get IPv4 and IPv6 addresses.
-
#initialize ⇒ MainSettings
constructor
Constructor.
-
#lease_time ⇒ Object
The lease renewal time.
-
#load_from_yaml(yaml_file) ⇒ Object
Load some more settings from a YAML file.
-
#resolver ⇒ Object
Get a Dnsruby::Resolver.
-
#target ⇒ Object
Target for ops.
-
#using_dnssec? ⇒ Boolean
Are we using DNSSEC?.
-
#using_tcp? ⇒ Boolean
Should we be using TCP as our transport?.
Constructor Details
#initialize ⇒ MainSettings
Constructor. Use the instance() function to actually initialize
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/wamupd/main_settings.rb', line 79 def initialize @hostname = Socket.gethostname() @dns_port = 53 @ttl = 7200 @priority = 1 @weight = 5 @resolver = nil @ipv4 = nil @ipv6 = nil @sleep_time = 60 @max_dns_response_time=10 @zone = "" @transport = :udp end |
Instance Attribute Details
#dns_port ⇒ Object (readonly)
Port to use when talking to the DNS server
40 41 42 |
# File 'lib/wamupd/main_settings.rb', line 40 def dns_port @dns_port end |
#dns_server ⇒ Object (readonly)
DNS server to try and update
37 38 39 |
# File 'lib/wamupd/main_settings.rb', line 37 def dns_server @dns_server end |
#dnssec_key_name ⇒ Object (readonly)
DNSSEC key name (if nil, do not use DNSSEC)
43 44 45 |
# File 'lib/wamupd/main_settings.rb', line 43 def dnssec_key_name @dnssec_key_name end |
#dnssec_key_value ⇒ Object (readonly)
DNSSEC key value (usually, a HMAC-MD5 private key)
46 47 48 |
# File 'lib/wamupd/main_settings.rb', line 46 def dnssec_key_value @dnssec_key_value end |
#hostname ⇒ Object (readonly)
The current hostname, or, if present, the host name desired from the YAML
34 35 36 |
# File 'lib/wamupd/main_settings.rb', line 34 def hostname @hostname end |
#ipv4 ⇒ Object (readonly)
Current IPv4 address
61 62 63 |
# File 'lib/wamupd/main_settings.rb', line 61 def ipv4 @ipv4 end |
#ipv6 ⇒ Object (readonly)
Current IPv6 address
64 65 66 |
# File 'lib/wamupd/main_settings.rb', line 64 def ipv6 @ipv6 end |
#max_dns_response_time ⇒ Object (readonly)
Maximum time to wait for DNS
70 71 72 |
# File 'lib/wamupd/main_settings.rb', line 70 def max_dns_response_time @max_dns_response_time end |
#priority ⇒ Object (readonly)
Default priority of SRV records
55 56 57 |
# File 'lib/wamupd/main_settings.rb', line 55 def priority @priority end |
#sleep_time ⇒ Object (readonly)
Minimum time to sleep between lease renewal checks
67 68 69 |
# File 'lib/wamupd/main_settings.rb', line 67 def sleep_time @sleep_time end |
#ttl ⇒ Object (readonly)
Default TTL of records
52 53 54 |
# File 'lib/wamupd/main_settings.rb', line 52 def ttl @ttl end |
#weight ⇒ Object (readonly)
Default weight of SRV records
58 59 60 |
# File 'lib/wamupd/main_settings.rb', line 58 def weight @weight end |
#zone ⇒ Object (readonly)
Zone
49 50 51 |
# File 'lib/wamupd/main_settings.rb', line 49 def zone @zone end |
Instance Method Details
#clear ⇒ Object
Reset the MainSettings
133 134 135 |
# File 'lib/wamupd/main_settings.rb', line 133 def clear initialize end |
#get_ip_addresses ⇒ Object
Get IPv4 and IPv6 addresses
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/wamupd/main_settings.rb', line 171 def get_ip_addresses sa = MainSettings.instance begin s = UDPSocket.new(Socket::AF_INET) s.connect("8.8.8.8", 1) if (s.addr[0] == "AF_INET") @ipv4 = IPAddr.new(s.addr.last) end rescue SocketError => e $stderr.puts "Unable to determine IPv4 address: #{e}" rescue Errno::ENETUNREACH => e $stderr.puts "Unable to determine IPv4 address: #{e}" end puts "Finished acquiring IPv4 address" if $verbose # begin # s = UDPSocket.new(Socket::AF_INET6) # s.connect("2001:4860:b006::2", 1) # if (s.addr[0] == "AF_INET6") # @ipv6 = IPAddr.new(s.addr.last) # end # rescue SocketError => e # $stderr.puts "Unable to determine IPv6 address: #{e}" # rescue Errno::ENETUNREACH => e # $stderr.puts "Unable to determine IPv6 address: #{e}" # end # puts "Finished acquiring IPv6 address" if $verbose end |
#lease_time ⇒ Object
The lease renewal time. By default, ttl * (2/3)
73 74 75 |
# File 'lib/wamupd/main_settings.rb', line 73 def lease_time return (0.667 * @ttl).to_i end |
#load_from_yaml(yaml_file) ⇒ Object
Load some more settings from a YAML file
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/wamupd/main_settings.rb', line 109 def load_from_yaml(yaml_file) y = Psych.load_file(yaml_file) properties_map = { "hostname" => :@hostname, "dns_server" => :@dns_server, "dns_port" => :@dns_port, "dnssec_key_name" => :@dnssec_key_name, "dnssec_key_hmac" => :@dnssec_key_value, "zone" => :@zone, "ttl" => :@ttl, "srv_priority" => :@priority, "srv_weight" => :@weight, "sleep_time" => :@sleep_time, "transport" => :@transport, "max_dns_response_time" => :@max_dns_response_time, } properties_map.each { |k,v| if (y.has_key?(k)) self.instance_variable_set(v, y[k]) end } end |
#resolver ⇒ Object
Get a Dnsruby::Resolver
138 139 140 141 142 143 |
# File 'lib/wamupd/main_settings.rb', line 138 def resolver if (@resolver.nil?) make_resolver end return @resolver end |
#target ⇒ Object
Target for ops
100 101 102 103 104 105 106 |
# File 'lib/wamupd/main_settings.rb', line 100 def target t = "" t += @hostname t += "." t += @zone return t end |
#using_dnssec? ⇒ Boolean
Are we using DNSSEC?
95 96 97 |
# File 'lib/wamupd/main_settings.rb', line 95 def using_dnssec? return (not @dnssec_key_name.nil?) end |
#using_tcp? ⇒ Boolean
Should we be using TCP as our transport?
146 147 148 |
# File 'lib/wamupd/main_settings.rb', line 146 def using_tcp? return (@transport == "tcp" || @transport == :tcp) end |