Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including other names in the preer probe fact #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/facter/gluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
peer_count = Regexp.last_match[1].to_i if output =~ %r{^Number of Peers: (\d+)$}
if peer_count > 0
peer_list = output.scan(%r{^Hostname: (.+)$}).flatten.join(',')
other_names = output.scan(%r{^Other names:\n((.+\n)+)}).flatten.join.scan(%r{(.+)\n?}).sort.uniq.flatten.join(',')
if other_names
peer_list += ',' + other_names
end
# note the stderr redirection here
# `gluster volume list` spits to stderr :(
output = Facter::Util::Resolution.exec("#{binary} volume list 2>&1")
Expand Down
5 changes: 3 additions & 2 deletions manifests/peer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
# peering attempt only resolves a cosmetic issue, not a functional one.
#
define gluster::peer (
$pool = 'default'
$pool = 'default',
$fqdn = $::fqdn,
) {

# we can't do much without the Gluster binary
Expand All @@ -51,7 +52,7 @@
if getvar('::gluster_binary') {
# we can't join to ourselves, so it only makes sense to operate
# on other gluster servers in the same pool
if $title != $::fqdn {
if $fqdn != $::fqdn {

# and we don't want to attach a server that is already a member
# of the current pool
Expand Down
84 changes: 35 additions & 49 deletions manifests/volume.pp
Original file line number Diff line number Diff line change
Expand Up @@ -104,60 +104,46 @@
if $minimal_requirements and $already_exists == false {
# this volume has not yet been created

# before we can create it, we need to ensure that all the
# servers hosting bricks are members of the storage pool
exec { "gluster create volume ${title}":
command => "${::gluster_binary} volume create ${title} ${args}",
}

# if we have volume options, activate them now
#
# Note: $options is an array, but create_resources requires
# a hash of hashes. We do some contortions to get the
# array into the hash of hashes that looks like:
#
# option.name:
# value: value
#
# first, get a list of unique server names hosting bricks
$brick_hosts = unique( regsubst( $bricks, '^([^:]+):(.+)$', '\1') )
# now get a list of all peers, including ourself
$pool_members = concat( split( $::gluster_peer_list, ','), [ $::fqdn ] )
# now see what the difference is
$missing_bricks = difference( $brick_hosts, $pool_members)
# Note 2: we're using the $_options variable, which contains the
# sorted list of options.
if $_options {
# first we need to prefix each array element with the volume name
# so that we match the gluster::volume::option title format of
# volume:option
$vol_opts = prefix( $_options, "${title}:" )
# now we make some YAML, and then parse that to get a Puppet hash
$yaml = join( regsubst( $vol_opts, ': ', ":\n value: ", 'G'), "\n")
$hoh = parseyaml($yaml)

if ! empty($missing_bricks) {
notice("Not creating Gluster volume ${title}: some bricks are not in the pool")
} else {
exec { "gluster create volume ${title}":
command => "${::gluster_binary} volume create ${title} ${args}",
# safety check
assert_type(Hash, $hoh)
# we need to ensure that these are applied AFTER the volume is created
# but BEFORE the volume is started
$new_volume_defaults = {
require => Exec["gluster create volume ${title}"],
before => Exec["gluster start volume ${title}"],
}

# if we have volume options, activate them now
#
# Note: $options is an array, but create_resources requires
# a hash of hashes. We do some contortions to get the
# array into the hash of hashes that looks like:
#
# option.name:
# value: value
#
# Note 2: we're using the $_options variable, which contains the
# sorted list of options.
if $_options {
# first we need to prefix each array element with the volume name
# so that we match the gluster::volume::option title format of
# volume:option
$vol_opts = prefix( $_options, "${title}:" )
# now we make some YAML, and then parse that to get a Puppet hash
$yaml = join( regsubst( $vol_opts, ': ', ":\n value: ", 'G'), "\n")
$hoh = parseyaml($yaml)

# safety check
assert_type(Hash, $hoh)
# we need to ensure that these are applied AFTER the volume is created
# but BEFORE the volume is started
$new_volume_defaults = {
require => Exec["gluster create volume ${title}"],
before => Exec["gluster start volume ${title}"],
}

create_resources(::gluster::volume::option, $hoh, $new_volume_defaults)
}
create_resources(::gluster::volume::option, $hoh, $new_volume_defaults)
}

# don't forget to start the new volume!
exec { "gluster start volume ${title}":
command => "${::gluster_binary} volume start ${title}",
require => Exec["gluster create volume ${title}"],
}
# don't forget to start the new volume!
exec { "gluster start volume ${title}":
command => "${::gluster_binary} volume start ${title}",
require => Exec["gluster create volume ${title}"],
}

} elsif $already_exists {
Expand Down