iscsiMultiPath.pl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. use VMware::VILib;
  5. use VMware::VIRuntime;
  6. use Data::Dumper;
  7. # validate options, and connect to the server
  8. Opts::parse();
  9. Opts::validate();
  10. Util::connect();
  11. my $hname = undef;
  12. if (scalar(@ARGV) == 1) {
  13. $hname = $ARGV[0];
  14. }
  15. my @iscsiHosts = ();
  16. if ($hname) {
  17. my $vmhost = Vim::find_entity_view(
  18. view_type => 'HostSystem',
  19. filter => {name => $hname}
  20. );
  21. if (!$vmhost) {
  22. print "Failed to find host $hname\n";
  23. exit(1);
  24. }
  25. push @iscsiHosts, $vmhost;
  26. } else {
  27. my $vmhosts = Vim::find_entity_views(view_type => 'HostSystem',);
  28. foreach (@$vmhosts) {
  29. push @iscsiHosts, $_;
  30. }
  31. }
  32. my $error = 0;
  33. foreach my $host (@iscsiHosts) {
  34. my $ss = Vim::get_view(mo_ref => $host->configManager->storageSystem,);
  35. my $hbas = $ss->storageDeviceInfo->hostBusAdapter;
  36. my $hba = undef;
  37. foreach my $h (@$hbas) {
  38. if ($h->isa('HostInternetScsiHba')) {
  39. $hba = $h;
  40. print $hba->device, "\n";
  41. last;
  42. }
  43. }
  44. if (!$hba) {
  45. print "Did not find HBA for $host->{'name'}\n";
  46. $error = 1;
  47. next;
  48. }
  49. }
  50. Util::disconnect();
  51. if ($error) {
  52. exit(1);
  53. }