Created
August 17, 2015 00:09
-
-
Save staybuzz/0ac11b8a5fcfa86c27ab to your computer and use it in GitHub Desktop.
make portgroup on vcenter from csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#csvfile=vlan-list.csv | |
# s -> source csv file | |
# n -> name of vswitch | |
# TODO: option is required | |
# $ ./mkpg.sh -s vlan-list.csv -n vswitch1 | |
while getopts s:n: OPT | |
do | |
case $OPT in | |
"s" ) FLG_S="TRUE" ; csvfile="$OPTARG" ;; | |
"n" ) FLG_N="TRUE" ; SWITCH_NAME="$OPTARG" ;; | |
esac | |
done | |
echo "${csvfile}" | |
echo "${SWITCH_NAME}" | |
for line in `cat ${csvfile} | grep -v ^#` | |
do | |
vlanid=`echo ${line} | cut -d ',' -f 1` | |
name=`echo ${line} | cut -d ',' -f 2` | |
echo "----" | |
echo ${vlanid} | |
echo ${name} | |
echo "----" | |
# Add PortGroup | |
esxcfg-vswitch -A "${name}" vSwitch0 | |
# Configure VLAN ID | |
esxcfg-vswitch -p "${name}" -v ${vlanid} vSwitch0 | |
done | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment