<commit_before>#!/bin/bash


iVmName="vInstaller"
vVmName="voltha_voltha"
baseImage="Ubuntu1604LTS"
iVmNetwork="vagrant-libvirt"
installerArchive="installer.tar.bz2"
installerDirectory="volthaInstaller"
installerPart="installer.part"
shutdownTimeout=5
ipTimeout=10

# Command line argument variables
testMode="no"
rebuildVoltha="no"



lBlue='\033[1;34m'
green='\033[0;32m'
orange='\033[0;33m'
NC='\033[0m'
red='\033[0;31m'
yellow='\033[1;33m'
dGrey='\033[1;30m'
lGrey='\033[1;37m'
lCyan='\033[1;36m'

uId=`id -u`
wd=`pwd`

parse_args()
{
	for i in $@
	do
		case "$i" in
			"test" )
				testMode="yes"
				echo -e "${lBlue}Test mode is ${green}enabled${NC}"
				;;
			"rebuild" )
				rebuildVoltha="yes"
				echo -e "${lBlue}Voltha rebuild is ${green}enabled${NC}"
				;;
		esac
	done
}


######################################
# MAIN MAIN MAIN MAIN MAIN MAIN MAIN #
######################################
parse_args $@
# Validate that vagrant is installed.
echo -e "${lBlue}Ensure that ${lCyan}vagrant${lBlue} is installed${NC}"
vInst=`which vagrant`

if [ -z "$vInst" ]; then
	wget https://releases.hashicorp.com/vagrant/1.9.5/vagrant_1.9.5_x86_64.deb
	sudo dpkg -i vagrant_1.8.5_x86_64.deb
	rm vagrant_1.8.5_x86_64.deb
fi
unset vInst

# Validate that ansible is installed
echo -e "${lBlue}Ensure that ${lCyan}ansible${lBlue} is installed${NC}"
aInst=`which ansible`

if [ -z "$aInst" ]; then
	sudo apt-get install -y software-properties-common
	sudo apt-add-repository ppa:ansible/ansible
	sudo apt-get update
	sudo apt-get install -y ansible
fi
unset vInst

# Verify if this is intended to be a test environment, if so
# configure the 3 VMs which will be started later to emulate
# the production installation cluster.
if [ "$testMode" == "yes" ]; then
	echo -e "${lBlue}Test mode ${green}enabled${lBlue}, configure the ${lCyan}ha-serv${lBlue} VMs${NC}"
	# Update the vagrant settings file
	sed -i -e '/server_name/s/.*/server_name: "ha-serv'${uId}'-"/' settings.vagrant.yaml
	sed -i -e '/docker_push_registry/s/.*/docker_push_registry: "vinstall'${uId}':5000"/' ansible/group_vars/all
	sed -i -e "/vinstall/s/vinstall/vinstall${uId}/" ../ansible/roles/docker/templates/daemon.json

	# Set the insecure registry configuration based on the installer hostname
	echo -e "${lBlue}Set up the insecure registry config for hostname ${lCyan}vinstall${uId}${NC}"
	echo '{' > ansible/roles/voltha/templates/daemon.json
	echo '"insecure-registries" : ["vinstall'${uId}':5000"]' >> ansible/roles/voltha/templates/daemon.json
	echo '}' >> ansible/roles/voltha/templates/daemon.json

	# Check to make sure that the vagrant-libvirt network is both defined and started
	echo -e "${lBlue}Verify tha the ${lCyan}vagrant-libvirt${lBlue} network is defined and started${NC}"
	virsh net-list | grep "vagrant-libvirt" > /dev/null
	rtrn=$?
	if [ $rtrn -eq 1 ]; then
		# The network isn't running, check if it's defined
		virsh net-list --all | grep "vagrant-libvirt" > /dev/null
		rtrn=$?
		if [ $rtrn -eq 1 ]; then
			# Not defined either
			echo -e "${lBlue}Defining the ${lCyan}vagrant-libvirt${lBlue} network${NC}"
			virsh net-define vagrant-libvirt.xml
			echo -e "${lBlue}Starting the ${lCyan}vagrant-libvirt${lBlue} network${NC}"
			virsh net-start vagrant-libvirt
		else
			# Defined but not started
			echo -e "${lBlue}Starting the ${lCyan}vagrant-libvirt${lBlue} network${NC}"
			virsh net-start vagrant-libvirt
		fi
	else
		echo -e "${lBlue}The ${lCyan}vagrant-libvirt${lBlue} network is ${green} running${NC}"
	fi

	# Change the installer name
	iVmName="vInstaller${uId}"
else
	rm -fr .test
	# Clean out the install config file keeping only the commented lines
        # which serve as documentation.
	sed -i -e '/^#/!d' install.cfg
	# Set the insecure registry configuration based on the installer hostname
	echo -e "${lBlue}Set up the inescure registry config for hostname ${lCyan}vinstall${NC}"
	sed -i -e '/docker_push_registry/s/.*/docker_push_registry: "vinstall:5000"/' ansible/group_vars/all
	echo '{' > ansible/roles/voltha/templates/daemon.json
	echo '"insecure-registries" : ["vinstall:5000"]' >> ansible/roles/voltha/templates/daemon.json
	echo '}' >> ansible/roles/voltha/templates/daemon.json
fi


# Shut down the domain in case it's running.
echo -e "${lBlue}Shut down the ${lCyan}$iVmName${lBlue} VM if running${NC}"
ctr=0<commit_msg>Changed the logic such that the vagrant-libvirt network is created regardless of whether test mode is active or not. This network is required in all cases because the voltha vm is created using Vagrant and the installer needs to be in the same network.<commit_after>#!/bin/bash


iVmName="vInstaller"
vVmName="voltha_voltha"
baseImage="Ubuntu1604LTS"
iVmNetwork="vagrant-libvirt"
installerArchive="installer.tar.bz2"
installerDirectory="volthaInstaller"
installerPart="installer.part"
shutdownTimeout=5
ipTimeout=10

# Command line argument variables
testMode="no"
rebuildVoltha="no"



lBlue='\033[1;34m'
green='\033[0;32m'
orange='\033[0;33m'
NC='\033[0m'
red='\033[0;31m'
yellow='\033[1;33m'
dGrey='\033[1;30m'
lGrey='\033[1;37m'
lCyan='\033[1;36m'

uId=`id -u`
wd=`pwd`

parse_args()
{
	for i in $@
	do
		case "$i" in
			"test" )
				testMode="yes"
				echo -e "${lBlue}Test mode is ${green}enabled${NC}"
				;;
			"rebuild" )
				rebuildVoltha="yes"
				echo -e "${lBlue}Voltha rebuild is ${green}enabled${NC}"
				;;
		esac
	done
}


######################################
# MAIN MAIN MAIN MAIN MAIN MAIN MAIN #
######################################
parse_args $@
# Validate that vagrant is installed.
echo -e "${lBlue}Ensure that ${lCyan}vagrant${lBlue} is installed${NC}"
vInst=`which vagrant`

if [ -z "$vInst" ]; then
	wget https://releases.hashicorp.com/vagrant/1.9.5/vagrant_1.9.5_x86_64.deb
	sudo dpkg -i vagrant_1.8.5_x86_64.deb
	rm vagrant_1.8.5_x86_64.deb
fi
unset vInst

# Validate that ansible is installed
echo -e "${lBlue}Ensure that ${lCyan}ansible${lBlue} is installed${NC}"
aInst=`which ansible`

if [ -z "$aInst" ]; then
	sudo apt-get install -y software-properties-common
	sudo apt-add-repository ppa:ansible/ansible
	sudo apt-get update
	sudo apt-get install -y ansible
fi
unset vInst

# Verify if this is intended to be a test environment, if so
# configure the 3 VMs which will be started later to emulate
# the production installation cluster.
if [ "$testMode" == "yes" ]; then
	echo -e "${lBlue}Test mode ${green}enabled${lBlue}, configure the ${lCyan}ha-serv${lBlue} VMs${NC}"
	# Update the vagrant settings file
	sed -i -e '/server_name/s/.*/server_name: "ha-serv'${uId}'-"/' settings.vagrant.yaml
	sed -i -e '/docker_push_registry/s/.*/docker_push_registry: "vinstall'${uId}':5000"/' ansible/group_vars/all
	sed -i -e "/vinstall/s/vinstall/vinstall${uId}/" ../ansible/roles/docker/templates/daemon.json

	# Set the insecure registry configuration based on the installer hostname
	echo -e "${lBlue}Set up the insecure registry config for hostname ${lCyan}vinstall${uId}${NC}"
	echo '{' > ansible/roles/voltha/templates/daemon.json
	echo '"insecure-registries" : ["vinstall'${uId}':5000"]' >> ansible/roles/voltha/templates/daemon.json
	echo '}' >> ansible/roles/voltha/templates/daemon.json

	# Change the installer name
	iVmName="vInstaller${uId}"
else
	rm -fr .test
	# Clean out the install config file keeping only the commented lines
        # which serve as documentation.
	sed -i -e '/^#/!d' install.cfg
	# Set the insecure registry configuration based on the installer hostname
	echo -e "${lBlue}Set up the inescure registry config for hostname ${lCyan}vinstall${NC}"
	sed -i -e '/docker_push_registry/s/.*/docker_push_registry: "vinstall:5000"/' ansible/group_vars/all
	echo '{' > ansible/roles/voltha/templates/daemon.json
	echo '"insecure-registries" : ["vinstall:5000"]' >> ansible/roles/voltha/templates/daemon.json
	echo '}' >> ansible/roles/voltha/templates/daemon.json
fi

# Check to make sure that the vagrant-libvirt network is both defined and started
echo -e "${lBlue}Verify tha the ${lCyan}vagrant-libvirt${lBlue} network is defined and started${NC}"
virsh net-list | grep "vagrant-libvirt" > /dev/null
rtrn=$?
if [ $rtrn -eq 1 ]; then
	# The network isn't running, check if it's defined
	virsh net-list --all | grep "vagrant-libvirt" > /dev/null
	rtrn=$?
	if [ $rtrn -eq 1 ]; then
		# Not defined either
		echo -e "${lBlue}Defining the ${lCyan}vagrant-libvirt${lBlue} network${NC}"
		virsh net-define vagrant-libvirt.xml
		echo -e "${lBlue}Starting the ${lCyan}vagrant-libvirt${lBlue} network${NC}"
		virsh net-start vagrant-libvirt
	else
		# Defined but not started
		echo -e "${lBlue}Starting the ${lCyan}vagrant-libvirt${lBlue} network${NC}"
		virsh net-start vagrant-libvirt
	fi
else
	echo -e "${lBlue}The ${lCyan}vagrant-libvirt${lBlue} network is ${green} running${NC}"
fi


# Shut down the domain in case it's running.
echo -e "${lBlue}Shut down the ${lCyan}$iVmName${lBlue} VM if running${NC}"
ctr=0
{'fraction_non_alphanumeric': 0.1613700168444694, 'fraction_numerical': 0.02335766423357664, 'mean_word_length': 4.683471601786854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, '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': '2729885', 'n_tokens_mistral': 3547, 'n_tokens_neox': 3269, 'n_words': 848}