summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJames Shubin <james@shubin.ca>2013-09-18 05:52:23 -0400
committerJames Shubin <james@shubin.ca>2013-09-18 05:52:23 -0400
commit4dbba38fc44e8d7226fdecec12b1237fc24d026d (patch)
tree215fa7e931f7c9b71bbdd2d7fade629dea5546d0 /lib
parent269be1cc13c43df0e8e3a3c0babbe494ed727e60 (diff)
downloadpuppet-gluster-4dbba38fc44e8d7226fdecec12b1237fc24d026d.tar.gz
puppet-gluster-4dbba38fc44e8d7226fdecec12b1237fc24d026d.tar.xz
puppet-gluster-4dbba38fc44e8d7226fdecec12b1237fc24d026d.zip
Finally, Fancy Firewalling...
This adds experimental support for automatic firewalling. Initially, we don't know the other hosts (until they are exported and collected) so we start with an blank firewall to all hosts. After hosts start checking in, we start only allowing specify host ips. For the volume building, we can't predict (AFAICT) which ports will be used until after the volume is started, so we initially allow all ports inbound, until the fact gets the data from the started volume and uses those specific ports. This naturally takes multiple puppet runs to complete.
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/gluster_ports.rb80
1 files changed, 80 insertions, 0 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