|
33 | 33 | if other_names |
34 | 34 | peer_list += ',' + other_names |
35 | 35 | end |
36 | | - # note the stderr redirection here |
37 | | - # `gluster volume list` spits to stderr :( |
38 | | - output = Facter::Util::Resolution.exec("#{binary} volume list 2>&1") |
39 | | - if output != 'No volumes present in cluster' |
40 | | - output.split.each do |vol| |
41 | | - # If a brick has trailing informaion such as (arbiter) remove it |
42 | | - info = Facter::Util::Resolution.exec("#{binary} volume info #{vol} | sed 's/ (arbiter)//g'") |
43 | | - # rubocop:disable Metrics/BlockNesting |
44 | | - vol_status = Regexp.last_match[1] if info =~ %r{^Status: (.+)$} |
45 | | - bricks = info.scan(%r{^Brick[^:]+: (.+)$}).flatten |
46 | | - volume_bricks[vol] = bricks |
47 | | - options = info.scan(%r{^(\w+\.[^:]+: .+)$}).flatten |
48 | | - volume_options[vol] = options if options |
49 | | - next unless vol_status == 'Started' |
50 | | - status = Facter::Util::Resolution.exec("#{binary} volume status #{vol} 2>/dev/null") |
51 | | - if status =~ %r{^Brick} |
52 | | - volume_ports[vol] = status.scan(%r{^Brick [^\t]+\t+(\d+)}).flatten.uniq.sort |
53 | | - end |
| 36 | + end |
| 37 | + # note the stderr redirection here |
| 38 | + # `gluster volume list` spits to stderr :( |
| 39 | + output = Facter::Util::Resolution.exec("#{binary} volume list 2>&1") |
| 40 | + if output != 'No volumes present in cluster' |
| 41 | + output.split.each do |vol| |
| 42 | + # If a brick has trailing informaion such as (arbiter) remove it |
| 43 | + info = Facter::Util::Resolution.exec("#{binary} volume info #{vol} | sed 's/ (arbiter)//g'") |
| 44 | + # rubocop:disable Metrics/BlockNesting |
| 45 | + vol_status = Regexp.last_match[1] if info =~ %r{^Status: (.+)$} |
| 46 | + bricks = info.scan(%r{^Brick[^:]+: (.+)$}).flatten |
| 47 | + volume_bricks[vol] = bricks |
| 48 | + options = info.scan(%r{^(\w+\.[^:]+: .+)$}).flatten |
| 49 | + volume_options[vol] = options if options |
| 50 | + next unless vol_status == 'Started' |
| 51 | + status = Facter::Util::Resolution.exec("#{binary} volume status #{vol} 2>/dev/null") |
| 52 | + if status =~ %r{^Brick} |
| 53 | + volume_ports[vol] = status.scan(%r{^Brick [^\t]+\t+(\d+)}).flatten.uniq.sort |
54 | 54 | end |
55 | 55 | end |
56 | 56 | end |
|
62 | 62 | end |
63 | 63 | end |
64 | 64 |
|
65 | | - # these facts doesn't make sense without peers |
66 | | - if peer_count > 0 |
67 | | - Facter.add(:gluster_peer_list) do |
| 65 | + Facter.add(:gluster_peer_list) do |
| 66 | + setcode do |
| 67 | + peer_list |
| 68 | + end |
| 69 | + end |
| 70 | + |
| 71 | + unless volume_bricks.empty? |
| 72 | + Facter.add(:gluster_volume_list) do |
68 | 73 | setcode do |
69 | | - peer_list |
| 74 | + volume_bricks.keys.join(',') |
70 | 75 | end |
71 | 76 | end |
72 | | - |
73 | | - unless volume_bricks.empty? |
74 | | - Facter.add(:gluster_volume_list) do |
| 77 | + volume_bricks.each do |vol, bricks| |
| 78 | + Facter.add("gluster_volume_#{vol}_bricks".to_sym) do |
75 | 79 | setcode do |
76 | | - volume_bricks.keys.join(',') |
| 80 | + bricks.join(',') |
77 | 81 | end |
78 | 82 | end |
79 | | - volume_bricks.each do |vol, bricks| |
80 | | - Facter.add("gluster_volume_#{vol}_bricks".to_sym) do |
| 83 | + end |
| 84 | + if volume_options |
| 85 | + volume_options.each do |vol, opts| |
| 86 | + Facter.add("gluster_volume_#{vol}_options".to_sym) do |
81 | 87 | setcode do |
82 | | - bricks.join(',') |
| 88 | + opts.join(',') |
83 | 89 | end |
84 | 90 | end |
85 | 91 | end |
86 | | - if volume_options |
87 | | - volume_options.each do |vol, opts| |
88 | | - Facter.add("gluster_volume_#{vol}_options".to_sym) do |
89 | | - setcode do |
90 | | - opts.join(',') |
91 | | - end |
92 | | - end |
93 | | - end |
94 | | - end |
95 | | - if volume_ports |
96 | | - volume_ports.each do |vol, ports| |
97 | | - Facter.add("gluster_volume_#{vol}_ports".to_sym) do |
98 | | - setcode do |
99 | | - ports.join(',') |
100 | | - end |
| 92 | + end |
| 93 | + if volume_ports |
| 94 | + volume_ports.each do |vol, ports| |
| 95 | + Facter.add("gluster_volume_#{vol}_ports".to_sym) do |
| 96 | + setcode do |
| 97 | + ports.join(',') |
101 | 98 | end |
102 | 99 | end |
103 | 100 | end |
|
0 commit comments