mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-31 10:06:39 +00:00
Merge pull request #2085 from xuweibj/probeutils
delete extra functions in probe_utils
This commit is contained in:
commit
e7da599706
@ -354,32 +354,6 @@ sub is_dns_ready {
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Convert host name to ip address
|
||||
Arguments:
|
||||
hostname: The hostname need to convert
|
||||
Returns:
|
||||
ip: The ip address
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub get_ip_from_hostname {
|
||||
my $hostname = shift;
|
||||
$hostname = shift if (($hostname) && ($hostname =~ /probe_utils/));
|
||||
my $ip = "";
|
||||
|
||||
my @output = `ping -c 1 $hostname 2>&1`;
|
||||
if (!$?) {
|
||||
if ($output[0] =~ /^PING.+\s+\((\d+\.\d+\.\d+\.\d+)\).+/) {
|
||||
$ip = $1;
|
||||
}
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Calculate network address from ip and netmask
|
||||
@ -409,45 +383,6 @@ sub get_network {
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Convert ip to hostname
|
||||
Arguments:
|
||||
ip: The ip need to convert
|
||||
Returns:
|
||||
hostname: hostname or ""
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub get_hostname_from_ip {
|
||||
my $ip = shift;
|
||||
$ip = shift if (($ip) && ($ip =~ /probe_utils/));
|
||||
my $dns_server = shift;
|
||||
my $hostname = "";
|
||||
my $output = "";
|
||||
|
||||
`which nslookup > /dev/null 2>&1`;
|
||||
if (!$?) {
|
||||
$output = `nslookup $ip $dns_server 2>&1`;
|
||||
if (!$?) {
|
||||
chomp($output);
|
||||
my $rc = $hostname = `echo "$output"|awk -F" " '/name =/ {print \$4}'|awk -F"." '{print \$1}'`;
|
||||
chomp($hostname);
|
||||
return $hostname if (!$rc);
|
||||
}
|
||||
}
|
||||
if (($hostname eq "") && (-e "/etc/hosts")) {
|
||||
$output = `cat /etc/hosts 2>&1 |grep $ip`;
|
||||
if (!$?) {
|
||||
my @splitoutput = split(" ", $output);
|
||||
$hostname = $splitoutput[1];
|
||||
}
|
||||
}
|
||||
return $hostname;
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Check if the free space of specific directory is more than expected value
|
||||
@ -482,48 +417,6 @@ sub is_dir_has_enough_space{
|
||||
return 2;
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Convert input time format to the number of non-leap seconds since whatever time the system considers to be the epoch
|
||||
the format of input time are two kinds
|
||||
one like "Aug 15 02:43:31", another likes "15/Aug/2016:01:10:24"
|
||||
Arguments:
|
||||
timestr: the time format need to be converted
|
||||
yday: the year of current time.
|
||||
Returns:
|
||||
the number of non-leap seconds since whatever time the system considers to be the epoch
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub convert_to_epoch_seconds {
|
||||
my $timestr=shift;
|
||||
$timestr = shift if (($timestr) && ($timestr =~ /probe_utils/));
|
||||
my $yday=shift;
|
||||
my $ref_seconds=shift;
|
||||
my $mday;
|
||||
my $dday;
|
||||
my $h;
|
||||
my $m;
|
||||
my $s;
|
||||
my $epoch_seconds=-1;
|
||||
my %monthsmap = ("Jan"=>0,"Feb"=>1,"Mar"=>2,"Apr"=>3,"May"=>4,"Jun"=>5,"Jul"=>6,"Aug"=>7,"Sep"=>8,"Oct"=>9,"Nov"=>10,"Dec"=>11);
|
||||
|
||||
if($timestr =~/(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)/){
|
||||
($mday,$dday,$h,$m,$s)=($1,$2,$3,$4,$5);
|
||||
$epoch_seconds = timelocal($s,$m,$h,$dday,$monthsmap{$mday},$yday);
|
||||
if($epoch_seconds>$ref_seconds){
|
||||
$yday-=1;
|
||||
$epoch_seconds = timelocal($s,$m,$h,$dday,$monthsmap{$mday},$yday);
|
||||
}
|
||||
}elsif($timestr =~ /(\d+)\/(\w+)\/(\d+):(\d+):(\d+):(\d+)/){
|
||||
$epoch_seconds = timelocal($6,$5,$4,$1,$monthsmap{$2},($3-1900));
|
||||
}
|
||||
return $epoch_seconds;
|
||||
}
|
||||
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
|
Loading…
x
Reference in New Issue
Block a user