diff --git a/perl-xCAT/xCAT/ProfiledNodeUtils.pm b/perl-xCAT/xCAT/ProfiledNodeUtils.pm index aa6190970..3ce61b9d1 100644 --- a/perl-xCAT/xCAT/ProfiledNodeUtils.pm +++ b/perl-xCAT/xCAT/ProfiledNodeUtils.pm @@ -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 diff --git a/xCAT-server/lib/xcat/plugins/profilednodes.pm b/xCAT-server/lib/xcat/plugins/profilednodes.pm index fa5ee2d47..50309d5a0 100644 --- a/xCAT-server/lib/xcat/plugins/profilednodes.pm +++ b/xCAT-server/lib/xcat/plugins/profilednodes.pm @@ -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";