#! /usr/bin/perl # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # # # Licensed Materials - Property of IBM # # (C) COPYRIGHT International Business Machines Corp. 2009,2019 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)97 1.6 src/rsct/caa/cmds/ct_caa_scaffold_net_intf_info.perl, topology.services, rsct_rady, rady2035a 4/8/10 16:04:14 # # This script parses /usr/sbin/nodeq output and outputs net intf info suitable # for digestion by libct_caa's simulation parsing functions. It is currently # limited to getting just one cluster's worth of info from /usr/sbin/nodeq, # because at the time of writing it wasn't clear whether /usr/bin/nodeq # could deal with more than one cluster and, if it could, what its # output would look like. # # # NOTE: At the end of this file lives "here documents" illustrating # the state of nodeq command output at various stages of parsing # history. # # # On 04/08/2010 it was learned the nodeq command was sunset in favor of # "lscluster -m". Therefore, all discussion of and references to nodeq in # this script should be taken as applying equally to "lscluster -m". # sub hex_to_dotted_decimal { my $hex_value = shift; # # Assumes this format for $hex_value: 0xNNNNNNNN # return sprintf("%u.%u.%u.%u", hex(substr($hex_value, 2, 2)), hex(substr($hex_value, 4, 2)), hex(substr($hex_value, 6, 2)), hex(substr($hex_value, 8, 2))); } my $cluster_name; my $node_name; my $node_number; my @output; my $found_cluster_name; if (-e "/usr/sbin/nodeq") { open INFO, "/usr/sbin/nodeq 2>/dev/null |"; } else { open INFO, "/usr/sbin/lscluster -m 2>/dev/null |"; } while () { chomp; # # Remove trailing whitespace. # $_ =~ s/\s*$//; if (/Node name: (.*)$/) { $node_name = $1; } elsif (/Cluster shorthand id for node: (.*)$/ || /Cluster number for node: (.*)$/) { $node_number = $1; } elsif (/Cluster names & cluster uuids:$/ || /Cluster names:$/ || /Cluster names : cluster uuids: cluster type$/) { # # Assume the next line is the one and only cluster name. # $_ = ; chomp; if (! $found_cluster_name) { # # Add the cluster name and set the number of netintf's slot # (slot 1) in the array to 0 (because it's incremented below). # ($cluster_name, $cluster_uuid, $junk) = split " "; $cluster_name =~ s/\s//g; push @output, $cluster_name; push @output, 0; # # Remember that we already have the cluster name. # $found_cluster_name = 1; } # # Get the interface info. # # # One day, clcmd no longer worked properly with the -n flag specified.... # open IFCONFIG, # "/usr/sbin/clcmd -n $cluster_name -m $node_name -- ifconfig -a |"; "/usr/sbin/clcmd -m $node_name -- ifconfig -a |"; while () { if (/^(.*): flags=.*<(.*),BROADCAST.*$/) { $net_intf_name = $1; $net_intf_status = $2; if ("UP" eq $net_intf_status) { $net_intf_status = 1; } else { $net_intf_status = 0; } $_ = ; $_ =~ /^.*inet (.*) netmask (.*) broadcast .*$/; if ($1 ne "127.0.0.1") { # # Add the node and net_intf info. # push @output, $node_number; push @output, $net_intf_name; push @output, $1; push @output, hex_to_dotted_decimal($2); push @output, 0; # "flags" field push @output, $net_intf_status; $output[1] = $output[1] + 1; } } } close IFCONFIG; } } close INFO; foreach my $line (@output) { printf "$line\n"; } exit 0; # # End of main. # # # "Here documents" showing the nodeq command output which parsing is # based upon. # my $nodeq_output_1 = <<'EOF'; [e95n2sq09][/tmp/bubbly]> nodeq Calling node query for all nodes Node query number of nodes examined: 3 Node name: e95n2sq07.ppd.pok.ibm.com Cluster number for node: 1 State of node: UP Network Interface used for last communication: en0 Smoothed rtt to node: 7 Mean Deviation in network rtt to node: 3 Number of clusters node is a member in: 1 Cluster names: CAYENNE ------------------------------ Node name: e95n2sq08.ppd.pok.ibm.com Cluster number for node: 2 State of node: UP Network Interface used for last communication: en0 Smoothed rtt to node: 7 Mean Deviation in network rtt to node: 3 Number of clusters node is a member in: 1 Cluster names: CAYENNE ------------------------------ Node name: e95n2sq09.ppd.pok.ibm.com Cluster number for node: 3 State of node: UP Network Interface used for last communication: Smoothed rtt to node: 0 Mean Deviation in network rtt to node: 0 Number of clusters node is a member in: 1 Cluster names: CAYENNE EOF my $nodeq_output_2 = <<'EOF'; [e95n1sq10][/tmp/bubbly]> nodeq Calling node query for all nodes Node query number of nodes examined: 3 Node name: e95n1sq10.ppd.pok.ibm.com Cluster shorthand id for node: 1 uuid for node: 1415114950 State of node: UP Network Interface used for last communication: Smoothed rtt to node: 0 Mean Deviation in network rtt to node: 0 Number of clusters node is a member in: 1 Cluster names & cluster uuids: CAA 1584323961 ------------------------------ Node name: e95n1sq11.ppd.pok.ibm.com Cluster shorthand id for node: 2 uuid for node: 455574125 State of node: UP Network Interface used for last communication: en0 Smoothed rtt to node: 7 Mean Deviation in network rtt to node: 3 Number of clusters node is a member in: 1 Cluster names & cluster uuids: CAA 1584323961 ------------------------------ Node name: e95n1sq12.ppd.pok.ibm.com Cluster shorthand id for node: 3 uuid for node: 1055117320 State of node: UP Network Interface used for last communication: en0 Smoothed rtt to node: 7 Mean Deviation in network rtt to node: 3 Number of clusters node is a member in: 1 Cluster names & cluster uuids: CAA 1584323961 EOF