Skip to content

Commit 3b7a822

Browse files
committed
Fix logic for single node gluster servers
1 parent 58c61fa commit 3b7a822

File tree

2 files changed

+41
-50
lines changed

2 files changed

+41
-50
lines changed

lib/facter/gluster.rb

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@
3333
if other_names
3434
peer_list += ',' + other_names
3535
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-
info = Facter::Util::Resolution.exec("#{binary} volume info #{vol}")
42-
# rubocop:disable Metrics/BlockNesting
43-
vol_status = Regexp.last_match[1] if info =~ %r{^Status: (.+)$}
44-
bricks = info.scan(%r{^Brick[^:]+: (.+)$}).flatten
45-
volume_bricks[vol] = bricks
46-
options = info.scan(%r{^(\w+\.[^:]+: .+)$}).flatten
47-
volume_options[vol] = options if options
48-
next unless vol_status == 'Started'
49-
status = Facter::Util::Resolution.exec("#{binary} volume status #{vol} 2>/dev/null")
50-
if status =~ %r{^Brick}
51-
volume_ports[vol] = status.scan(%r{^Brick [^\t]+\t+(\d+)}).flatten.uniq.sort
52-
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+
info = Facter::Util::Resolution.exec("#{binary} volume info #{vol}")
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
5353
end
5454
end
5555
end
@@ -61,42 +61,39 @@
6161
end
6262
end
6363

64-
# these facts doesn't make sense without peers
65-
if peer_count > 0
66-
Facter.add(:gluster_peer_list) do
64+
Facter.add(:gluster_peer_list) do
65+
setcode do
66+
peer_list
67+
end
68+
end
69+
70+
unless volume_bricks.empty?
71+
Facter.add(:gluster_volume_list) do
6772
setcode do
68-
peer_list
73+
volume_bricks.keys.join(',')
6974
end
7075
end
71-
72-
unless volume_bricks.empty?
73-
Facter.add(:gluster_volume_list) do
76+
volume_bricks.each do |vol, bricks|
77+
Facter.add("gluster_volume_#{vol}_bricks".to_sym) do
7478
setcode do
75-
volume_bricks.keys.join(',')
79+
bricks.join(',')
7680
end
7781
end
78-
volume_bricks.each do |vol, bricks|
79-
Facter.add("gluster_volume_#{vol}_bricks".to_sym) do
82+
end
83+
if volume_options
84+
volume_options.each do |vol, opts|
85+
Facter.add("gluster_volume_#{vol}_options".to_sym) do
8086
setcode do
81-
bricks.join(',')
87+
opts.join(',')
8288
end
8389
end
8490
end
85-
if volume_options
86-
volume_options.each do |vol, opts|
87-
Facter.add("gluster_volume_#{vol}_options".to_sym) do
88-
setcode do
89-
opts.join(',')
90-
end
91-
end
92-
end
93-
end
94-
if volume_ports
95-
volume_ports.each do |vol, ports|
96-
Facter.add("gluster_volume_#{vol}_ports".to_sym) do
97-
setcode do
98-
ports.join(',')
99-
end
91+
end
92+
if volume_ports
93+
volume_ports.each do |vol, ports|
94+
Facter.add("gluster_volume_#{vol}_ports".to_sym) do
95+
setcode do
96+
ports.join(',')
10097
end
10198
end
10299
end

manifests/volume.pp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,13 @@
8989
if getvar('::gluster_binary'){
9090
# we need the Gluster binary to do anything!
9191

92-
if getvar('::gluster_peer_list') {
93-
$minimal_requirements = true
94-
} else {
95-
$minimal_requirements = false
96-
}
97-
9892
if getvar('::gluster_volume_list') and member( split( $::gluster_volume_list, ',' ), $title ) {
9993
$already_exists = true
10094
} else {
10195
$already_exists = false
10296
}
10397

104-
if $minimal_requirements and $already_exists == false {
98+
if $already_exists == false {
10599
# this volume has not yet been created
106100

107101
exec { "gluster create volume ${title}":

0 commit comments

Comments
 (0)