mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-09-04 12:07:56 +00:00
refactor(networkutils): rename isIpaddr to isIpv4addr
This commit is contained in:
@@ -139,7 +139,7 @@ sub getIPaddress
|
||||
my $type = shift;
|
||||
my $nodetocheck = shift;
|
||||
my $port = shift;
|
||||
if (xCAT::NetworkUtils::isIpaddr($nodetocheck)) {
|
||||
if (xCAT::NetworkUtils::isIpv4addr($nodetocheck)) {
|
||||
return $nodetocheck;
|
||||
}
|
||||
my $side = "[A|B]";
|
||||
@@ -201,7 +201,7 @@ sub getIPaddress
|
||||
if ($tmp_s and $tmp_s =~ /^$side-$port$/i) {
|
||||
$tmp_s =~ s/a/A/;
|
||||
$tmp_s =~ s/b/B/;
|
||||
if (xCAT::NetworkUtils::isIpaddr($tmp_n)) {
|
||||
if (xCAT::NetworkUtils::isIpv4addr($tmp_n)) {
|
||||
$node_side_pairs{$tmp_s} = $tmp_n;
|
||||
$children_num++;
|
||||
} else {
|
||||
|
||||
@@ -1687,7 +1687,7 @@ sub getNodeIPaddress
|
||||
}
|
||||
|
||||
# Quick return if pass in an IP
|
||||
return $nodetocheck if (xCAT::NetworkUtils->isIpaddr($nodetocheck));
|
||||
return $nodetocheck if (xCAT::NetworkUtils->isIpv4addr($nodetocheck));
|
||||
|
||||
my $nodeip = xCAT::NetworkUtils->getipaddr($nodetocheck);
|
||||
if (!$nodeip)
|
||||
@@ -2132,7 +2132,7 @@ sub validate_ip
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 isIpaddr
|
||||
=head3 isIpv4addr
|
||||
|
||||
returns 1 if parameter is has a valid IP address form.
|
||||
|
||||
@@ -2154,7 +2154,7 @@ sub validate_ip
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub isIpaddr
|
||||
sub isIpv4addr
|
||||
{
|
||||
my $addr = shift;
|
||||
if (($addr) && ($addr =~ /xCAT::NetworkUtils/))
|
||||
@@ -2183,6 +2183,20 @@ sub isIpaddr
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 isIpaddr
|
||||
|
||||
Deprecated alias for isIpv4addr, kept for external callers.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub isIpaddr
|
||||
{
|
||||
return isIpv4addr(@_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -520,7 +520,7 @@ sub mkhwconn
|
||||
for my $nn (@newnodes)
|
||||
{
|
||||
my $node_ip;
|
||||
unless (xCAT::NetworkUtils->isIpaddr($nn)) {
|
||||
unless (xCAT::NetworkUtils->isIpv4addr($nn)) {
|
||||
$node_ip = xCAT::NetworkUtils::getNodeIPaddress($nn);
|
||||
} else {
|
||||
$node_ip = $nn;
|
||||
|
||||
@@ -1106,7 +1106,7 @@ sub get_host {
|
||||
}
|
||||
|
||||
if ($tmpmtm eq $mtm and $tmpsn eq $sn) {
|
||||
my $ifip = xCAT::NetworkUtils->isIpaddr($oldnode);
|
||||
my $ifip = xCAT::NetworkUtils->isIpv4addr($oldnode);
|
||||
if ($ifip) { # which means that the node is defined by the new lsslp
|
||||
if ($tmpside eq $side) { # match! which means that node is the same as the new one
|
||||
if ($ip eq $tmpip) { #which means that the ip is not changed
|
||||
@@ -1230,7 +1230,7 @@ sub get_host {
|
||||
}
|
||||
|
||||
# not matched, use the new name
|
||||
my $ifip = xCAT::NetworkUtils->isIpaddr($nodename);
|
||||
my $ifip = xCAT::NetworkUtils->isIpv4addr($nodename);
|
||||
unless ($ifip) {
|
||||
return $nodename;
|
||||
} else {
|
||||
@@ -1338,7 +1338,7 @@ sub read_from_table {
|
||||
@{ $::OLD_DATA_CACHE{ $entry->{node} } }[1] = @{ $vpdhash{ $entry->{node} } }[1]; #sn
|
||||
@{ $::OLD_DATA_CACHE{ $entry->{node} } }[2] = @{ $vpdhash{ $entry->{node} } }[2]; #side
|
||||
# find node ip address, check node name first, then check hosts table
|
||||
my $ifip = xCAT::NetworkUtils->isIpaddr($entry->{node});
|
||||
my $ifip = xCAT::NetworkUtils->isIpv4addr($entry->{node});
|
||||
if ($ifip)
|
||||
{
|
||||
@{ $::OLD_DATA_CACHE{ $entry->{node} } }[3] = $entry->{node}; #ip
|
||||
|
||||
@@ -487,7 +487,7 @@ sub obtain_log_content {
|
||||
if ($split_line[0] =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)(.+)-(.+)/) {
|
||||
$log_content{time_record} = "$4:$5:$6";
|
||||
$log_content{time} = $self->convert_to_epoch_seconds($split_line[0]);
|
||||
if (!xCAT::NetworkUtils->isIpaddr($split_line[1])) {
|
||||
if (!xCAT::NetworkUtils->isIpv4addr($split_line[1])) {
|
||||
my @sender_tmp = split(/\./, $split_line[1]);
|
||||
$log_content{sender} = $sender_tmp[0];
|
||||
} else {
|
||||
@@ -515,7 +515,7 @@ sub obtain_log_content {
|
||||
my $timestamp = join(" ", @split_line[ 0 .. 2 ]);
|
||||
$log_content{time_record} = $split_line[2];
|
||||
$log_content{time} = $self->convert_to_epoch_seconds($timestamp);
|
||||
if (!xCAT::NetworkUtils->isIpaddr($split_line[3])) {
|
||||
if (!xCAT::NetworkUtils->isIpv4addr($split_line[3])) {
|
||||
my @sender_tmp = split(/\./, $split_line[3]);
|
||||
$log_content{sender} = $sender_tmp[0];
|
||||
} else {
|
||||
@@ -546,7 +546,7 @@ sub obtain_log_content {
|
||||
$log_content{time_record} = "$4:$5:$6";
|
||||
}
|
||||
$log_content{time} = $self->convert_to_epoch_seconds($split_line[3]);
|
||||
if (!xCAT::NetworkUtils->isIpaddr($split_line[0])) {
|
||||
if (!xCAT::NetworkUtils->isIpv4addr($split_line[0])) {
|
||||
my @sender_tmp = split(/\./, $split_line[0]);
|
||||
$log_content{sender} = $sender_tmp[0];
|
||||
} else {
|
||||
|
||||
@@ -478,7 +478,7 @@ sub do_pre_check {
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if (!xCAT::NetworkUtils->isIpaddr("$masteripinsite")) {
|
||||
if (!xCAT::NetworkUtils->isIpv4addr("$masteripinsite")) {
|
||||
probe_utils->send_msg("stdout", "f", $msg);
|
||||
probe_utils->send_msg("stdout", "d", "The value of 'master' in 'site' table isn't an IP address");
|
||||
exit 1;
|
||||
|
||||
@@ -401,7 +401,7 @@ sub check_site_table {
|
||||
$rst = 1;
|
||||
}
|
||||
} else {
|
||||
if (($attr eq "master") and (!xCAT::NetworkUtils->isIpaddr("$value"))) {
|
||||
if (($attr eq "master") and (!xCAT::NetworkUtils->isIpv4addr("$value"))) {
|
||||
my $masterip = xCAT::NetworkUtils->getipaddr("$value");
|
||||
if (! defined $masterip){
|
||||
push @$error_ref, "The value of 'master' in 'site' table isn't an IP address and can not be resolved to a IP address";
|
||||
@@ -571,7 +571,7 @@ sub check_directory {
|
||||
my $mountip;
|
||||
if ($mountoutput =~ /(.+):$sitetable_ref->{$dir} on $sitetable_ref->{$dir} /) {
|
||||
my $mountsource = $1;
|
||||
if (xCAT::NetworkUtils->isIpaddr($mountsource)) {
|
||||
if (xCAT::NetworkUtils->isIpv4addr($mountsource)) {
|
||||
$mountip = $mountsource;
|
||||
} else {
|
||||
$mountip = xCAT::NetworkUtils->getipaddr($mountsource);
|
||||
|
||||
@@ -4932,7 +4932,7 @@ sub isobjnamevalid{
|
||||
$objtype="node" unless(defined $objtype and ($objtype ne ""));
|
||||
if($objtype eq "node"){
|
||||
#the ip address as a valid node object name is a hack for p7IH support
|
||||
if(($objname !~ /^[a-zA-Z0-9-_]+$/) and !xCAT::NetworkUtils->isIpaddr($objname)){
|
||||
if(($objname !~ /^[a-zA-Z0-9-_]+$/) and !xCAT::NetworkUtils->isIpv4addr($objname)){
|
||||
return 0;
|
||||
}
|
||||
} elsif ($objtype eq "group"){
|
||||
|
||||
@@ -2424,7 +2424,7 @@ sub process_request
|
||||
foreach my $node (@{ $req->{node} }) {
|
||||
|
||||
#need to change the way of finding IP for nodes
|
||||
my $ifip = xCAT::NetworkUtils->isIpaddr($node);
|
||||
my $ifip = xCAT::NetworkUtils->isIpv4addr($node);
|
||||
if ($ifip)
|
||||
{
|
||||
$ip_hash->{$node} = $node;
|
||||
|
||||
@@ -297,7 +297,7 @@ sub addotherinterfaces
|
||||
} else {
|
||||
($itf, $ip) = split(/:/, $_);
|
||||
}
|
||||
if ($ip && xCAT::NetworkUtils->isIpaddr($ip))
|
||||
if ($ip && xCAT::NetworkUtils->isIpv4addr($ip))
|
||||
{
|
||||
if ($itf =~ /^-/)
|
||||
{
|
||||
@@ -330,7 +330,7 @@ sub delotherinterfaces
|
||||
} else {
|
||||
($itf, $ip) = split(/:/, $_);
|
||||
}
|
||||
if ($ip && xCAT::NetworkUtils->isIpaddr($ip))
|
||||
if ($ip && xCAT::NetworkUtils->isIpv4addr($ip))
|
||||
{
|
||||
if ($itf =~ /^-/)
|
||||
{
|
||||
@@ -393,7 +393,7 @@ sub add_hosts_content {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xCAT::NetworkUtils->isIpaddr($ip))
|
||||
if (xCAT::NetworkUtils->isIpv4addr($ip))
|
||||
{
|
||||
addnode $callback, $nodename, $ip, $ref->{hostnames}, $domain;
|
||||
}
|
||||
@@ -632,7 +632,7 @@ sub process_request
|
||||
$domain = $::XCATSITEVALS{domain};
|
||||
}
|
||||
|
||||
if (xCAT::NetworkUtils->isIpaddr($_->{ip}))
|
||||
if (xCAT::NetworkUtils->isIpv4addr($_->{ip}))
|
||||
{
|
||||
addnode $callback, $_->{node}, $_->{ip}, $_->{hostnames}, $domain;
|
||||
}
|
||||
|
||||
@@ -1359,7 +1359,7 @@ sub rspconfig_parse_address_port {
|
||||
return (undef, undef, "Invalid parameter: $value");
|
||||
}
|
||||
|
||||
return (undef, undef, "Invalid parameter: $address") if (!xCAT::NetworkUtils->isIpaddr($address));
|
||||
return (undef, undef, "Invalid parameter: $address") if (!xCAT::NetworkUtils->isIpv4addr($address));
|
||||
return (undef, undef, "Invalid parameter: $port") if (!rspconfig_valid_port($port) or $port == 0);
|
||||
return ($address, $port, undef);
|
||||
}
|
||||
@@ -1678,12 +1678,12 @@ sub parse_args {
|
||||
|
||||
my $nodes_num = @$noderange;
|
||||
return ([ 1, "Invalid parameter for option $key" ]) if (!$value and $key ne ("ntpservers"));
|
||||
return ([ 1, "Invalid parameter for option $key: $value" ]) if (($key eq "netmask") and !xCAT::NetworkUtils->isIpaddr($value));
|
||||
return ([ 1, "Invalid parameter for option $key: $value" ]) if (($key eq "gateway") and ($value !~ "0.0.0.0" and !xCAT::NetworkUtils->isIpaddr($value)));
|
||||
return ([ 1, "Invalid parameter for option $key: $value" ]) if (($key eq "netmask") and !xCAT::NetworkUtils->isIpv4addr($value));
|
||||
return ([ 1, "Invalid parameter for option $key: $value" ]) if (($key eq "gateway") and ($value !~ "0.0.0.0" and !xCAT::NetworkUtils->isIpv4addr($value)));
|
||||
if ($key eq "ip") {
|
||||
return ([ 1, "Can not configure more than 1 nodes' ip at the same time" ]) if ($nodes_num >= 2 and $value ne "dhcp");
|
||||
if ($value ne "dhcp" ) {
|
||||
if (!xCAT::NetworkUtils->isIpaddr($value)) {
|
||||
if (!xCAT::NetworkUtils->isIpv4addr($value)) {
|
||||
return ([ 1, "Invalid parameter for option $key: $value" ]);
|
||||
} else {
|
||||
$all_subcommand .= $key . ",";
|
||||
|
||||
@@ -324,12 +324,12 @@ sub parse_args {
|
||||
return([1, "Invalid parameter for option $key: $value"]);
|
||||
}
|
||||
} elsif ($key eq "netmask") {
|
||||
if (!xCAT::NetworkUtils->isIpaddr($value)) {
|
||||
if (!xCAT::NetworkUtils->isIpv4addr($value)) {
|
||||
return ([ 1, "Invalid parameter for option $key: $value" ]);
|
||||
}
|
||||
$set_net_info{"netmask"} = 1;
|
||||
} elsif ($key eq "gateway") {
|
||||
if ($value ne "0.0.0.0" and !xCAT::NetworkUtils->isIpaddr($value)) {
|
||||
if ($value ne "0.0.0.0" and !xCAT::NetworkUtils->isIpv4addr($value)) {
|
||||
return ([ 1, "Invalid parameter for option $key: $value" ]);
|
||||
}
|
||||
$set_net_info{"gateway"} = 1;
|
||||
@@ -339,7 +339,7 @@ sub parse_args {
|
||||
if ($value ne "dhcp") {
|
||||
if (@$noderange > 1) {
|
||||
return ([ 1, "Can not configure more than 1 nodes' ip at the same time" ]);
|
||||
} elsif (!xCAT::NetworkUtils->isIpaddr($value)) {
|
||||
} elsif (!xCAT::NetworkUtils->isIpv4addr($value)) {
|
||||
return ([ 1, "Invalid parameter for option $key: $value" ]);
|
||||
}
|
||||
$set_net_info{"ip"} = 1;
|
||||
|
||||
Reference in New Issue
Block a user