1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixes for python 2.4 support, better collection of riak version.

This commit is contained in:
James Martin 2013-09-05 16:40:36 -04:00
parent 441062f061
commit 8c1ed028d3

View file

@ -87,9 +87,14 @@ EXAMPLES = '''
''' '''
import urllib2 import urllib2
import json
import time import time
import socket import socket
import sys
try:
import json
except ImportError:
import simplejson as json
def ring_check(module, riak_admin_bin): def ring_check(module, riak_admin_bin):
cmd = '%s ringready 2> /dev/null' % riak_admin_bin cmd = '%s ringready 2> /dev/null' % riak_admin_bin
@ -129,19 +134,15 @@ def main():
riak_bin = module.get_bin_path('riak') riak_bin = module.get_bin_path('riak')
riak_admin_bin = module.get_bin_path('riak-admin') riak_admin_bin = module.get_bin_path('riak-admin')
cmd = "%s version 2> /dev/null |grep ^riak|cut -f2 -d' '|tr -d '('" % riak_bin
rc, out, err = module.run_command(cmd)
if rc == 0:
version = out.strip()
else:
module.fail_json(msg='Could not determine Riak version')
# here we attempt to get stats from the http stats interface for 120 seconds.
timeout = time.time() + 120 timeout = time.time() + 120
while True: while True:
if time.time() > timeout: if time.time() > timeout:
module.fail_json(msg='Timeout, could not fetch Riak stats.') module.fail_json(msg='Timeout, could not fetch Riak stats.')
try: try:
if sys.version_info<(2,6,0):
stats_raw = urllib2.urlopen(
'http://%s/stats' % (http_conn), None).read()
else:
stats_raw = urllib2.urlopen( stats_raw = urllib2.urlopen(
'http://%s/stats' % (http_conn), None, 5).read() 'http://%s/stats' % (http_conn), None, 5).read()
break break
@ -163,7 +164,7 @@ def main():
node_name = stats['nodename'] node_name = stats['nodename']
nodes = stats['ring_members'] nodes = stats['ring_members']
ring_size = stats['ring_creation_size'] ring_size = stats['ring_creation_size']
version = stats['riak_core_version']
result = dict(node_name=node_name, result = dict(node_name=node_name,
nodes=nodes, nodes=nodes,