ENV=prod
REGION=us
HOSTMACHINE=mc02
VIRTUALMACHINE=mp
#OSVERSION=22.04
OSVERSION=noble
OS=ub
NETWORK=en0
if [ "$APP" == "" ]
then
APP=kubeadm
fi
currentHost=`hostname`
CPU=6
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 [ "Gangammals-Mini.heaerieglobalsolutions.net" == "$currentHost" ]
then
HOSTMACHINE="mc03"
fi
if [ "Shanthys-Mini.heaerieglobalsolutions.net" == "$currentHost" ]
then
HOSTMACHINE="mc02"
fi
if [ "Agalyas-Air.heaerieglobalsolutions.net" == "$currentHost" ]
then
HOSTMACHINE="mc01"
fi
if [ "us-ub01-prod-pc-ub2404-eth0-dc-0" == "$currentHost" ]
then
HOSTMACHINE="ub01"
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 8G --disk 50G --cpus $CPU --network $NETWORK --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