Created
March 27, 2017 13:23
-
-
Save umiyosh/6aadd8452124649087797a64e3ce022d to your computer and use it in GitHub Desktop.
pretty_cluster_node.py
This file contains 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
import fileinput | |
import re | |
masters_info = [] | |
slaves_info = [] | |
for line in fileinput.input(): | |
info = {} | |
cluster_node = re.split(r' +', line) | |
if 'master' in cluster_node[2]: | |
info['nodeid'] = cluster_node[0] | |
info['addr'] = cluster_node[1] | |
masters_info.append(info) | |
else: | |
info['nodeid'] = cluster_node[0] | |
info['addr'] = cluster_node[1] | |
info['master_nodeid'] = cluster_node[3] | |
slaves_info.append(info) | |
for master_info in masters_info: | |
print "master", master_info['addr'], master_info['nodeid'] | |
for slave_info in slaves_info: | |
if slave_info['master_nodeid'] == master_info['nodeid']: | |
print " slave", slave_info['addr'], slave_info['nodeid'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment