mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 03:12:30 +00:00 
			
		
		
		
	Merge pull request #3367 from cxhong/3305
Add Vlan and MTU to switch_macmap output
This commit is contained in:
		| @@ -356,6 +356,8 @@ sub dump_mac_info { | ||||
|                         } | ||||
|                     } | ||||
|                     @{ $ret{$switch}->{$snmpportname}->{MACaddress} } = @{ $self->{macinfo}->{$switch}->{$snmpportname} }; | ||||
|                     @{ $ret{$switch}->{$snmpportname}->{Vlanid} } = @{ $self->{vlaninfo}->{$switch}->{$snmpportname} }; | ||||
|                     @{ $ret{$switch}->{$snmpportname}->{Mtu} } = @{ $self->{mtuinfo}->{$switch}->{$snmpportname} };  | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| @@ -720,6 +722,12 @@ sub refresh_switch { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     # get mtu | ||||
|     my $iftomtumap = walkoid($session, '.1.3.6.1.2.1.2.2.1.4', silentfail => 1, verbose => $self->{show_verbose_info}, switch => $switch, callback => $self->{callback}); | ||||
|     unless (defined($iftomtumap)) { | ||||
|         xCAT::MsgUtils->message("I", "MTU information is not availabe for this switch $switch"); | ||||
|     } | ||||
|  | ||||
|     #Above is valid without community string indexing, on cisco, we need it on the next one and onward | ||||
|     my $iftovlanmap = walkoid($session, '.1.3.6.1.4.1.9.9.68.1.2.2.1.2', silentfail => 1, verbose => $self->{show_verbose_info}, switch => $switch, callback => $self->{callback}); #use cisco vlan membership mib to ascertain vlan | ||||
|     my $trunktovlanmap = walkoid($session, '.1.3.6.1.4.1.9.9.46.1.6.1.1.5', silentfail => 1, verbose => $self->{show_verbose_info}, switch => $switch, callback => $self->{callback}); #for trunk ports, we are interested in the native vlan, so we need cisco vtp mib too | ||||
| @@ -783,24 +791,38 @@ sub refresh_switch { | ||||
|             xCAT::MsgUtils->message("S", "Error communicating with " . $session->{DestHost} . ": Unable to get MAC entries via either BRIDGE or Q-BRIDE MIB"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         if (defined($self->{collect_mac_info})) { | ||||
|             my %index_to_mac = (); | ||||
|             my %index_to_vlan = (); | ||||
|             foreach (keys %$mactoindexmap) { | ||||
|                 my $index     = $mactoindexmap->{$_}; | ||||
|                 my @tmp       = split /\./, $_; | ||||
|                 my $vlan      = @tmp[0]; | ||||
|                 my @mac       = @tmp[ -6 .. -1 ]; | ||||
|                 my $macstring = sprintf("%02x:%02x:%02x:%02x:%02x:%02x", @mac); | ||||
|                 push @{ $index_to_mac{$index} }, $macstring; | ||||
|                 push @{ $index_to_vlan{$index} }, $vlan;     | ||||
|             } | ||||
|             foreach my $boid (keys %$bridgetoifmap) { | ||||
|                 my $port_index = $boid; | ||||
|                 my $port_name  = $namemap->{ $bridgetoifmap->{$port_index} }; | ||||
|                 my $mtu  = $iftomtumap->{ $bridgetoifmap->{$port_index} }; | ||||
|                 if (defined($index_to_mac{$port_index})) { | ||||
|                     push @{ $self->{macinfo}->{$switch}->{$port_name} }, @{ $index_to_mac{$port_index} }; | ||||
|                 } | ||||
|                 else { | ||||
|                     $self->{macinfo}->{$switch}->{$port_name}->[0] = ''; | ||||
|                 } | ||||
|  | ||||
|                 if (defined($index_to_vlan{$port_index})) { | ||||
|                     push @{ $self->{vlaninfo}->{$switch}->{$port_name} }, @{ $index_to_vlan{$port_index} }; | ||||
|                 } | ||||
|                 else { | ||||
|                     $self->{vlaninfo}->{$switch}->{$port_name}->[0] = ''; | ||||
|                 } | ||||
|                 push @{ $self->{mtuinfo}->{$switch}->{$port_name} } , $mtu; | ||||
|  | ||||
|             } | ||||
|             return; | ||||
|         } | ||||
|   | ||||
| @@ -226,16 +226,16 @@ sub process_request { | ||||
|                 } | ||||
|                 foreach my $portname (keys %{ $macinfo->{$switch} }) { | ||||
|                     if (length($portname) > $port_name_length) { | ||||
|                         $port_name_length = length($portname); | ||||
|                         $port_name_length = length($portname) + 10; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             my $format = "%-" . $switch_name_length . "s  %-" . $port_name_length . "s  %-18s  %s"; | ||||
|             my $format = "%-" . $switch_name_length . "s  %-" . $port_name_length . "s  %-26s  %s"; | ||||
|             my %failed_switches = (); | ||||
|             my $header = sprintf($format, "Switch", "Port", "MAC address", "Node"); | ||||
|             my $header = sprintf($format, "Switch", "Port(MTU)", "MAC address(VLAN)", "Node"); | ||||
|             if (!defined($req->{opt}->{check}) and $port_name_length) { | ||||
|                 $cb->({ data => $header }); | ||||
|                 $cb->({ data => "------------------------------------------------------------------" }) | ||||
|                 $cb->({ data => "--------------------------------------------------------------------------------------" }) | ||||
|             } | ||||
|             foreach my $switch (keys %$macinfo) { | ||||
|                 if (defined($macinfo->{$switch}->{ErrorStr})) { | ||||
| @@ -256,12 +256,37 @@ sub process_request { | ||||
|                     if (defined($macinfo->{$switch}->{$port}->{Node})) { | ||||
|                         $node = $macinfo->{$switch}->{$port}->{Node}; | ||||
|                     } | ||||
|  | ||||
|                     my $mtu = ''; | ||||
|                     my $vlanid = ''; | ||||
|                     my @vlans = (); | ||||
|                     if (defined($macinfo->{$switch}->{$port}->{Vlanid})) { | ||||
|                         @vlans = @{ $macinfo->{$switch}->{$port}->{Vlanid} }; | ||||
|                     } | ||||
|  | ||||
|                     my @macarrary = (); | ||||
|                     if (defined($macinfo->{$switch}->{$port}->{MACaddress})) { | ||||
|                         @macarray = @{ $macinfo->{$switch}->{$port}->{MACaddress} }; | ||||
|                         my $ind = 0; | ||||
|                         foreach (@macarray) { | ||||
|                             my $data = sprintf($format, $switch, $port, ($_ ne '') ? $_ : '       N/A', $node); | ||||
|                             my $mac = $_; | ||||
|                             $vlanid = $vlans[$ind]; | ||||
|                             my $mac_vlan; | ||||
|                             if (!$mac) { | ||||
|                                 $mac_vlan="N/A"; | ||||
|                             } elsif ($vlanid) { | ||||
|                                 $mac_vlan = "$mac($vlanid)";  | ||||
|                             } else { | ||||
|                                 $mac_vlan = $mac; | ||||
|                             } | ||||
|                             my $port_mtu = $port; | ||||
|                             if (defined($macinfo->{$switch}->{$port}->{Mtu})) { | ||||
|                                 $mtu = $macinfo->{$switch}->{$port}->{Mtu}->[0]; | ||||
|                                 $port_mtu = "$port($mtu)"; | ||||
|                             } | ||||
|                             my $data = sprintf($format, $switch, $port_mtu, $mac_vlan, $node); | ||||
|                             $cb->({ data => $data }); | ||||
|                             $ind++; | ||||
|  | ||||
|                             #$cb->({node=>[{name=>$switch,data=>$data}]}); | ||||
|                         } | ||||
| @@ -269,7 +294,7 @@ sub process_request { | ||||
|                 } | ||||
|             } | ||||
|             if (!defined($req->{opt}->{check}) and $port_name_length) { | ||||
|                 $cb->({ data => "------------------------------------------------------------------" }) | ||||
|                 $cb->({ data => "--------------------------------------------------------------------------------------" }) | ||||
|             } | ||||
|             foreach (keys %failed_switches) { | ||||
|                 $cb->({ node => [ { name => $_, error => [ $failed_switches{$_} ], errorcode => 1 } ] }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user