Skip to content

Commit 0c68d99

Browse files
committed
Fix logic for single node gluster servers
1 parent 0a650c7 commit 0c68d99

File tree

2 files changed

+42
-51
lines changed

2 files changed

+42
-51
lines changed

lib/facter/gluster.rb

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@
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-
# 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
5454
end
5555
end
5656
end
@@ -62,42 +62,39 @@
6262
end
6363
end
6464

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
6873
setcode do
69-
peer_list
74+
volume_bricks.keys.join(',')
7075
end
7176
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
7579
setcode do
76-
volume_bricks.keys.join(',')
80+
bricks.join(',')
7781
end
7882
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
8187
setcode do
82-
bricks.join(',')
88+
opts.join(',')
8389
end
8490
end
8591
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(',')
10198
end
10299
end
103100
end

manifests/volume.pp

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

105-
if getvar('::gluster_peer_list') {
106-
$minimal_requirements = true
107-
} else {
108-
$minimal_requirements = false
109-
}
110-
111105
if getvar('::gluster_volume_list') and member( split( $::gluster_volume_list, ',' ), $title ) {
112106
$already_exists = true
113107
} else {
114108
$already_exists = false
115109
}
116110

117-
if $minimal_requirements and $already_exists == false {
111+
if $already_exists == false {
118112
# this volume has not yet been created
119113

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

0 commit comments

Comments
 (0)