fix #215702 nodeimport can import the same host info file for switch auto discovery twice or more

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@16405 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
qyin 2013-05-23 07:59:27 +00:00
parent 7f3056c15f
commit e6fedc6556
2 changed files with 36 additions and 0 deletions

View File

@ -543,6 +543,29 @@ sub get_allnode_singleattrib_hash
#-------------------------------------------------------------------------------
=head3 get_db_swtichports
Description : Get all records of switch config from a table, then return a string list.
Arguments : $tabname - the table name.
Returns : Reference of the records hash.
=cut
#-------------------------------------------------------------------------------
sub get_db_switchports
{
my $class = shift;
my $table = xCAT::Table->new("switch");
my @attribs = ("switch", "port");
my @entries = $table->getAllAttribs(@attribs);
my %allrecords;
foreach (@entries)
{
$allrecords{$_->{'switch'} . "_" . $_->{'port'}} = 0;
}
return \%allrecords;
}
#-------------------------------------------------------------------------------
=head3 is_discover_started
Description : Judge whether profiled nodes discovering is running or not.
Arguments : NA

View File

@ -37,6 +37,7 @@ my %allnicips;
my %allracks;
my %allchassis;
my %allswitches;
my %all_switchports;
# The array of all chassis which is special CMM
my %allcmmchassis;
@ -368,6 +369,10 @@ Usage:
$recordsref = xCAT::ProfiledNodeUtils->get_allnode_singleattrib_hash('switches', 'switch');
%allswitches = %$recordsref;
# Get all switches_switchport
$recordsref = xCAT::ProfiledNodeUtils->get_db_switchports();
%all_switchports = %$recordsref;
# MAC records looks like: "01:02:03:04:05:0E!node5│01:02:03:05:0F!node6-eth1". We want to get the real mac addres.
foreach (keys %allmacs){
my @hostentries = split(/\|/, $_);
@ -1965,6 +1970,14 @@ sub validate_node_entry{
if (!($node_entry{$_} =~ /^\d+$/)){
$errmsg .= "Specified port $node_entry{$_} is invalid\n";
}
# now, we need to check "swith_switchport" string list to avoid duplicate config
my $switch_port = $node_entry{'switch'} . "_" . $node_entry{$_};
if (exists $all_switchports{$switch_port}){
$errmsg .= "Specified switch port $node_entry{$_} already exists in the database or in the nodeinfo file. You must use a new switch port.\n";
}else{
# after checking, add this one into all_switchports
$all_switchports{$switch_port} = 0;
}
}elsif ($_ eq "rack"){
if (! exists $allracks{$node_entry{$_}}){
$errmsg .= "Specified rack $node_entry{$_} is not defined\n";