Created
February 7, 2013 00:12
-
-
Save jasonpincin/4727161 to your computer and use it in GitHub Desktop.
Updates IP addresses of a SmartOS VM (with less hassle)
This file contains 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
#!/usr/bin/bash | |
# Updates IP addresses of a SmartOS VM | |
# This script stops the VM, updates the IP address(es), | |
# and starts the VM back up. | |
# | |
# Usage: | |
# vmip.sh <uuid> <ip1> [ip2] [ip3] [...] | |
# | |
# The IP's are applied to NICs of the VM in order. The | |
# first interface will be assigned <ip1>, the second | |
# interface will be assigned [ip2], etc. You can see | |
# the order of the NICS by executing the following | |
# command prior to running vmip: | |
# | |
# vmadm get <uuid> | json nics | |
cmd="{\"update_nics\": [" | |
for (( i=2; i<= $#; i++ )) | |
do | |
idx=$(($i-2)) | |
mac=$(vmadm get $1 |json nics |json $idx| json mac) | |
if [ $idx -gt 0 ] | |
then | |
cmd="$cmd, " | |
fi | |
cmd="$cmd { \"mac\":\"$mac\", \"ip\":\"${@:$i:1}\"}" | |
done | |
cmd="$cmd]}" | |
fi | |
cmd="$cmd { \"mac\":\"$mac\", \"ip\":\"${@:$i:1}\"}" | |
done | |
cmd="$cmd]}" | |
vmadm stop $1 | |
echo $cmd | vmadm update $1 | |
vmadm start $1 | |
vmadm get $1 | json nics |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are lines 36 through 39 meant to be duplicates of lines 30 through 33?