diff options
| -rw-r--r-- | lib/facter/gluster_ports.rb | 80 | ||||
| -rw-r--r-- | manifests/host.pp | 10 | ||||
| -rw-r--r-- | manifests/host/data.pp | 26 | ||||
| -rw-r--r-- | manifests/volume.pp | 46 |
4 files changed, 150 insertions, 12 deletions
diff --git a/lib/facter/gluster_ports.rb b/lib/facter/gluster_ports.rb new file mode 100644 index 0000000..1d261a2 --- /dev/null +++ b/lib/facter/gluster_ports.rb @@ -0,0 +1,80 @@ +# Simple? gluster module by James +# Copyright (C) 2010-2013+ James Shubin +# Written by James Shubin <james@shubin.ca> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +require 'facter' + +# find the module_vardir +dir = Facter.value('puppet_vardirtmp') # nil if missing +if dir.nil? # let puppet decide if present! + dir = Facter.value('puppet_vardir') + if dir.nil? + var = nil + else + var = dir.gsub(/\/$/, '')+'/'+'tmp/' # ensure trailing slash + end +else + var = dir.gsub(/\/$/, '')+'/' +end + +if var.nil? + # if we can't get a valid vardirtmp, then we can't continue + uuidfile = nil +else + module_vardir = var+'gluster/' + xmlfile = module_vardir+'xml.py' +end + +host = Facter.value('fqdn') +found = {} + +# we need the script installed first to be able to generate the port facts... +if File.exist?(xmlfile) + volumes = `/usr/sbin/gluster volume list` + if $?.exitstatus == 0 + volumes.split.each do |x| + # values come out as comma separated strings for direct usage + cmd = '/usr/sbin/gluster volume status --xml | '+xmlfile+" ports --volume '"+x+"' --host '"+host+"'" + result = `#{cmd}` + if $?.exitstatus == 0 + found[x] = result + # TODO: else, print warning + end + end + # TODO: else, print warning + end +end + +found.keys.each do |x| + Facter.add('gluster_ports_volume_'+x) do + #confine :operatingsystem => %w{CentOS, RedHat, Fedora} + setcode { + # don't reuse single variable to avoid bug #: + # http://projects.puppetlabs.com/issues/22455 + found[x] + } + end +end + +# list of generated gluster_ports_volume's +Facter.add('gluster_ports_volumes_facts') do + #confine :operatingsystem => %w{CentOS, RedHat, Fedora} + setcode { + found.keys.collect {|x| 'gluster_ports_volume_'+x }.join(',') + } +end + +# vim: ts=8 diff --git a/manifests/host.pp b/manifests/host.pp index cc34564..390b4c4 100644 --- a/manifests/host.pp +++ b/manifests/host.pp @@ -31,7 +31,15 @@ define gluster::host( Gluster::Host[$name] -> Service['glusterd'] # glusterd requires host # if we're on itself - if ( "${fqdn}" == "${name}" ) { + if "${fqdn}" == "${name}" { + + # store the ip here so that it can be accessed by bricks... + class { '::gluster::host::data': + #name => $name, + ip => "${ip}", + fqdn => "${fqdn}", + } + # don't purge the uuid file generated within file { "${vardir}/uuid/": ensure => directory, # make sure this is a directory diff --git a/manifests/host/data.pp b/manifests/host/data.pp new file mode 100644 index 0000000..ee54efb --- /dev/null +++ b/manifests/host/data.pp @@ -0,0 +1,26 @@ +# Simple? gluster module by James +# Copyright (C) 2010-2013+ James Shubin +# Written by James Shubin <james@shubin.ca> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +class gluster::host::data( + #$name, + $ip, + $fqdn +) { + # so far, this does nothing but 'store' variables +} + +# vim: ts=8 diff --git a/manifests/volume.pp b/manifests/volume.pp index b1bc712..0873ad4 100644 --- a/manifests/volume.pp +++ b/manifests/volume.pp @@ -122,17 +122,6 @@ define gluster::volume( } } - # TODO: - #if $shorewall { - # shorewall::rule { 'gluster-TODO': - # rule => " - # ACCEPT ${zone} $FW tcp 24009:${endport} - # ", - # comment => 'TODO', - # before => Service['glusterd'], - # } - #} - # run if vip not defined (by pass mode) or vip exists on this machine if ($vip == '' or $vipif != '') { if $start == true { @@ -161,6 +150,41 @@ define gluster::volume( # don't manage volume run state } } + + $shorewall = $::gluster::server::shorewall + if $shorewall { + $zone = $::gluster::server::zone # firewall zone + + $ips = $::gluster::server::ips # override host ip list + $ip = $::gluster::host::data::ip # ip of brick's host... + $source_ips = type($ips) ? { + 'array' => inline_template("<%= (ips+[]).uniq.delete_if {|x| x.empty? }.join(',') %>"), + default => ["${ip}"], + } + + $port = getvar("gluster_ports_volume_${name}") # fact ! + + # NOTE: we need to add the $fqdn so that exported resources + # don't conflict... I'm not sure they should anyways though + @@shorewall::rule { "gluster-volume-${name}-${fqdn}": + action => 'ACCEPT', + source => "${zone}", # override this on collect... + source_ips => $source_ips, + dest => '$FW', + proto => 'tcp', + port => "${port}", # comma separated string or list + #comment => "${fqdn}", + comment => 'Allow incoming tcp port from glusterfsds.', + tag => 'gluster_firewall_volume', + ensure => present, + } + # we probably shouldn't collect the above rule from our self... + #Shorewall::Rule <<| tag == 'gluster_firewall_volume' and comment != "${fqdn}" |>> { + Shorewall::Rule <<| tag == 'gluster_firewall_volume' |>> { + source => "${zone}", # use our source zone + before => Service['glusterd'], + } + } } # vim: ts=8 |
