Class: Rig::Model::Dns

Inherits:
Object
  • Object
show all
Defined in:
lib/rig/model/dns.rb

Class Method Summary collapse

Class Method Details

.allObject



8
9
10
# File 'lib/rig/model/dns.rb', line 8

def all
  Rig::Connection.dns.zones.all
end

.create(name, value, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rig/model/dns.rb', line 26

def create(name, value, options={})
  zone = zone(Rig.get_config(:dns_zone))

  if IPAddress.valid?(value)
    #A record
    o = {:name => name, :value => value, :type => 'A', :ttl => 86400}.merge(options)
  else
    #CNAME record
    o = {:name => name, :value => value, :type => 'CNAME', :ttl => 300}.merge(options)
  end
  zone.records.create(o)
end

.destroy(name) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rig/model/dns.rb', line 39

def destroy(name)
  zone = zone(Rig.get_config(:dns_zone))
  name = name.gsub(/\.$/, '')
  # cant seem to make zone.records#get or zone.records#find work correctly
  list = zone.records.all.select {|e| e.attributes[:name] == "#{name}."}
  record = list.first
  if record
    Rig::Log.info ".. destroying zone: #{name}"
    record.destroy
  else
    Rig::Log.info "record not found: #{name}"
  end
end

.records(zone) ⇒ Object



16
17
18
# File 'lib/rig/model/dns.rb', line 16

def records(zone)
  zone(zone).records
end

.remove_environment(name) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/rig/model/dns.rb', line 53

def remove_environment(name)
  zone = zone(Rig.get_config(:dns_zone))
  list = zone.records.all.select {|e| e.attributes[:name] =~ /\.#{name}\.#{Rig.get_config(:dns_subdomain)}/ }
  list.each do |e|
    Rig::Log.info "record: #{e.attributes[:name]}"
    destroy(e.attributes[:name])
  end
end

.remove_instance(dns) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/rig/model/dns.rb', line 62

def remove_instance(dns)
  zone = zone(Rig.get_config(:dns_zone))
  dns = dns.gsub(/\.$/, '')
  list = zone.records.all.select {|e| e.attributes[:value] == "#{dns}." }
  list.each do |e|
    Rig::Log.info "record: #{e.attributes[:name]}"
    destroy(e.attributes[:name])
  end
end

.zone(zone) ⇒ Object



12
13
14
# File 'lib/rig/model/dns.rb', line 12

def zone(zone)
  Rig::Connection.dns.zones.find(zone).first
end

.zone_create(name) ⇒ Object



20
21
22
23
24
# File 'lib/rig/model/dns.rb', line 20

def zone_create(name)
  Rig::Connection.dns.zones.create(
      :domain => name
  )
end