Class: Designate::Zone

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

Constant Summary

Constants inherited from Client

Client::API_VERSION, Client::DOMAIN

Instance Method Summary collapse

Methods inherited from Client

#create_zone, #find_or_create_zone, #find_template_by_id, #find_zone_by_domain, #find_zone_by_id, #templates, #zones

Constructor Details

#initialize(data) ⇒ Zone

Returns a new instance of Zone.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/designate/zone.rb', line 4

def initialize(data)
  data.each do |key, value|
    instance_variable_set("@#{key}", value)
    Zone.instance_eval do
      attr_reader key.to_sym
    end
  end
  hosts = []
  data['hosts'].each { |host| hosts << Host.new(host) }
  @hosts = hosts
end

Instance Method Details

#create_host(host_type, data, options = {}) ⇒ Object

Raises:



35
36
37
38
39
40
41
42
43
# File 'lib/designate/zone.rb', line 35

def create_host(host_type, data, options = {})
  raise InvalidHostType unless %w(A AAAA CNAME MX NS SRV TXT).include?(host_type)
  options[:host_type] = host_type
  options[:hostname] ||= nil
  options[:data] = data
  if host = post("zones/#{id}/hosts.xml", { :host => options })
    return Host.new(host)
  end
end

#destroyObject



25
26
27
# File 'lib/designate/zone.rb', line 25

def destroy
  delete("zones/#{id}.xml")
end

#host(host_id) ⇒ Object



29
30
31
32
33
# File 'lib/designate/zone.rb', line 29

def host(host_id)
  if host = get("hosts/#{host_id}.xml")['host']
    Host.new(host)
  end
end

#update(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/designate/zone.rb', line 16

def update(options = {})
  options[:default_ttl] ||= 14400
  options[:nx_ttl] ||= 900
  if options[:zone_template_id]
    options[:follow_template] ||= 'no'
  end
  put("zones/#{id}.xml", { :zone => options })
end