Class: Designate::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/designate/client.rb

Direct Known Subclasses

Host, Template, Zone

Constant Summary collapse

API_VERSION =
"1.1"
DOMAIN =
"ns.zerigo.com"

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



9
10
11
12
# File 'lib/designate/client.rb', line 9

def initialize()
  @@auth_string = CGI.escape(zerigo_config[:username]) + ':' + CGI.escape(zerigo_config[:key])
  @domain = zerigo_config[:domain]
end

Instance Method Details

#create_zone(domain = @domain, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/designate/client.rb', line 36

def create_zone(domain = @domain, options = {})
  options[:domain] = domain
  options[:default_ttl] ||= 14400
  options[:nx_ttl] ||= 300
  if options[:zone_template_id]
    options[:follow_template] ||= 'no'
  end
  if zone = post("zones.xml", { :zone => options })['zone']
    Zone.new(zone)
  end
end

#find_or_create_zone(domain = @domain) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/designate/client.rb', line 48

def find_or_create_zone(domain = @domain)
  if zone = find_zone_by_domain(domain)
    return zone
  else
    create_zone(domain)
  end
end

#find_template_by_id(id) ⇒ Object



62
63
64
65
66
# File 'lib/designate/client.rb', line 62

def find_template_by_id(id)
  if template = get("zone_templates/#{id}.xml")['zone_template'] rescue false
    Template.new(template)
  end
end

#find_zone_by_domain(domain = @domain) ⇒ Object



30
31
32
33
34
# File 'lib/designate/client.rb', line 30

def find_zone_by_domain(domain = @domain)
  if zone = get("zones/#{domain}.xml")['zone'] rescue false
    Zone.new(zone)
  end
end

#find_zone_by_id(id) ⇒ Object



24
25
26
27
28
# File 'lib/designate/client.rb', line 24

def find_zone_by_id(id)
  if zone = get("zones/#{id}.xml")['zone'] rescue false
    Zone.new(zone)
  end
end

#templatesObject



56
57
58
59
60
# File 'lib/designate/client.rb', line 56

def templates
  templates = []
  get('zone_templates.xml')['zone_templates'].each { |template| templates << Template.new(template) }
  return templates
end

#zerigo_configObject



14
15
16
# File 'lib/designate/client.rb', line 14

def zerigo_config()
  YAML.load(File.new("config/zerigo.yml"))
end

#zonesObject



18
19
20
21
22
# File 'lib/designate/client.rb', line 18

def zones
  zones = []
  get('zones.xml')['zones'].each { |zone| zones << Zone.new(zone) }
  return zones
end