Class: Rubber::Dns::Nettica

Inherits:
Base
  • Object
show all
Defined in:
lib/rubber/dns/nettica.rb

Instance Attribute Summary

Attributes inherited from Base

#env

Instance Method Summary collapse

Methods inherited from Base

#destroy, #hostname, #up_to_date, #update

Constructor Details

#initialize(env) ⇒ Nettica

Returns a new instance of Nettica.



7
8
9
10
11
12
13
# File 'lib/rubber/dns/nettica.rb', line 7

def initialize(env)
  super(env)
  @nettica_env = @env.dns_providers.nettica
  @client = ::Nettica::Client.new(@nettica_env.user, @nettica_env.password)
  @ttl = (@nettica_env.ttl || 300).to_i
  @record_type = @nettica_env.record_type || "A"
end

Instance Method Details

#create_host_record(host, ip) ⇒ Object



25
26
27
28
# File 'lib/rubber/dns/nettica.rb', line 25

def create_host_record(host, ip)
  new = @client.create_domain_record(env.domain, host, @record_type, ip, @ttl, 0)
  @client.add_record(new)
end

#destroy_host_record(host) ⇒ Object



30
31
32
33
34
# File 'lib/rubber/dns/nettica.rb', line 30

def destroy_host_record(host)
  old_record = @client.list_domain(env.domain).record.find {|r| r.hostName == host }
  old = @client.create_domain_record(env.domain, host, old_record.recordType, old_record.data, old_record.tTL, old_record.priority)
  @client.delete_record(old)
end

#host_exists?(host) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/rubber/dns/nettica.rb', line 19

def host_exists?(host)
  domain_info = @client.list_domain(env.domain)
  raise "Domain needs to exist in nettica before records can be updated" unless domain_info.record
  return domain_info.record.any? { |r| r.hostName == host }
end

#nameserverObject



15
16
17
# File 'lib/rubber/dns/nettica.rb', line 15

def nameserver
  "dns1.nettica.com"
end

#update_domain_record(ip) ⇒ Object

update the top level domain record which has an empty hostName



42
43
44
45
# File 'lib/rubber/dns/nettica.rb', line 42

def update_domain_record(ip)
  old_record = @client.list_domain(env.domain).record.find {|r| r.hostName == '' and r.recordType == 'A' and r.data =~ /\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/}
  update_record('', ip, old_record)
end

#update_host_record(host, ip) ⇒ Object



36
37
38
39
# File 'lib/rubber/dns/nettica.rb', line 36

def update_host_record(host, ip)
  old_record = @client.list_domain(env.domain).record.find {|r| r.hostName == host }
  update_record(host, ip, old_record)
end

#update_record(host, ip, old_record) ⇒ Object



47
48
49
50
51
# File 'lib/rubber/dns/nettica.rb', line 47

def update_record(host, ip, old_record)
  old = @client.create_domain_record(env.domain, host, old_record.recordType, old_record.data, old_record.tTL, old_record.priority)
  new = @client.create_domain_record(env.domain, host, @record_type, ip, @ttl, 0)
  @client.update_record(old, new)
end