Class: Gaff::Dynect_api

Inherits:
Object
  • Object
show all
Defined in:
lib/gaff/dynect_api.rb

Class Method Summary collapse

Class Method Details

.exec(msg) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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/gaff/dynect_api.rb', line 4

def self.exec(msg)
  parser = Yajl::Parser.new
  hash = parser.parse(msg)
 
  Gaff::Log.debug(hash)
  STDOUT.flush
  
  begin
    dynect = DynectRest.new(
      hash["params"]["customer_name"], 
      hash["params"]["username"], 
      hash["params"]["password"], 
      hash["params"]["zone"])
                        
    Gaff::Log.debug(dynect)
    STDOUT.flush
  
    case hash["method"]
    when "add_a_record"
      result = dynect.a.fqdn("#{hash["params"]["node"]}.#{hash["params"]["zone"]}").ttl(hash["params"]["ttl"]).address(hash["params"]["rdata"]).save
      publish = dynect.publish
    when "add_cname_record"
      result = dynect.cname.fqdn("#{hash["params"]["node"]}.#{hash["params"]["zone"]}").ttl(hash["params"]["ttl"]).cname(hash["params"]["rdata"]).save
      publish = dynect.publish  
    when "delete_a_record"
      result = dynect.a.fqdn("#{hash["params"]["node"]}.#{hash["params"]["zone"]}").delete
      publish = dynect.publish
    when "delete_cname_record"
      result = dynect.cname.fqdn("#{hash["params"]["node"]}.#{hash["params"]["zone"]}").delete
      publish = dynect.publish
    end
    
    Gaff::Log.info(result)
    Gaff::Log.debug(publish)
    STDOUT.flush        
  rescue Exception => e
    Gaff::Log.error(e)
    STDOUT.flush
  end
end