<commit_before># -*- coding: utf-8 -*-
#!/usr/bin/python
##-------------------------------------------------------------------
## @copyright 2016 <EMAIL>
## Licensed under MIT
## https://raw.githubusercontent.com/DennyZhang/devops_public/master/LICENSE
##
## File : ufw_add_node_to_cluster.py
## Author : Denny <<EMAIL>>
## Description :
## Here we assume firewall should allow all traffic within the Intranet.
##      Running a cluster of nodes in certain public cloud,
##      like Linode, we don't have private subnet.
##      Thus to add one node, we need:
##          1. Properly configure firewall in the new node
##          2. Change firewall rules in existing node, to allow incoming traffic
## --
## Created : <2016-12-13>
## Updated: Time-stamp: <2016-12-13 22:50:24>
##-------------------------------------------------------------------
server_ip_new_node = ""
server_list_existing = ""

################################################################################
## TODO: remove to common library
def remove_comment_in_str(string):
    l = []
    for line in string.split("\n"):
        line = line.strip()
        if line.startswith("#") or line == "":
            continue
        l.append(line)
    return "\n".join(l)

def test_remove_comment_in_str():
    string= '''## server_ip:ssh_port
## couchbase
192.168.3.11:2702
172.16.58.3:2702
172.16.31.10:2702
172.16.58.3:2702

## Elasticsearch
172.16.58.3:2702
172.16.31.10:2702
172.16.31.10:2702
172.16.58.3:2702
172.16.58.3:2702
172.16.58.3:2702
172.16.31.10:2702
192.168.3.11:2702
192.168.127.12:2702

## APP
172.16.31.10:2702
172.16.31.10:2702
192.168.127.12:2702
172.16.31.10:2702

## LoadBlanacer
172.16.31.10:2702
172.16.17.32:2702

## Nagios
172.16.17.32:2702
'''
    print remove_comment_in_str(string)
################################################################################

def test():
 print "hello, world"

if __name__ == '__main__':
 test()
## File : ufw_add_node_to_cluster.py ends
<commit_msg>parameter check<commit_after># -*- coding: utf-8 -*-
#!/usr/bin/python
##-------------------------------------------------------------------
## @copyright 2016 DennyZhang.com
## Licensed under MIT
## https://raw.githubusercontent.com/DennyZhang/devops_public/master/LICENSE
##
## File : ufw_add_node_to_cluster.py
## Author : Denny <<EMAIL>>
## Description :
## Here we assume firewall should allow all traffic within the Intranet.
##      Running a cluster of nodes in certain public cloud,
##      like Linode, we don't have private subnet.
##      Thus to add one node, we need:
##          1. Properly configure firewall in the new node
##          2. Change firewall rules in existing node, to allow incoming traffic
## --
## Created : <2016-12-13>
## Updated: Time-stamp: <2016-12-13 22:56:42>
##-------------------------------------------------------------------
import os, sys

################################################################################
## TODO: remove to common library
def check_variable_is_set(val, msg):
    if val is None:
        sys.exit("%s" % (msg))

def remove_comment_in_str(string):
    l = []
    for line in string.split("\n"):
        line = line.strip()
        if line.startswith("#") or line == "":
            continue
        l.append(line)
    return "\n".join(l)

# TODO: better way to manage unit test code
def test_remove_comment_in_str():
    string= '''## server_ip:ssh_port
## couchbase
172.16.58.3:2702

## Elasticsearch
172.16.58.3:2702
172.16.31.10:2702
'''
    print remove_comment_in_str(string)

################################################################################
# How To Test:
# 		export server_ip="127.0.0.1"
# 		export server_list="127.0.0.1"
# 		python ./ufw_add_node_to_cluster.py 
if __name__ == '__main__':
    server_ip_new_node = os.environ.get('server_ip')
    check_variable_is_set(server_ip_new_node, "ERROR: server_ip is not configured")

    server_list_existing = os.environ.get('server_list')
    check_variable_is_set(server_list_existing, "ERROR: server_list is not configured")

    server_list_existing = remove_comment_in_str(server_list_existing)
## File : ufw_add_node_to_cluster.py ends

{'fraction_non_alphanumeric': 0.26323353293413176, 'fraction_numerical': 0.08742514970059881, 'mean_word_length': 2.935909519321395, 'pattern_counts': {'":': 2, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 25, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1785037', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1313, 'n_words': 306}