Class: Oxidized::Nodes
- Inherits:
-
Array
- Object
- Array
- Oxidized::Nodes
- Defined in:
- lib/oxidized/nodes.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #fetch(node, group) ⇒ Object
-
#find_node_index(node) ⇒ Fixnum
Index number of node in Nodes.
-
#get ⇒ String
Node from the head of the array.
- #get_diff(node, group, oid1, oid2) ⇒ Object
- #get_version(node, 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, group) ⇒ Object
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/oxidized/nodes.rb', line 7 def source @source end |
Instance Method Details
#fetch(node, group) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/oxidized/nodes.rb', line 58 def fetch node, group with_lock do i = find_node_index node output = self[i].output.new raise Oxidized::NotSupported unless output.respond_to? :fetch output.fetch node, group end end |
#find_node_index(node) ⇒ Fixnum
Returns index number of node in Nodes.
92 93 94 |
# File 'lib/oxidized/nodes.rb', line 92 def find_node_index node find_index node or raise Oxidized::NodeNotFound, "unable to find '#{node}'" end |
#get ⇒ String
Returns node from the head of the array.
84 85 86 87 88 |
# File 'lib/oxidized/nodes.rb', line 84 def get with_lock do (self << shift).last end end |
#get_diff(node, group, oid1, oid2) ⇒ Object
172 173 174 175 176 177 178 179 |
# File 'lib/oxidized/nodes.rb', line 172 def get_diff node, group, oid1, oid2 with_lock do i = find_node_index node output = self[i].output.new raise Oxidized::NotSupported unless output.respond_to? :fetch output.get_diff node, group, oid1, oid2 end end |
#get_version(node, group, oid) ⇒ Object
163 164 165 166 167 168 169 170 |
# File 'lib/oxidized/nodes.rb', line 163 def get_version node, group, oid with_lock do i = find_node_index node output = self[i].output.new raise Oxidized::NotSupported unless output.respond_to? :fetch output.get_version node, group, oid end end |
#list ⇒ Object
45 46 47 48 49 |
# File 'lib/oxidized/nodes.rb', line 45 def list with_lock do map { |e| e.serialize } end end |
#load(node_want = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/oxidized/nodes.rb', line 9 def load node_want=nil with_lock do new = [] @source = CFG.source.default Oxidized.mgr.add_source @source Oxidized.mgr.source[@source].new.load.each do |node| # we want to load specific node(s), not all of them next unless node_want? node_want, node begin _node = Node.new node new.push _node rescue ModelNotFound => err Log.error "node %s raised %s with message '%s'" % [node, err.class, err.] rescue Resolv::ResolvError => err Log.error "node %s is not resolvable, raised %s with message '%s'" % [node, err.class, err.] end end size == 0 ? replace(new) : update_nodes(new) Log.info "Loaded #{size} nodes" end end |
#next(node, opt = {}) ⇒ Object Also known as: top
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/oxidized/nodes.rb', line 68 def next node, opt={} if waiting.find_node_index(node) with_lock do n = del node n.user = opt['user'] 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 end end end |
#node_want?(node_want, node) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/oxidized/nodes.rb', line 31 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) if name_is_ip and node_want_ip == node[:name] true elsif node[:ip] and node_want_ip == node[:ip] true elsif node_want.match node[:name] true unless name_is_ip end end |
#show(node) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/oxidized/nodes.rb', line 51 def show node with_lock do i = find_node_index node self[i].serialize end end |
#version(node, group) ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'lib/oxidized/nodes.rb', line 154 def version node, group with_lock do i = find_node_index node output = self[i].output.new raise Oxidized::NotSupported unless output.respond_to? :fetch output.version node, group end end |