Class: Rubber::Dns::Base
- Inherits:
-
Object
- Object
- Rubber::Dns::Base
- Defined in:
- lib/rubber/dns/base.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #create_host_record(host, ip) ⇒ Object
- #destroy(host) ⇒ Object
- #destroy_host_record(host) ⇒ Object
- #host_exists?(host) ⇒ Boolean
- #hostname(host) ⇒ Object
-
#initialize(env) ⇒ Base
constructor
A new instance of Base.
- #nameserver ⇒ Object
- #up_to_date(host, ip) ⇒ Object
- #update(host, ip) ⇒ Object
- #update_host_record(host, ip) ⇒ Object
Constructor Details
#initialize(env) ⇒ Base
Returns a new instance of Base.
8 9 10 |
# File 'lib/rubber/dns/base.rb', line 8 def initialize(env) @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/rubber/dns/base.rb', line 6 def env @env end |
Instance Method Details
#create_host_record(host, ip) ⇒ Object
54 55 56 |
# File 'lib/rubber/dns/base.rb', line 54 def create_host_record(host, ip) raise "create_host_record not implemented" end |
#destroy(host) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rubber/dns/base.rb', line 26 def destroy(host) if host_exists?(host) puts "Destroying dynamic DNS record: #{host}" destroy_host_record(host) end end |
#destroy_host_record(host) ⇒ Object
58 59 60 |
# File 'lib/rubber/dns/base.rb', line 58 def destroy_host_record(host) raise "destroy_host_record not implemented" end |
#host_exists?(host) ⇒ Boolean
50 51 52 |
# File 'lib/rubber/dns/base.rb', line 50 def host_exists?(host) raise "host_exists? not implemented" end |
#hostname(host) ⇒ Object
33 34 35 |
# File 'lib/rubber/dns/base.rb', line 33 def hostname(host) "#{host}.#{@env.domain}" end |
#nameserver ⇒ Object
46 47 48 |
# File 'lib/rubber/dns/base.rb', line 46 def nameserver() raise "nameserver not implemented" end |
#up_to_date(host, ip) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/rubber/dns/base.rb', line 37 def up_to_date(host, ip) # This queries dns server directly instead of using hosts file current_ip = nil Resolv::DNS.open(:nameserver => [nameserver], :search => [], :ndots => 1) do |dns| current_ip = dns.getaddress(hostname(host)).to_s rescue nil end return ip == current_ip end |
#update(host, ip) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rubber/dns/base.rb', line 12 def update(host, ip) if up_to_date(host, ip) puts "IP has not changed for #{host}, not updating dynamic DNS" else if ! host_exists?(host) puts "Creating dynamic DNS: #{host} => #{ip}" create_host_record(host, ip) else puts "Updating dynamic DNS: #{host} => #{ip}" update_host_record(host, ip) end end end |
#update_host_record(host, ip) ⇒ Object
62 63 64 |
# File 'lib/rubber/dns/base.rb', line 62 def update_host_record(host, ip) raise "update_host_record not implemented" end |