Class: IptablesWeb::Model::Node

Inherits:
Base
  • Object
show all
Defined in:
lib/iptables_web/model/node.rb

Class Method Summary collapse

Methods inherited from Base

access_token=, api_base_url=

Class Method Details

.handshake(&block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/iptables_web/model/node.rb', line 7

def self.handshake(&block)
  node = find('current')
  if node
    begin
      block.call if block
    rescue Exception => e
      node.has_errors = true
      node.report = 'Exception: ' + e.message
      node.report << "\n"
      node.report << 'Backtrace: ' + e.backtrace.join("\n")
      raise e
    ensure
      # save node after updating
      node.ips = []
      ::System.get_ifaddrs.each do |interface, config|
        next if interface.to_s.include?('lo')
        node.ips.push({
            interface: interface,
            ip: config[:inet_addr],
            netmask: config[:netmask]
          })
      end
      node.ips.uniq! { |ip| ip[:ip] }
      node.hostname = `hostname -f`
      node.save
    end
  end
end