config_iscsi.exp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/local/bin/expect
  2. if { ! [info exists env(ESXI_ROOT_PW)] } {
  3. puts "ERROR: Please set the ESXI_ROOT_PW environment variable first!"
  4. exit 1
  5. }
  6. if { ! [info exists env(VI_USERNAME)] } {
  7. puts "ERROR: Please set the VI_USERNAME environment variable first!"
  8. exit 1
  9. }
  10. if { ! [info exists env(VI_PASSWORD)] } {
  11. puts "ERROR: Please set the VI_PASSWORD environment variable first!"
  12. exit 1
  13. }
  14. if { ! [info exists env(VI_SERVER)] } {
  15. puts "ERROR: Please set the VI_SERVER environment variable first!"
  16. exit 1
  17. }
  18. set pw $env(ESXI_ROOT_PW)
  19. set hosts [list \
  20. "dc1-hv-1.ciscolive.network" \
  21. "dc1-hv-2.ciscolive.network" \
  22. "dc1-hv-3.ciscolive.network" \
  23. "dc1-hv-4.ciscolive.network" \
  24. "dc1-hv-5.ciscolive.network" \
  25. "dc1-hv-6.ciscolive.network" \
  26. "dc1-hv-7.ciscolive.network" \
  27. "dc1-hv-8.ciscolive.network" \
  28. "dc2-hv-1.ciscolive.network" \
  29. "dc2-hv-2.ciscolive.network" \
  30. "dc2-hv-3.ciscolive.network" \
  31. "dc2-hv-4.ciscolive.network" \
  32. "dc2-hv-5.ciscolive.network" \
  33. "dc2-hv-6.ciscolive.network" \
  34. "dc2-hv-7.ciscolive.network" \
  35. "dc2-hv-8.ciscolive.network"]
  36. #set hosts [list "dc1-hv-5.ciscolive.network"]
  37. set vmks [list "vmk1" "vmk4"]
  38. 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"]]
  39. foreach host $hosts {
  40. if { [catch {exec /home/jclarke/iscsiMultiPath.pl $host} result] } {
  41. puts "ERROR: Failed to get iSCSI HBA for $host: $result"
  42. continue
  43. }
  44. set hba $result
  45. eval spawn ssh -o StrictHostKeyChecking=no root@$host
  46. interact -o -nobuffer -re "assword:" return
  47. send "$pw\r"
  48. interact -o -nobuffer -re "root@.*\]" return
  49. foreach vmk $vmks {
  50. send "esxcli iscsi networkportal add --nic $vmk --adapter $hba\r"
  51. expect -re "root@.*\]"
  52. }
  53. if { [regexp {^(dc\d)-} $host -> dc] } {
  54. set targets $target_arr($dc)
  55. foreach target $targets {
  56. send "vmkiscsi-tool -D -a $target $hba\r"
  57. expect -re "root@.*\]"
  58. }
  59. }
  60. send "esxcli storage core adapter rescan --adapter $hba\r"
  61. expect -re "root@.*\]"
  62. send "exit\r"
  63. }