20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/ssp/application/domain.rb', line 20
def update(domain, ip)
host, domain = domain.split(".", 2)
if domain.index('.').nil?
domain, host = "#{host}.#{domain}", ""
end
zone = linode.domain.list.detect do |d|
d.domain == domain
end
raise Thor::Error, "Zone not found for #{domain}" unless zone
records = linode.domain.resource.list(:domainid => zone.domainid)
if current_record = records.detect {|r| r.type == "A" && r.name == host}
record = linode.domain.resource.update :domainid => zone.domainid, :resourceid => current_record.resourceid, :target => ip, :ttl_sec => options[:ttl]
unless record.resourceid
raise Thor::Error, "Failed to update the record for #{host} in #{domain}"
end
else
record = linode.domain.resource.create :domainid => zone.domainid, :type => "A", :name => host, :target => ip, :ttl_sec => options[:ttl]
unless record.resourceid
raise Thor::Error, "Failed to create a new record for #{host} in #{domain}"
end
end
end
|