Class: Oxidized::Nodes

Inherits:
Array
  • Object
show all
Defined in:
lib/oxidized/nodes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#jobsObject

Returns the value of attribute jobs.



7
8
9
# File 'lib/oxidized/nodes.rb', line 7

def jobs
  @jobs
end

#sourceObject

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_name, group) ⇒ Object



59
60
61
62
63
# File 'lib/oxidized/nodes.rb', line 59

def fetch node_name, group
  yield_node_output(node_name) do |node, output|
    output.fetch node, group
  end
end

#find_node_index(node) ⇒ Fixnum

Returns index number of node in Nodes.

Parameters:

  • node

    node whose index number in Nodes to find

Returns:

  • (Fixnum)

    index number of node in Nodes



91
92
93
# File 'lib/oxidized/nodes.rb', line 91

def find_node_index node
  find_index node or raise Oxidized::NodeNotFound, "unable to find '#{node}'"
end

#getString

Returns node from the head of the array.

Returns:

  • (String)

    node from the head of the array



83
84
85
86
87
# File 'lib/oxidized/nodes.rb', line 83

def get
  with_lock do
    (self << shift).last
  end
end

#get_diff(node_name, group, oid1, oid2) ⇒ Object



107
108
109
110
111
# File 'lib/oxidized/nodes.rb', line 107

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



101
102
103
104
105
# File 'lib/oxidized/nodes.rb', line 101

def get_version node_name, group, oid
  yield_node_output(node_name) do |node, output|
    output.get_version node, group, oid
  end
end

#listObject



46
47
48
49
50
# File 'lib/oxidized/nodes.rb', line 46

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
30
# File 'lib/oxidized/nodes.rb', line 9

def load node_want=nil
  with_lock do
    new = []
    @source = Oxidized.config.source.default
    Oxidized.mgr.add_source @source
    Oxidized.logger.info "lib/oxidized/nodes.rb: Loading nodes"
    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
        Oxidized.logger.error "node %s raised %s with message '%s'" % [node, err.class, err.message]
      rescue Resolv::ResolvError => err
        Oxidized.logger.error "node %s is not resolvable, raised %s with message '%s'" % [node, err.class, err.message]
      end
    end
    size == 0 ? 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

Parameters:

  • node (String)

    name of the node moved into the head of array



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/oxidized/nodes.rb', line 66

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
      jobs.want += 1 if Oxidized.config.next_adds_job?
    end
  end
end

#node_want?(node_want, node) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/oxidized/nodes.rb', line 32

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



52
53
54
55
56
57
# File 'lib/oxidized/nodes.rb', line 52

def show node
  with_lock do
    i = find_node_index node
    self[i].serialize
  end
end

#version(node_name, group) ⇒ Object



95
96
97
98
99
# File 'lib/oxidized/nodes.rb', line 95

def version node_name, group
  yield_node_output(node_name) do |node, output|
    output.version node, group
  end
end