Sha256: 6994e3a1cd4b10039fb5ddf0540ac879eea65d4f709763dba77be4f2945a7386

Contents?: true

Size: 1.58 KB

Versions: 22

Compression:

Stored size: 1.58 KB

Contents

module Rubber
  module Dns

    class Base

      attr_reader :env

      def initialize(env)
        @env = env
      end

      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

      def destroy(host)
        if host_exists?(host)
          puts "Destroying dynamic DNS record: #{host}"
          destroy_host_record(host)
        end
      end

      def hostname(host)
        "#{host}.#{@env.domain}"
      end

      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

      def nameserver()
        raise "nameserver not implemented"
      end

      def host_exists?(host)
        raise "host_exists? not implemented"
      end

      def create_host_record(host, ip)
        raise "create_host_record not implemented"
      end

      def destroy_host_record(host)
        raise "destroy_host_record not implemented"
      end

      def update_host_record(host, ip)
        raise "update_host_record not implemented"
      end

    end

  end
end

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
sml-rubber-0.9.1 lib/rubber/dns/base.rb
sml-rubber-0.9.10 lib/rubber/dns/base.rb
sml-rubber-0.9.11 lib/rubber/dns/base.rb
sml-rubber-0.9.13 lib/rubber/dns/base.rb
sml-rubber-0.9.3 lib/rubber/dns/base.rb
sml-rubber-0.9.4 lib/rubber/dns/base.rb
sml-rubber-0.9.5 lib/rubber/dns/base.rb
sml-rubber-0.9.6 lib/rubber/dns/base.rb
sml-rubber-0.9.7 lib/rubber/dns/base.rb
sml-rubber-0.9.8 lib/rubber/dns/base.rb
sml-rubber-0.9.9 lib/rubber/dns/base.rb
wr0ngway-rubber-1.0.0 lib/rubber/dns/base.rb
wr0ngway-rubber-1.0.1 lib/rubber/dns/base.rb
axtro-rubber-1.0.2.8 lib/rubber/dns/base.rb
axtro-rubber-1.0.2.7 lib/rubber/dns/base.rb
axtro-rubber-1.0.2.6 lib/rubber/dns/base.rb
axtro-rubber-1.0.2.5 lib/rubber/dns/base.rb
axtro-rubber-1.0.2.4 lib/rubber/dns/base.rb
axtro-rubber-1.0.2.3 lib/rubber/dns/base.rb
axtro-rubber-1.0.2.2 lib/rubber/dns/base.rb