Skip to content

Instantly share code, notes, and snippets.

@jasonpincin
Created February 7, 2013 00:12
Show Gist options
  • Save jasonpincin/4727161 to your computer and use it in GitHub Desktop.
Save jasonpincin/4727161 to your computer and use it in GitHub Desktop.
Updates IP addresses of a SmartOS VM (with less hassle)
#!/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
@gozoinks
Copy link

Are lines 36 through 39 meant to be duplicates of lines 30 through 33?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment