Class: Oxidized::Nodes
- Inherits:
-
Array
- Object
- Array
- Oxidized::Nodes
- Defined in:
- lib/oxidized/nodes.rb
Instance Attribute Summary collapse
-
#jobs ⇒ Object
Returns the value of attribute jobs.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
-
#fetch(node_name, group) ⇒ Object
Returns the configuration of group/node_name.
- #find_index(node) ⇒ Object
-
#find_node_index(node) ⇒ Fixnum
Index number of node in Nodes.
-
#get ⇒ String
Node from the head of the array.
- #get_diff(node_name, group, oid1, oid2) ⇒ Object
- #get_version(node_name, group, oid) ⇒ Object
- #list ⇒ Object
- #load(node_want = nil) ⇒ Object
- #next(node, opt = {}) ⇒ Object (also: #top)
- #node_want?(node_want, node) ⇒ Boolean
- #show(node) ⇒ Object
-
#version(node_name, group) ⇒ Object
Returns all stored versions of group/node_name.
Instance Attribute Details
#jobs ⇒ Object
Returns the value of attribute jobs.
8 9 10 |
# File 'lib/oxidized/nodes.rb', line 8 def jobs @jobs end |
#source ⇒ Object
Returns the value of attribute source.
8 9 10 |
# File 'lib/oxidized/nodes.rb', line 8 def source @source end |
Instance Method Details
#fetch(node_name, group) ⇒ Object
Returns the configuration of group/node_name
#fetch is called by oxidzed-web
67 68 69 70 71 |
# File 'lib/oxidized/nodes.rb', line 67 def fetch(node_name, group) yield_node_output(node_name) do |node, output| output.fetch node, group end end |
#find_index(node) ⇒ Object
125 126 127 |
# File 'lib/oxidized/nodes.rb', line 125 def find_index(node) index { |e| [e.name, e.ip].include? node } end |
#find_node_index(node) ⇒ Fixnum
Returns index number of node in Nodes.
100 101 102 |
# File 'lib/oxidized/nodes.rb', line 100 def find_node_index(node) find_index(node) || raise(NodeNotFound, "unable to find '#{node}'") end |
#get ⇒ String
Returns node from the head of the array.
92 93 94 95 96 |
# File 'lib/oxidized/nodes.rb', line 92 def get with_lock do (self << shift).last end end |
#get_diff(node_name, group, oid1, oid2) ⇒ Object
119 120 121 122 123 |
# File 'lib/oxidized/nodes.rb', line 119 def get_diff(node_name, group, oid1, oid2) yield_node_output(node_name) do |node, output| output.get_diff node, group, oid1, oid2 end end |
#get_version(node_name, group, oid) ⇒ Object
113 114 115 116 117 |
# File 'lib/oxidized/nodes.rb', line 113 def get_version(node_name, group, oid) yield_node_output(node_name) do |node, output| output.get_version node, group, oid end end |
#list ⇒ Object
51 52 53 54 55 |
# File 'lib/oxidized/nodes.rb', line 51 def list with_lock do map { |e| e.serialize } end end |
#load(node_want = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/oxidized/nodes.rb', line 10 def load(node_want = nil) with_lock do new = [] @source = Oxidized.config.source.default Oxidized.mgr.add_source(@source) || raise(MethodNotFound, "cannot load node source '#{@source}', not found") Oxidized.logger.info "lib/oxidized/nodes.rb: Loading nodes" nodes = Oxidized.mgr.source[@source].new.load node_want nodes.each do |node| # we want to load specific node(s), not all of them next unless node_want? node_want, node begin node_obj = Node.new node new.push node_obj rescue ModelNotFound => e Oxidized.logger.error "node %s raised %s with message '%s'" % [node, e.class, e.] rescue Resolv::ResolvError => e Oxidized.logger.error "node %s is not resolvable, raised %s with message '%s'" % [node, e.class, e.] end end size.zero? ? replace(new) : update_nodes(new) Oxidized.logger.info "lib/oxidized/nodes.rb: Loaded #{size} nodes" end end |
#next(node, opt = {}) ⇒ Object Also known as: top
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/oxidized/nodes.rb', line 74 def next(node, opt = {}) return if running.find_index(node) with_lock do n = del node n.user = opt['user'] n.email = opt['email'] n.msg = opt['msg'] n.from = opt['from'] # set last job to nil so that the node is picked for immediate update n.last = nil put n jobs.increment if Oxidized.config.next_adds_job? end end |
#node_want?(node_want, node) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/oxidized/nodes.rb', line 35 def node_want?(node_want, node) return true unless node_want node_want_ip = (IPAddr.new(node_want) rescue false) name_is_ip = (IPAddr.new(node[:name]) rescue false) # rubocop:todo Lint/DuplicateBranch if name_is_ip && (node_want_ip == node[:name]) true elsif node[:ip] && (node_want_ip == node[:ip]) true elsif node_want.match node[:name] true unless name_is_ip end # rubocop:enable Lint/DuplicateBranch end |
#show(node) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/oxidized/nodes.rb', line 57 def show(node) with_lock do i = find_node_index node self[i].serialize end end |
#version(node_name, group) ⇒ Object
Returns all stored versions of group/node_name
Called by oxidized-web
107 108 109 110 111 |
# File 'lib/oxidized/nodes.rb', line 107 def version(node_name, group) yield_node_output(node_name) do |node, output| output.version node, group end end |