Skip to content

Instantly share code, notes, and snippets.

@staybuzz
Last active March 16, 2016 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staybuzz/bcdae3b1727165858719 to your computer and use it in GitHub Desktop.
Save staybuzz/bcdae3b1727165858719 to your computer and use it in GitHub Desktop.
#!/bin/sh
#ref: http://orebibou.com/2014/01/esxi%E4%B8%8A%E3%81%AE%E4%BB%AE%E6%83%B3%E3%83%9E%E3%82%B7%E3%83%B3nic%E3%81%AEmac%E3%82%A2%E3%83%89%E3%83%AC%E3%82%B9%E4%B8%80%E6%8B%AC%E5%8F%96%E5%BE%97%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88/
#Get VM List
VimCmdList=`vim-cmd vmsvc/getallvms | grep "vmx-" | grep ".vmx" | awk '{print $2,$3,$4}'`
IFS=$'\n'
cat /dev/null > tmp.list
cat /dev/null > 1-6.list
for i in $VimCmdList; do
#Get VM Name
VMName=`echo "$i" | awk '{print $1}'`
#Get vmx file place
VMXFolder=`echo "$i" | awk '{print $2}' | cut -d"[" -f2 | cut -d"]" -f1`
VMXFile=`echo "$i" | awk '{print $3}'`
#Get VM MAC Address
VMEthernetInfo=`cat /vmfs/volumes/$VMXFolder/$VMXFile | sort | grep "networkName \|generatedAddress " | cut -d"\"" -f2 | cut -d"\"" -f1 | sed ':loop; N; $!b loop; ;s/\n/,/g' | cut -d "," -f1`
echo $VMName,$VMEthernetInfo
for i in $VMEthernetInfo; do
#echo "$VMName,$i"
TeamNo=`echo $VMName | cut -d "_" -f1 | sed "s/T//"`
# for VLAN X2
First=192
Second=168
Third=`expr $TeamNo + 100`
case $VMName in
*_RT3)
Forth=1;;
*_CentOS)
Forth=2;;
*_MySQL_Eipiration)
Forth=3;;
*_GFS1)
Forth=4;;
*_GFS2)
Forth=5;;
*_GFS3)
Forth=6;;
*_MySQL_Pictogram)
Forth=7;;
*_SELinux)
Forth=8;;
*)
;;
esac
# for VLAN X3
First=10
Second=$TeamNo
Third=3
case $VMName in
*_shellshock)
Forth=2;;
*_DNS_DoS)
Forth=3;;
*_NTP_DoS)
Forth=4;;
*_SNMP_DoS)
Forth=5;;
*_SSDP_DoS)
Forth=6;;
*_Proxy_DoS)
Forth=7;;
*)
;;
esac
# for VLAN X4
First=10
Second=$TeamNo
Third=4
case $VMName in
*_VyOS_pingDoS)
Forth=1;;
*_ping_DoS)
Forth=2;;
*)
;;
esac
# for VLAN X5
First=10
Second=$TeamNo
Third=5
case $VMName in
*_RT4)
Forth=1;;
*_Tunnel_check)
Forth=2;;
*)
;;
esac
# dump dhcp conf
if [ $Forth -ne 0 ];
then
echo -e "host ${VMName} {
\thardware ethernet ${i};
\tfixed-address ${First}.${Second}.${Third}.${Forth};
\toption subnet-mask 255.255.255.0;
\toption broadcast-address ${First}.${Second}.${Third}.255;
\toption routers ${First}.${Second}.${Third}.1;
\toption domain-name "pkpk";
\toption domain-name-servers 172.17..105.2
}"
echo -e "${VMName},${First}.${Second}.${Third}.${Forth}" >> tmp.list
fi
done
done
for i in `seq 1 1 15` ; do
echo -e "[team${i}]" >> 1-15.list
cat tmp.list | sort | grep T${i} | cut -d"," -f2 >> 1-15.list
echo -e "\n" >> 1-15.list
done
rm -f tmp.list
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment