|
1 | | -peer_count = 0 |
2 | 1 | peer_list = '' |
3 | 2 | volume_bricks = {} |
4 | 3 | volume_options = {} |
|
25 | 24 | binary |
26 | 25 | end |
27 | 26 | end |
28 | | - output = Facter::Util::Resolution.exec("#{binary} peer status") |
29 | | - peer_count = Regexp.last_match[1].to_i if output =~ %r{^Number of Peers: (\d+)$} |
| 27 | + require 'rexml/document' |
| 28 | + |
| 29 | + peer_status = REXML::Document.new(Facter::Util::Resolution.exec("#{binary} peer status --xml")) |
| 30 | + peers = REXML::XPath.match(peer_status, '/cliOutput/peerStatus/peer/hostname/text()') |
| 31 | + peer_count = peers.size |
30 | 32 | if peer_count > 0 |
31 | | - peer_list = output.scan(%r{^Hostname: (.+)$}).flatten.join(',') |
32 | | - # note the stderr redirection here |
33 | | - # `gluster volume list` spits to stderr :( |
34 | | - output = Facter::Util::Resolution.exec("#{binary} volume list 2>&1") |
35 | | - if output != 'No volumes present in cluster' |
36 | | - output.split.each do |vol| |
37 | | - info = Facter::Util::Resolution.exec("#{binary} volume info #{vol}") |
38 | | - # rubocop:disable Metrics/BlockNesting |
39 | | - vol_status = Regexp.last_match[1] if info =~ %r{^Status: (.+)$} |
40 | | - bricks = info.scan(%r{^Brick[^:]+: (.+)$}).flatten |
41 | | - volume_bricks[vol] = bricks |
42 | | - options = info.scan(%r{^(\w+\.[^:]+: .+)$}).flatten |
43 | | - volume_options[vol] = options if options |
44 | | - next unless vol_status == 'Started' |
45 | | - status = Facter::Util::Resolution.exec("#{binary} volume status #{vol} 2>/dev/null") |
46 | | - if status =~ %r{^Brick} |
47 | | - volume_ports[vol] = status.scan(%r{^Brick [^\t]+\t+(\d+)}).flatten.uniq.sort |
48 | | - end |
49 | | - end |
| 33 | + peer_list = peers.join(',') |
| 34 | + volumes = REXML::Document.new(Facter::Util::Resolution.exec("#{binary} volume info --xml")) |
| 35 | + REXML::XPath.match(volumes, '/cliOutput/volInfo/volumes/volume').each do |vol| |
| 36 | + vol_name = vol.elements['name'].text |
| 37 | + vol_status = vol.elements['statusStr'].text |
| 38 | + bricks = REXML::XPath.match(vol, 'bricks/brick/name/text()') |
| 39 | + volume_bricks[vol_name] = bricks |
| 40 | + options = REXML::XPath.match(vol, 'options/option').map { |option| "#{option.elements['name'].text}: #{option.elements['value'].text}" } |
| 41 | + volume_options[vol_name] = options if options |
| 42 | + next unless vol_status == 'Started' |
| 43 | + status = REXML::Document.new(Facter::Util::Resolution.exec("#{binary} volume status #{vol_name} --xml")) |
| 44 | + volume_ports[vol_name] = REXML::XPath.match(status, "/cliOutput/volStatus/volumes/volume/node[starts-with(hostname/text(), '#{Facter.value('hostname')}')]/port/text()") |
50 | 45 | end |
51 | 46 | end |
52 | 47 |
|
|
78 | 73 | end |
79 | 74 | end |
80 | 75 | end |
| 76 | + # rubocop:disable Metrics/BlockNesting |
81 | 77 | if volume_options |
82 | 78 | volume_options.each do |vol, opts| |
83 | 79 | Facter.add("gluster_volume_#{vol}_options".to_sym) do |
|
0 commit comments