Skip to content

Commit c215cec

Browse files
committed
Create script
0 parents  commit c215cec

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

gstatus_discovery.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/python3
2+
import json
3+
import subprocess
4+
import sys
5+
6+
gluster_volume_names = []
7+
gstatus_output = subprocess.check_output('python /root/gstatus/gstatus.py -a -o json ', shell=True).decode()
8+
date, time, json_part = gstatus_output.split(maxsplit=2)
9+
gluster_info = json.loads(json_part)
10+
volume_list = gluster_info["volume_summary"]
11+
12+
nargs = len(sys.argv)
13+
14+
if nargs == 1:
15+
for volume in volume_list:
16+
gluster_volume_names.append({"{#VOLUME_NAME}": volume["volume_name"]})
17+
print(json.dumps({'data': gluster_volume_names}))
18+
19+
elif nargs == 2:
20+
print(gluster_info[sys.argv[1]])
21+
elif nargs == 3:
22+
for volume in volume_list:
23+
if volume.get('volume_name') and sys.argv[2] == volume["volume_name"]:
24+
print(volume[sys.argv[1]])
25+
break
26+
else:
27+
if sys.argv[1] == "state":
28+
print('down')
29+
else:
30+
print()
31+
32+
else:
33+
print('Wrong arguments')
34+

0 commit comments

Comments
 (0)