mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Updated the rest of glusterfs.py for python2.6 compatibility
This commit is contained in:
parent
971ce58cd6
commit
522b4990ef
1 changed files with 18 additions and 11 deletions
|
@ -77,6 +77,17 @@ def _etree_to_dict(t):
|
|||
return d
|
||||
|
||||
|
||||
def _iter(root, term):
|
||||
'''
|
||||
Checks for python2.6 or python2.7
|
||||
'''
|
||||
if sys.version_info < (2, 7):
|
||||
return root.getiterator(term)
|
||||
else:
|
||||
return root.iter(term)
|
||||
|
||||
|
||||
|
||||
def list_peers():
|
||||
'''
|
||||
Return a list of gluster peers
|
||||
|
@ -107,11 +118,7 @@ def list_peers():
|
|||
|
||||
'''
|
||||
root = _gluster_xml('peer status')
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
result = [x.find('hostname').text for x in root.getiterator('peer')]
|
||||
else:
|
||||
result = [x.find('hostname').text for x in root.iter('peer')]
|
||||
result = [x.find('hostname').text for x in _iter(root, 'peer')]
|
||||
if len(result) == 0:
|
||||
return None
|
||||
else:
|
||||
|
@ -257,7 +264,7 @@ def list_volumes():
|
|||
|
||||
get_volume_list = 'gluster --xml volume list'
|
||||
root = _gluster_xml('volume list')
|
||||
results = [x.text for x in root.iter('volume')]
|
||||
results = [x.text for x in _iter(root, 'volume')]
|
||||
return results
|
||||
|
||||
|
||||
|
@ -287,13 +294,13 @@ def status(name):
|
|||
|
||||
# Build a hash to map hostname to peerid
|
||||
hostref = {}
|
||||
for node in root.iter('node'):
|
||||
for node in _iter(root, 'node'):
|
||||
peerid = node.find('peerid').text
|
||||
hostname = node.find('hostname').text
|
||||
if hostname not in ('NFS Server', 'Self-heal Daemon'):
|
||||
hostref[peerid] = hostname
|
||||
|
||||
for node in root.iter('node'):
|
||||
for node in _iter(root, 'node'):
|
||||
hostname = node.find('hostname').text
|
||||
if hostname not in ('NFS Server', 'Self-heal Daemon'):
|
||||
path = node.find('path').text
|
||||
|
@ -330,12 +337,12 @@ def info(name):
|
|||
cmd = 'volume info {0}'.format(name)
|
||||
root = _gluster_xml(cmd)
|
||||
|
||||
volume = [x for x in root.iter('volume')][0]
|
||||
volume = [x for x in _iter(root, 'volume')][0]
|
||||
|
||||
ret = {name: _etree_to_dict(volume)}
|
||||
|
||||
bricks = {}
|
||||
for i, brick in enumerate(volume.iter('brick'), start=1):
|
||||
for i, brick in enumerate(_iter(volume, 'brick'), start=1):
|
||||
brickkey = 'brick{0}'.format(i)
|
||||
bricks[brickkey] = {'path': brick.text}
|
||||
for child in brick.getchildren():
|
||||
|
@ -346,7 +353,7 @@ def info(name):
|
|||
ret[name]['bricks'] = bricks
|
||||
|
||||
options = {}
|
||||
for option in volume.iter('option'):
|
||||
for option in _iter(volume, 'option'):
|
||||
options[option.find('name').text] = option.find('value').text
|
||||
ret[name]['options'] = options
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue