As I wrote a few days ago, I started a new job. One of my first (voluntary) tasks was writing a shell script which would copy a VDisk Host-Mapping from a given host to another. This is useful, if you do have a lot of ESX servers for example and a few roaming ones.
Now, if say, you need to do some ESX-Updates and you would like to add the roaming one to a given farm, you would be in a dark an deary place. You would be required to either click through the GUI a dozen times (in my case, it might have needed ~200 clicks) or type svcinfo lshostvdiskmap <examplehosthere> and svctask mkhostvdiskmap <newhosthere> -force (these are incomplete command references) a few times.
Both methods ain’t optimal nor fast. Since the SVCTools (Perl, jikes) don’t really came into consideration, and the SVC SSH interface really doesn’t provide any other method to do a simple
cut -d: -f3 (as a hint: if anyone knows a nice method to emulate cut with bash patterns — yeah, I ain’t kidding — please drop me a note!), I ended up writing a simple shell script which is gonna do all the tasks from any Linux system (in possession of the SSH DSA private keys for the SVC of course).
The script looks like this:
if [ -n $2 ] ; then
echo " copyvdiskhostmap.sh [ host_to | host_from ]"
echo " host_to - Target host, for which we will create the VDisk map."
echo " host_from - Source host, from which the VDisk map will be copied."
if [ ! -f $svc_priv_dsa ] ; then
echo " copyvdiskhostmap.sh is missing the SSH DSA private key needed"
echo " to access the SAN Volume controller."
echo " Please specify the correct path!"
for mapping in $( ssh -i $svc_priv_dsa admin@$svc_cluster_ip svcinfo
lshostvdiskmap -nohdr -delim : $host_from ); do
vdisk_scsi_id="$( echo $mapping | cut -d: -f3 )"
vdisk_name="$( echo $mapping | cut -d: -f5 )"
ssh -i $svc_priv_dsa admin@$svc_cluster_ip svcinfo lshost $host_to ||
echo "Failed, since the target host doesn't existent!" && break
ssh -i $svc_priv_dsa admin@$svc_cluster_ip svctask mkvdiskhostmap -force
-host $host_to -scsi $vdisk_scsi_id $vdisk_name