Class: Sunzi::DNS::Linode

Inherits:
Base
  • Object
show all
Defined in:
lib/sunzi/dns/linode.rb

Instance Method Summary collapse

Methods included from Utility

#abort_with, #exit_with, #say

Constructor Details

#initialize(config, cloud) ⇒ Linode

Returns a new instance of Linode.



6
7
8
9
10
11
# File 'lib/sunzi/dns/linode.rb', line 6

def initialize(config, cloud)
  @api = ::Linode.new(:api_key => (cloud == 'linode') ? config['api_key'] : config['linode']['api_key'])
  zone = config['fqdn']['zone']
  @domain = @api.domain.list.find{|i| i.domain == zone }
  abort_with "zone for #{zone} was not found on Linode DNS!" unless @domain
end

Instance Method Details

#add(fqdn, ip) ⇒ Object



13
14
15
16
# File 'lib/sunzi/dns/linode.rb', line 13

def add(fqdn, ip)
  say 'adding the public IP to Linode DNS Manager...'
  @api.domain.resource.create(:DomainID => @domain.domainid, :Type => 'A', :Name => fqdn, :Target => ip)
end

#delete(ip) ⇒ Object



18
19
20
21
22
23
# File 'lib/sunzi/dns/linode.rb', line 18

def delete(ip)
  say 'deleting the public IP from Linode DNS Manager...'
  resource = @api.domain.resource.list(:DomainID => @domain.domainid).find{|i| i.target == ip }
  abort_with "ip address #{ip} was not found on Linode DNS!" unless resource
  @api.domain.resource.delete(:DomainID => @domain.domainid, :ResourceID => resource.resourceid)
end