Newer
Older
clusterSetupDev / scripts / createVm.sh
@Agalya Ramadoss Agalya Ramadoss on 12 Apr 2024 1 KB for prod
ENV=prod
REGION=us
HOSTMACHINE=mc02
VIRTUALMACHINE=mp
OSVERSION=22.04
OS=ub
NETWORK=en0
if [ "$APP" == "" ]
then 
	APP=kubeadm
fi

currentHost=`hostname`
CPU=2

function findEthEthernet 
{
	set -x
	eth0=`multipass networks |grep ethernet | grep -v Adapter |cut -d " " -f1`
	
	if [ "$eth0" == "" ] 
	then
		eth0=`multipass networks |grep wifi |cut -d " " -f1`

	fi
	echo $eth0
}

function osVersion
{
	os=$1
	osversion=$2
	echo "${os}${osversion//./}"
}

function createVm
{
	set -x

	action=$1
	NETWORK=$2

	if [ "Shanthys-Mini.heaerieglobalsolutions.net" == "$currentHost" ] 
	then
		HOSTMACHINE="mc02"
	fi

	if [ "Agalyas-Air.heaerieglobalsolutions.net" == "$currentHost" ] 
	then
		HOSTMACHINE="mc01"
	fi
	HOSTNAME_PREFIX="$REGION-$HOSTMACHINE-$ENV-$VIRTUALMACHINE-`osVersion $OS $OSVERSION`-$NETWORK-$APP"
	if [ "$action" == "create" ]
	then 
		echo "create"
		SEQ=`./getSeq.sh $HOSTNAME_PREFIX current++`
	else
		SEQ=`./getSeq.sh $HOSTNAME_PREFIX --current`
	fi
	echo $SEQ
	HOSTNAME="$HOSTNAME_PREFIX-$SEQ"

	mkdir -p  ~/data/$HOSTNAME
	if [ "$action" == "create" ]
	then
		multipass launch $OSVERSION --name $HOSTNAME --memory 4G --disk 50G --cpus $CPU --network en0 --mount ~/data/$HOSTNAME:/data/
	else

		multipass delete $HOSTNAME --purge 
		
	fi

}

noOfinstance=1

if [ "$1" != "" ] 
then 
	noOfinstance=$1
fi

action="create"
if [ "$2" != "" ] 
then 
	action=$2
fi


NETWORK=`findEthEthernet`
for i in $(seq 1 $noOfinstance) 
do 
	echo "$i"
	createVm $action $NETWORK
done