The Latest Gartner® Magic Quadrant™Hyperconverged Infrastructure Software
Moderators: anton (staff), art (staff), Anatoly (staff), Max (staff)
Code: Select all
#!/usr/bin/env perl
use Getopt::Long;
use strict;
use warnings;
my $debug = 0;
my $report_only = 0;
my $host_uuid;
my $sr_uuid;
GetOptions (
'sr-uuid=s' => \$sr_uuid,
'debug' => \$debug
);
my $uuid_regex = '[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}';
my $exit_code = 0;
if ($sr_uuid !~ /$uuid_regex/) {
print STDERR "Invalid format host UUID specified: $sr_uuid\n";
exit 2;
}
open(my $xensource_inventory_fh, '< /etc/xensource-inventory') or die("Unable to read /etc/xensource-inventory: $!");
while(<$xensource_inventory_fh>) {
chomp;
if ($_ =~ /INSTALLATION_UUID='($uuid_regex)'/) {
$host_uuid = $1;
last;
}
}
if (! defined($host_uuid)) {
print STDERR "Unable to determine host-uuid\n";
exit 2;
}
my @sessions;
print "iscsiadm -m session\n" if $debug;
open(my $iscsiadm_session_stdout, '-|', 'iscsiadm', '-m', 'session');
while(<$iscsiadm_session_stdout>) {
chomp;
if (my @session = $_ =~ /.*?\]\s+(.*?):[0-9}+,[0-9]+\s+(iqn[^\s]+)/) {
push(@sessions, \@session);
}
}
close $iscsiadm_session_stdout;
exit $? if $? != 0;
my $pbd_uuid;
print "xe pbd-list host-uuid=$host_uuid sr-uuid=$sr_uuid\n" if $debug;
open(my $xe_pbd_list_stdout, '-|', 'xe', 'pbd-list', "host-uuid=$host_uuid", "sr-uuid=$sr_uuid");
while(<$xe_pbd_list_stdout>) {
chomp;
if ($_ =~ /^uuid.*($uuid_regex)/) {
$pbd_uuid = $1;
}
}
close($xe_pbd_list_stdout);
exit $? if $? != 0;
if (defined($pbd_uuid)) {
my $multi_session_config;
print "xe pbd-param-get param-name=device-config uuid=$pbd_uuid\n" if $debug;
open(my $xe_pbd_param_get_stdout, '-|', 'xe', 'pbd-param-get', 'param-name=device-config', "uuid=$pbd_uuid");
while(<$xe_pbd_param_get_stdout>) {
chomp;
if ($_ =~ /^multiSession.*: (.*?)\|;/) {
$multi_session_config = $1;
}
}
close($xe_pbd_param_get_stdout);
exit $? if $? != 0;
if (defined($multi_session_config)) {
my @paths = split(/\|/, $multi_session_config);
if (scalar @paths < 1) {
print STDERR "Unable to parse 'xe pbd-param-get' command output\n";
exit 2;
} else {
foreach my $path (@paths) {
my $match_found;
my @path_settings = split(/,/, $path);
foreach my $session (@sessions) {
if ($$session[0] eq $path_settings[0] && $$session[1] eq $path_settings[2]) {
$match_found = 1;
}
}
if (! $match_found) {
print STDERR "No session found for $path_settings[2] on $path_settings[0]\n";
if (! $report_only) {
print "iscsiadm -m node -T $path_settings[2] -p $path_settings[0] -l\n" if $debug;
system('iscsiadm', '-m', 'node', '-T', $path_settings[2], '-p', $path_settings[0], '-l');
$exit_code = 1 if $? != 0;
}
}
}
}
} else {
print STDERR "Unable to parse 'xe pbd-param-get' command output\n";
exit 2;
}
} else {
print STDERR "Unable to locate PDB for host-uuid=$host_uuid and sr-uuid=$sr_uuid. Please check Host and SR UUID then try SR repair.\n";
}
exit $exit_code;