Created
May 3, 2019 12:19
-
-
Save alanbchristie/817d04ebd3dafbf11c40ceaa38ceb8d6 to your computer and use it in GitHub Desktop.
Generates volume discrepancies between Heketi and Gluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Usage: gluster-cmp.py <heketi-txt> <gluster-txt> | |
# | |
# Given two text files, the output of: - | |
# | |
# - heketi-cli volume list | |
# - gluster volume status all | |
# | |
# ...this utility lists volumes that gluster knows about that | |
# heketi does not and volumes heketi knows about that gluster does not. | |
# | |
# Alan Christie | |
# May 2019 | |
import os | |
import re | |
import sys | |
heketi_vol_re = re.compile(r'.*Name:(\S+)') | |
gluster_vol_re = re.compile(r'^Status of volume: (\S+)') | |
if len(sys.argv) != 3: | |
print('Usage: gluster-cmp.py <heketi-txt-file> <gluster-txt-file>') | |
sys.exit(1) | |
# Collect Heketi Volumes | |
heketi_volumes = [] | |
with open(os.path.expanduser(sys.argv[1])) as input_file: | |
for line in input_file: | |
match_obj = heketi_vol_re.match(line) | |
if match_obj: | |
heketi_volumes.append(match_obj.group(1)) | |
# Collect Gluster volumes | |
gluster_volumes = [] | |
with open(os.path.expanduser(sys.argv[2])) as input_file: | |
for line in input_file: | |
match_obj = gluster_vol_re.match(line) | |
if match_obj: | |
gluster_volumes.append(match_obj.group(1)) | |
# Print discrepancies... | |
print('Volumes known to Gluster but unknown to Heketi') | |
print('----------------------------------------------') | |
num_unkown = 0 | |
for volume in gluster_volumes: | |
if volume not in heketi_volumes: | |
print(volume) | |
num_unkown += 1 | |
print('({}/{})'.format(num_unkown, len(gluster_volumes))) | |
print('') | |
print('Volumes known to Heketi but unknown to Gluster') | |
print('----------------------------------------------') | |
num_unkown = 0 | |
for volume in heketi_volumes: | |
if volume not in gluster_volumes: | |
print(volume) | |
num_unkown += 1 | |
print('({}/{})'.format(num_unkown, len(heketi_volumes))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment