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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#!/bin/bash svc_cluster_ip=10.0.0.10 svc_priv_dsa=~/.ssh/id_dsa_svc if [ -n $2 ] ; then echo " copyvdiskhostmap.sh [ host_to | host_from ]" echo 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." echo exit 1; fi 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!" fi host_to=$1 host_from=$2 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 done |