2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-30 01:26:38 +00:00

Merge pull request #1802 from cxhong/macmap

Checking nodetype to distinguish between node/switch discovery
This commit is contained in:
zet809 2016-09-12 20:46:29 +08:00 committed by GitHub
commit 6bb622903f
2 changed files with 24 additions and 2 deletions

View File

@ -288,6 +288,10 @@ sub dump_mac_info {
$self->{callback} = $callback;
}
my $community = "public";
my @snmpcs = xCAT::TableUtils->get_site_attribute("snmpc");
my $tmp = $snmpcs[0];
if (defined($tmp)) { $community = $tmp }
my $dump_all_switches = 0;
my %switches_to_dump = ();
if (!defined($noderange)) {
@ -366,6 +370,7 @@ sub find_mac {
my $self = shift;
my $mac = shift;
my $cachedonly = shift;
my $discover_switch=shift;
# For now HARDCODE (TODO, configurable?) a cache as stale after five minutes
# Also, if things are changed in the config, our cache could be wrong,
@ -390,7 +395,7 @@ sub find_mac {
#If requesting a cache only check or the cache is a mere 20 seconds old
#don't bother querying switches
if ($cachedonly or ($self->{timestamp} > (time() - 20))) { return undef; }
$self->refresh_table; #not cached or stale cache, refresh
$self->refresh_table($discover_switch); #not cached or stale cache, refresh
if ($self->{mactable}->{ lc($mac) }) {
return $self->{mactable}->{ lc($mac) };
}
@ -426,6 +431,7 @@ sub fill_switchparms {
sub refresh_table {
my $self = shift;
my $discover_switch = shift;
my $curswitch;
$self->{mactable} = {};
$self->{switchtab} = xCAT::Table->new('switch', -create => 1);
@ -469,7 +475,23 @@ sub refresh_table {
#Build hash of switch port names per switch
$self->{switches} = {};
#get nodetype from nodetype table, build a temp hash
my $typehash;
my $ntable = xCAT::Table->new('nodetype');
if ($ntable) {
$typehash = $ntable->getAllNodeAttribs(['node','nodetype'], 1);
}
foreach my $entry (@entries) {
# if we are doing switch discovery and the node is not a switch, skip
# if we are NOT doing switch discovery, and the node is a switch, skip
my $ntype = $typehash->{$entry->{node}}->[0]->{nodetype};
if ( (($discover_switch) and ( $ntype ne "switch"))
or ( !($discover_switch) and ( $ntype eq "switch")) ){
xCAT::MsgUtils->message("S", "refresh_table: skip $entry->{node} and $entry->{switch}");
next;
}
if (defined($entry->{switch}) and $entry->{switch} ne "" and defined($entry->{port}) and $entry->{port} ne "") {
if (!$self->{switches}->{ $entry->{switch} }->{ $entry->{port} })

View File

@ -1383,7 +1383,7 @@ sub switchsetup {
# issue makehosts so we can use xdsh
my $dswitch = get_hostname($outhash->{$mac}->{name}, $ip);
my $node = $macmap->find_mac($mac,0);
my $node = $macmap->find_mac($mac,0,1);
if (!$node) {
send_msg($request, 0, "NO predefined switch matched this switch $dswitch with ip address $ip and mac address $mac");
next;