2017-11-02 15:55:03 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
2017-11-05 23:59:42 +00:00
|
|
|
import json
|
2017-11-02 15:55:03 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def main(states, nodeid):
|
|
|
|
with open(states) as handle:
|
|
|
|
data = json.load(handle)
|
|
|
|
|
|
|
|
if nodeid in data['nodes']:
|
|
|
|
del data['nodes'][nodeid]
|
|
|
|
print("node {} removed".format(nodeid))
|
|
|
|
else:
|
|
|
|
print('node not in state file', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
with open(states, 'w') as handle:
|
|
|
|
json.dump(data, handle)
|
|
|
|
|
2017-11-05 23:59:42 +00:00
|
|
|
|
2017-11-02 15:55:03 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
parser.add_argument('-s', '--states', action='store', required=True,
|
|
|
|
help='path to the states json file')
|
|
|
|
parser.add_argument('-n', '--nodeid', action='store', required=True,
|
|
|
|
help='nodeid of the node to remove')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
main(args.states, args.nodeid)
|