Class: Netdot::Host
- Inherits:
-
Object
- Object
- Netdot::Host
- Defined in:
- lib/netdot/host.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
-
#create(name, ip) ⇒ Object
Create A record for given name and IP Will also create PTR record if .arpa zone exists.
-
#delete(name) ⇒ Object
Delete A record for given name.
-
#find(param, value) ⇒ Object
Find RR and Ipblock records with flexible arguments Handle exceptions.
-
#find_by_ip(ip) ⇒ Object
Find RR and Ipblock records associated with this IP.
-
#find_by_name(name) ⇒ Object
Find RR and Ipblock records associated with given name.
-
#initialize(argv = {}) ⇒ Host
constructor
A new instance of Host.
-
#update(name, ip) ⇒ Object
Update A record for given name and IP Will also create PTR record if .arpa zone exists.
Constructor Details
#initialize(argv = {}) ⇒ Host
Returns a new instance of Host.
5 6 7 8 9 10 11 |
# File 'lib/netdot/host.rb', line 5 def initialize(argv = {}) [:connection].each do |k| raise ArgumentError, "Missing required argument '#{k}'" unless argv[k] end argv.each { |k,v| instance_variable_set("@#{k}", v) } end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
3 4 5 |
# File 'lib/netdot/host.rb', line 3 def connection @connection end |
Instance Method Details
#create(name, ip) ⇒ Object
Create A record for given name and IP Will also create PTR record if .arpa zone exists
42 43 44 45 |
# File 'lib/netdot/host.rb', line 42 def create(name, ip) Netdot.logger.debug("Creating new DNS records with name:#{name} and ip:#{ip}") @connection.post('host', {'name' => name, 'address' => ip}) end |
#delete(name) ⇒ Object
Delete A record for given name
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/netdot/host.rb', line 59 def delete(name) host = find_by_name(name) return unless host # remove any associated IP addresses Netdot.logger.debug("Removing IP records for #{name}") host['Ipblock'].keys.each do |id| begin @connection.delete("host?ipid=#{id}") rescue Exception => e # Not Found is ok, otherwise re-raise raise unless (e. =~ /404/) end end end |
#find(param, value) ⇒ Object
Find RR and Ipblock records with flexible arguments Handle exceptions
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/netdot/host.rb', line 16 def find(param, value) begin host = @connection.get("/host?#{param.to_s}=#{value}"); rescue Exception => e # Not Found is ok, otherwise re-raise raise unless (e. =~ /404/) end # Return what we got host end |
#find_by_ip(ip) ⇒ Object
Find RR and Ipblock records associated with this IP
35 36 37 |
# File 'lib/netdot/host.rb', line 35 def find_by_ip(ip) find(:address, ip) end |
#find_by_name(name) ⇒ Object
Find RR and Ipblock records associated with given name
29 30 31 |
# File 'lib/netdot/host.rb', line 29 def find_by_name(name) find(:name, name) end |
#update(name, ip) ⇒ Object
Update A record for given name and IP Will also create PTR record if .arpa zone exists
50 51 52 53 54 55 |
# File 'lib/netdot/host.rb', line 50 def update(name, ip) Netdot.logger.debug("Updating DNS records with name:#{name} and ip:#{ip}") delete(name) #delete_by_ip(ip) create(name, ip) end |