update hostname validate rule: only 0-9 a-z and - are valid characters
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14815 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
40eb1fe5ad
commit
7b75b8b766
@ -2205,7 +2205,7 @@ sub isValidMAC
|
||||
sub isValidHostname
|
||||
{
|
||||
my ($class, $hostname) = @_;
|
||||
if ($hostname =~ /^[\-a-zA-Z0-9]+$/){
|
||||
if ($hostname =~ /^[a-z0-9][\-a-z0-9]+[a-z0-9]$/){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@ -2224,7 +2224,7 @@ sub isValidHostname
|
||||
sub isValidFQDN
|
||||
{
|
||||
my ($class, $hostname) = @_;
|
||||
if ($hostname =~ /^[\-\.a-zA-Z0-9]+$/){
|
||||
if ($hostname =~ /^[a-z0-9][\.\-a-z0-9]+[a-z0-9]$/){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -187,16 +187,20 @@ sub get_hostname_format_type{
|
||||
|
||||
my $ridx = index $format, "#R";
|
||||
my $nidx = index $format, "#N";
|
||||
my $simpname = "";
|
||||
if ($ridx >= 0){
|
||||
($prefix, $appendix, $rlen) = xCAT::ProfiledNodeUtils->split_hostname($format, 'R');
|
||||
($prefix, $appendix, $nlen) = xCAT::ProfiledNodeUtils->split_hostname($format, 'N');
|
||||
if ($rlen >= 10 || $nlen >= 10){
|
||||
$simpname = $prefix."0".$appendix;
|
||||
($prefix, $appendix, $nlen) = xCAT::ProfiledNodeUtils->split_hostname($simpname, 'N');
|
||||
$simpname = $prefix."0".$appendix;
|
||||
if ($rlen >= 10 || $nlen >= 10 || $nlen == 0){
|
||||
$type = "unknown";
|
||||
} else{
|
||||
$type = "rack";
|
||||
}
|
||||
} elsif ($nidx >= 0){
|
||||
($prefix, $appendix, $nlen) = xCAT::ProfiledNodeUtils->split_hostname($format, 'N');
|
||||
$simpname = $prefix."0".$appendix;
|
||||
if ($nlen >= 10){
|
||||
$type = "unknown";
|
||||
} else{
|
||||
@ -205,6 +209,12 @@ sub get_hostname_format_type{
|
||||
} else{
|
||||
$type = "unknown";
|
||||
}
|
||||
# validate whether hostname format includes other invalid characters.
|
||||
if ($type ne "unknown"){
|
||||
if (! xCAT::NetworkUtils->isValidHostname($simpname)){
|
||||
$type = "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
@ -1269,12 +1269,6 @@ sub gen_new_hostinfo_string{
|
||||
$allips{$nextip} = 0;
|
||||
}
|
||||
}
|
||||
my $nicips = "";
|
||||
foreach(keys %ipshash){
|
||||
$nicips = "$_:$ipshash{$_},$nicips";
|
||||
}
|
||||
$hostinfo_dict{$item}{"nicips"} = $nicips;
|
||||
|
||||
# Generate IP address if no IP specified.
|
||||
if (! exists $hostinfo_dict{$item}{"ip"}) {
|
||||
if (exists $ipshash{$installnic}){
|
||||
@ -1283,6 +1277,14 @@ sub gen_new_hostinfo_string{
|
||||
return 0, "There are no more IP addresses available in the static network range for interface $installnic";
|
||||
}
|
||||
}
|
||||
|
||||
my $nicips = $installnic.":".$hostinfo_dict{$item}{"ip"};
|
||||
foreach(keys %ipshash){
|
||||
if ( $_ eq $installnic ) {next;}
|
||||
$nicips = "$_:$ipshash{$_},$nicips";
|
||||
}
|
||||
$hostinfo_dict{$item}{"nicips"} = $nicips;
|
||||
|
||||
$hostinfo_dict{$item}{"objtype"} = "node";
|
||||
$hostinfo_dict{$item}{"groups"} = "__Managed";
|
||||
if (exists $args_dict{'networkprofile'}){$hostinfo_dict{$item}{"groups"} .= ",".$args_dict{'networkprofile'}}
|
||||
|
Loading…
Reference in New Issue
Block a user