diff --git a/perl-xCAT/xCAT/ProfiledNodeUtils.pm b/perl-xCAT/xCAT/ProfiledNodeUtils.pm index 753b65f5a..c3d9a6d47 100644 --- a/perl-xCAT/xCAT/ProfiledNodeUtils.pm +++ b/perl-xCAT/xCAT/ProfiledNodeUtils.pm @@ -184,7 +184,10 @@ sub get_hostname_format_type{ $type = "rack"; } elsif ($nidx >= 0){ $type = "numric"; + } else{ + $type = "unknown"; } + return $type; } @@ -296,7 +299,7 @@ sub get_nodes_nic_attrs{ sub get_netprofile_bmcnet{ my ($class, $netprofilename) = @_; - my $netprofile_nicshash_ref = xCAT::ProfiledNodeUtils->get_netprofile_nic_attrs($netprofilename); + my $netprofile_nicshash_ref = xCAT::ProfiledNodeUtils->get_nodes_nic_attrs($netprofilename)->{$netprofilename}; my %netprofile_nicshash = %$netprofile_nicshash_ref; if (exists $netprofile_nicshash{'bmc'}{"network"}){ return $netprofile_nicshash{'bmc'}{"network"} @@ -317,7 +320,7 @@ sub get_netprofile_bmcnet{ sub get_netprofile_provisionnet{ my ($class, $netprofilename) = @_; - my $netprofile_nicshash_ref = xCAT::ProfiledNodeUtils->get_netprofile_nic_attrs($netprofilename); + my $netprofile_nicshash_ref = xCAT::ProfiledNodeUtils->get_nodes_nic_attrs([$netprofilename])->{$netprofilename}; my %netprofile_nicshash = %$netprofile_nicshash_ref; my $restab = xCAT::Table->new('noderes'); my $installnicattr = $restab->getNodeAttribs($netprofilename, ['installnic']); diff --git a/xCAT-server/lib/xcat/plugins/profilednodes.pm b/xCAT-server/lib/xcat/plugins/profilednodes.pm index 6f21b0d54..0f3eb87fd 100644 --- a/xCAT-server/lib/xcat/plugins/profilednodes.pm +++ b/xCAT-server/lib/xcat/plugins/profilednodes.pm @@ -220,6 +220,13 @@ sub nodeimport{ return; } + # validate hostnameformat: + my $nameformattype = xCAT::ProfiledNodeUtils->get_hostname_format_type($args_dict{'hostnameformat'}); + if ($nameformattype eq "unknown"){ + setrsp_errormsg("Invalid hostname format: $args_dict{'hostnameformat'}"); + return; + } + # Get database records: all hostnames, all ips, all racks... xCAT::MsgUtils->message('S', "Getting database records."); my $recordsref = xCAT::ProfiledNodeUtils->get_allnode_singleattrib_hash('nodelist', 'node'); @@ -673,7 +680,7 @@ sub nodediscoverstart{ return; } - my @enabledparams = ('networkprofile', 'hardwareprofile', 'imageprofile', 'hostnameformat', 'rank', 'rack', 'chassis', 'height', 'unit'); + my @enabledparams = ('networkprofile', 'hardwareprofile', 'imageprofile', 'hostnameformat', 'rank', 'rack', 'chassis', 'height', 'unit', 'groups'); foreach my $argname (keys %args_dict){ if (! grep{ $_ eq $argname} @enabledparams){ setrsp_errormsg("Illegal attribute $argname specified."); @@ -688,6 +695,13 @@ sub nodediscoverstart{ } } + # validate hostnameformat: + my $nameformattype = xCAT::ProfiledNodeUtils->get_hostname_format_type($args_dict{'hostnameformat'}); + if ($nameformattype eq "unknown"){ + setrsp_errormsg("Invalid hostname format: $args_dict{'hostnameformat'}"); + return; + } + my $recordsref = xCAT::ProfiledNodeUtils->get_all_rack(1); %allracks = %$recordsref; $recordsref = xCAT::ProfiledNodeUtils->get_all_chassis(1); @@ -747,6 +761,19 @@ sub nodediscoverstart{ return; } + # Make sure provisioning network has a dynamic range. + my $provnet = xCAT::ProfiledNodeUtils->get_netprofile_provisionnet($args_dict{networkprofile}); + if (! $provnet){ + setrsp_errormsg("No provisioning network defined for network profile."); + return; + } + my $networkstab = xCAT::Table->new("networks"); + my $netentry = ($networkstab->getAllAttribsWhere("netname = '$provnet'", 'ALL'))[0]; + if (! $netentry->{'dynamicrange'}){ + setrsp_errormsg("No dynamicrange defined for the provisioning network."); + return; + } + # save discover args into table site. my $valuestr = ""; foreach (keys %args_dict){ @@ -1136,6 +1163,7 @@ sub gen_new_hostinfo_string{ if (exists $args_dict{'networkprofile'}){$hostinfo_dict{$item}{"groups"} .= ",".$args_dict{'networkprofile'}} if (exists $args_dict{'imageprofile'}){$hostinfo_dict{$item}{"groups"} .= ",".$args_dict{'imageprofile'}} if (exists $args_dict{'hardwareprofile'}){$hostinfo_dict{$item}{"groups"} .= ",".$args_dict{'hardwareprofile'}} + if (exists $args_dict{'groups'}){$hostinfo_dict{$item}{"groups"} .= ",".$args_dict{'groups'}} # Update BMC records. if (exists $netprofileattr{"bmc"}){ @@ -1184,6 +1212,8 @@ sub read_and_generate_hostnames{ # Auto generate hostnames for "__hostname__" entries. open(HOSTFILE, $hostfile); my $filecontent = join("", ); + # Convert windows txt file into unix format. + $filecontent =~ s/\cM\cJ/\n/g; while ((index $filecontent, "__hostname__:") >= 0){ my $nexthost = shift @$freehostnamesref; # no more valid hostnames to assign. @@ -1401,7 +1431,7 @@ sub setrsp_invalidrecords # The total number of invalid records. $rsp->{error} = "Some error records detected"; - $rsp->{errorcode} = 1; + $rsp->{errorcode} = 2; $rsp->{invalid_records_num} = scalar @$recordsref; # We write details of invalid records into a file.