mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Created make_confiles.sh and clusterize_confiles.py
This commit is contained in:
parent
1c5c4223c7
commit
c3ce5ef4f7
72
deploy-cluster-aws/clusterize_confiles.py
Normal file
72
deploy-cluster-aws/clusterize_confiles.py
Normal file
@ -0,0 +1,72 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Given a directory full of default BigchainDB config files,
|
||||
transform them into config files for a cluster with proper
|
||||
keyrings, API endpoint values, etc.
|
||||
|
||||
Note: This script assumes that there is a file named hostlist.py
|
||||
containing public_dns_names = a list of the public DNS names of
|
||||
all the hosts in the cluster.
|
||||
|
||||
Usage:
|
||||
python clusterize_confiles.py <dir> <number_of_files>
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
|
||||
from hostlist import public_dns_names
|
||||
|
||||
|
||||
# Parse the command-line arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('dir',
|
||||
help='Directory containing the config files')
|
||||
parser.add_argument('number_of_files',
|
||||
help='Number of config files expected in dir',
|
||||
type=int)
|
||||
args = parser.parse_args()
|
||||
|
||||
conf_dir = args.dir
|
||||
numfiles_expected = int(args.number_of_files)
|
||||
|
||||
# Check if the number of files in conf_dir is what was expected
|
||||
conf_files = os.listdir(conf_dir)
|
||||
numfiles = len(conf_files)
|
||||
if numfiles != numfiles_expected:
|
||||
raise ValueError('There are {} files in {} but {} were expected'.
|
||||
format(numfiles, conf_dir, numfiles_expected))
|
||||
|
||||
# Make a list containing all the public keys from
|
||||
# all the config files
|
||||
pubkeys = []
|
||||
for filename in conf_files:
|
||||
file_path = os.path.join(conf_dir, filename)
|
||||
with open(file_path, 'r') as f:
|
||||
conf_dict = json.load(f)
|
||||
pubkey = conf_dict['keypair']['public']
|
||||
pubkeys.append(pubkey)
|
||||
|
||||
# Rewrite each config file, one at a time
|
||||
for i, filename in enumerate(conf_files):
|
||||
file_path = os.path.join(conf_dir, filename)
|
||||
with open(file_path, 'r') as f:
|
||||
conf_dict = json.load(f)
|
||||
# The keyring is the list of *all* public keys
|
||||
# minus the config file's own public key
|
||||
keyring = list(pubkeys)
|
||||
keyring.remove(conf_dict['keypair']['public'])
|
||||
conf_dict['keyring'] = keyring
|
||||
# Allow incoming server traffic from any IP address
|
||||
# to port 9984
|
||||
conf_dict['server']['bind'] = '0.0.0.0:9984'
|
||||
# Set the api_endpoint
|
||||
conf_dict['api_endpoint'] = 'http://' + public_dns_names[i] + \
|
||||
':9984/api/v1'
|
||||
# Delete the config file
|
||||
os.remove(file_path)
|
||||
# Write new config file with the same filename
|
||||
print('Rewriting {}'.format(file_path))
|
||||
with open(file_path, 'w') as f2:
|
||||
json.dump(conf_dict, f2)
|
40
deploy-cluster-aws/make_confiles.sh
Executable file
40
deploy-cluster-aws/make_confiles.sh
Executable file
@ -0,0 +1,40 @@
|
||||
#! /bin/bash
|
||||
|
||||
# The set -e option instructs bash to immediately exit
|
||||
# if any command has a non-zero exit status
|
||||
set -e
|
||||
|
||||
function printErr()
|
||||
{
|
||||
echo "usage: ./make_confiles.sh <dir> <number_of_files>"
|
||||
echo "No argument $1 supplied"
|
||||
}
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
printErr "<dir>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
printErr "<number_of_files>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CONFDIR=$1
|
||||
NUMFILES=$2
|
||||
|
||||
# If $CONFDIR exists, remove it
|
||||
if [ -d "$CONFDIR" ]; then
|
||||
rm -rf $CONFDIR
|
||||
fi
|
||||
|
||||
# Create $CONFDIR
|
||||
mkdir $CONFDIR
|
||||
|
||||
# Use the bigchaindb configure command to create
|
||||
# $NUMFILES BigchainDB config files in $CONFDIR
|
||||
for (( i=1; i<=$NUMFILES; i++ )); do
|
||||
CONPATH=$CONFDIR"/bcdb_conf"$i
|
||||
echo "Writing "$CONPATH
|
||||
bigchaindb -y -c $CONPATH configure
|
||||
done
|
Loading…
x
Reference in New Issue
Block a user