diff options
author | James Shubin <james@shubin.ca> | 2013-09-07 16:20:29 -0400 |
---|---|---|
committer | James Shubin <james@shubin.ca> | 2013-09-07 16:20:29 -0400 |
commit | 4345cf9e625259585f7f8541e08c0e79a914e78c (patch) | |
tree | 83dd170ca9286fe32943f1ea41cecf893531ccc1 /files | |
parent | 64aaaf3b0160ac50d22bbdd73725de53bab668a8 (diff) | |
download | puppet-gluster-4345cf9e625259585f7f8541e08c0e79a914e78c.tar.gz puppet-gluster-4345cf9e625259585f7f8541e08c0e79a914e78c.tar.xz puppet-gluster-4345cf9e625259585f7f8541e08c0e79a914e78c.zip |
Add proper ping/status checks before volume creation.
This adds proper (optional) ping checks with fping and gluster peer
status checks to ensure the peer are available before a volume create
command. This required rewriting of the xml.py hack which helps puppet
interface with the xml formatted gluster cli output. In addition,
downstream commands such as volume::property gained checks to ensure the
volume was present beforehand. While it is not obvious, it should be
noted that because of the distributed nature of glusterfs, more than one
puppet run will be required for complete deployment. With these patches,
individual runs shouldn't ever end in temporary error as they used too.
Diffstat (limited to 'files')
-rw-r--r-- | files/xml.py | 68 |
1 files changed, 56 insertions, 12 deletions
diff --git a/files/xml.py b/files/xml.py index abd4212..1e9a724 100644 --- a/files/xml.py +++ b/files/xml.py @@ -1,6 +1,5 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# Copyright (C) 2012+ Jordi GutiƩrrez Hermoso <jordigh@octave.org> # Copyright (C) 2012-2013+ James Shubin # Written by James Shubin <james@shubin.ca> # @@ -17,24 +16,69 @@ # 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/>. -# thanks to Jordi for fighting with the xml for me so that I didn't have to :) +# EXAMPLE: +# $ gluster peer status --xml | ./xml.py --connected <PEER1> <PEER2> <PEERn> +# <BOOL> # EXAMPLE: -# $ gluster volume --xml info <VOLNAME> | ./xml.py <KEY> +# $ gluster volume --xml info <VOLNAME> | ./xml.py --property <KEY> # <VALUE> import sys import lxml.etree as etree -if len(sys.argv) != 2: - sys.exit(1) +argv = sys.argv +argv.pop(0) # get rid of $0 + +if len(argv) < 1: + sys.exit(3) + +mode = argv.pop(0) +tree = etree.parse(sys.stdin) +root = tree.getroot() + +# are all the hostnames in argv connected ? +if mode == '--connected': + store = {} + peers = [x for x in argv if x != ''] + + for i in root.findall('.//peerStatus'): + p = i.find('peer') + h = p.find('hostname').text + c = (str(p.find('connected').text) == '1') # connected + store[h] = c # save for later... + + # if no peers specified, assume we should check all... + if len(peers) == 0: + peers = store.keys() -t = etree.parse(sys.stdin) -r = t.getroot() -v = [x.find('value').text for x in r.findall('.//option') if x.find('name').text == str(sys.argv[1])] -if len(v) == 1: - print v[0] + for i in peers: + if i in store.keys(): + if not store[i]: + # someone is unconnected + sys.exit(1) + else: + # we're looking for a peer that isn't peered yet + sys.exit(2) + + # must be good! sys.exit(0) -else: # more than one value found - sys.exit(1) + +elif mode == '--property': + if len(argv) != 1: + sys.exit(3) + + store = [] + for i in root.findall('.//option'): + if i.find('name').text == str(argv[0]): + store.append(i.find('value').text) + + if len(store) == 1: + print(store[0]) + sys.exit(0) + else: # more than one value found + sys.exit(1) + +# else: +sys.exit(3) |