#!/usr/local/bin/expect if { ! [info exists env(ESXI_ROOT_PW)] } { puts "ERROR: Please set the ESXI_ROOT_PW environment variable first!" exit 1 } if { ! [info exists env(VI_USERNAME)] } { puts "ERROR: Please set the VI_USERNAME environment variable first!" exit 1 } if { ! [info exists env(VI_PASSWORD)] } { puts "ERROR: Please set the VI_PASSWORD environment variable first!" exit 1 } if { ! [info exists env(VI_SERVER)] } { puts "ERROR: Please set the VI_SERVER environment variable first!" exit 1 } set pw $env(ESXI_ROOT_PW) set hosts [list \ "dc1-hv-1.ciscolive.network" \ "dc1-hv-2.ciscolive.network" \ "dc1-hv-3.ciscolive.network" \ "dc1-hv-4.ciscolive.network" \ "dc1-hv-5.ciscolive.network" \ "dc1-hv-6.ciscolive.network" \ "dc1-hv-7.ciscolive.network" \ "dc1-hv-8.ciscolive.network" \ "dc2-hv-1.ciscolive.network" \ "dc2-hv-2.ciscolive.network" \ "dc2-hv-3.ciscolive.network" \ "dc2-hv-4.ciscolive.network" \ "dc2-hv-5.ciscolive.network" \ "dc2-hv-6.ciscolive.network" \ "dc2-hv-7.ciscolive.network" \ "dc2-hv-8.ciscolive.network"] #set hosts [list "dc1-hv-5.ciscolive.network"] set vmks [list "vmk1" "vmk4"] array set target_arr [list "dc1" [list "10.118.253.20:3260" "10.119.253.20:3260" "10.118.253.21:3260" "10.119.253.21:3260"] "dc2" [list "10.118.253.22:3260" "10.119.253.22:3260" "10.118.253.23:3260" "10.119.253.23:3260"]] foreach host $hosts { if { [catch {exec /home/jclarke/iscsiMultiPath.pl $host} result] } { puts "ERROR: Failed to get iSCSI HBA for $host: $result" continue } set hba $result eval spawn ssh -o StrictHostKeyChecking=no root@$host interact -o -nobuffer -re "assword:" return send "$pw\r" interact -o -nobuffer -re "root@.*\]" return foreach vmk $vmks { send "esxcli iscsi networkportal add --nic $vmk --adapter $hba\r" expect -re "root@.*\]" } if { [regexp {^(dc\d)-} $host -> dc] } { set targets $target_arr($dc) foreach target $targets { send "vmkiscsi-tool -D -a $target $hba\r" expect -re "root@.*\]" } } send "esxcli storage core adapter rescan --adapter $hba\r" expect -re "root@.*\]" send "exit\r" }