Class: Netdot::Host
- Inherits:
-
Object
- Object
- Netdot::Host
- Defined in:
- lib/netdot/host.rb
Overview
Manage Host objects.
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
-
#create(name, ip) ⇒ Object
Creates a DNS A record for the specified name and IP.
-
#delete(name) ⇒ Object
Deletes the DNS A record for the specified name.
-
#find(param, value) ⇒ Object
Finds all RR and Ipblock records, given a flexible set of arguments.
-
#find_by_ip(ip) ⇒ Object
Finds all RR and Ipblock records associated with the specified IP.
-
#find_by_name(name) ⇒ Object
Finds all RR and Ipblock records associated with the specified name.
-
#initialize(argv = {}) ⇒ Host
constructor
Constructor.
-
#update(name, ip) ⇒ Object
Updates the DNS A record for the sepcified name and IP.
Constructor Details
#initialize(argv = {}) ⇒ Host
Constructor
9 10 11 12 13 14 15 |
# File 'lib/netdot/host.rb', line 9 def initialize(argv = {}) [:connection].each do |k| fail 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.
5 6 7 |
# File 'lib/netdot/host.rb', line 5 def connection @connection end |
Instance Method Details
#create(name, ip) ⇒ Object
Creates a DNS A record for the specified name and IP. Will also create PTR record if .arpa zone exists.
48 49 50 51 52 |
# File 'lib/netdot/host.rb', line 48 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
Deletes the DNS A record for the specified name.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/netdot/host.rb', line 66 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 => e # Not Found is ok, otherwise re-raise raise unless e. =~ /404/ end end end |
#find(param, value) ⇒ Object
Finds all RR and Ipblock records, given a flexible set of arguments. Handles NOT FOUND exceptions.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/netdot/host.rb', line 21 def find(param, value) begin host = @connection.get("/host?#{param}=#{value}") rescue => e # Not Found is ok, otherwise re-raise raise unless e. =~ /404/ end # Return what we got host end |
#find_by_ip(ip) ⇒ Object
Finds all RR and Ipblock records associated with the specified IP.
40 41 42 |
# File 'lib/netdot/host.rb', line 40 def find_by_ip(ip) find(:address, ip) end |
#find_by_name(name) ⇒ Object
Finds all RR and Ipblock records associated with the specified name.
34 35 36 |
# File 'lib/netdot/host.rb', line 34 def find_by_name(name) find(:name, name) end |
#update(name, ip) ⇒ Object
Updates the DNS A record for the sepcified name and IP. Will also create PTR record if .arpa zone exists.
58 59 60 61 62 |
# File 'lib/netdot/host.rb', line 58 def update(name, ip) Netdot.logger.debug("Updating DNS records with name:#{name} and ip:#{ip}") delete(name) create(name, ip) end |