#!/usr/bin/env perl

use File::Basename;
my $program_name             = basename($0);

my $os   = $ARGV[0];
my $arch = $ARGV[1];
#my $log  = "/tmp/pre_deploy_sn.log";

print ">>>Enter $program_name\n";
my $orgclusterconffile = "/opt/xcat/share/xcat/tools/autotest/default.conf";
my $snnodename = `cat $orgclusterconffile |grep -E '^SN\s*='|awk -F'=' '{print \$2}'`;
chomp($snnodename);
#`echo "SN=$snnodename" >> $log`;
print "The target SN = $snnodename\n";
sleep 300;

my $timecnt = 0;
while ($timecnt < 120) {
    my $booted = system("lsdef -l $snnodename|grep status|grep booted > /dev/null 2>&1");
    last if ($booted == 0);

    if ($os =~ /rhel/i && $arch =~ /^ppc64$/i) {
        my $booting = system("lsdef -l $snnodename|grep status|grep booting > /dev/null 2>&1");
        system("xdsh $snnodename \"echo 1\"") if ($booting == 0);
        print "send signal to $snnodename for the $timecnt times\n";
        #`echo "send signal to $snnodename for the $timecnt times" >> $log`;
    }

    sleep 30;
    $timecnt++;
}

print ">>>Leave $program_name\n";
exit 0;
