diff options
author | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-07-21 17:03:18 +0530 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-07-27 17:43:01 +0000 |
commit | 7b93a1626d0475c38c47d3995c038a804c323966 (patch) | |
tree | 87c101d8a731980c7cc7d6928a05aeb8e712f827 | |
parent | e36476e232dcb48af0e089893000761c1bd61d95 (diff) | |
download | phosphor-mrw-tools-7b93a1626d0475c38c47d3995c038a804c323966.tar.gz phosphor-mrw-tools-7b93a1626d0475c38c47d3995c038a804c323966.zip |
Parse MRW and generate OCC to its sensor ID mapping
Change-Id: If96240e12f42c87aa624bfda3ec9b7367272e2f5
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
-rwxr-xr-x | gen_occ_map.pl | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/gen_occ_map.pl b/gen_occ_map.pl new file mode 100755 index 0000000..0aba66a --- /dev/null +++ b/gen_occ_map.pl @@ -0,0 +1,126 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use mrw::Targets; # Set of APIs allowing access to parsed ServerWiz2 XML output +use mrw::Inventory; # To get list of Inventory targets +use Getopt::Long; # For parsing command line arguments +use POSIX; # For checking if something is a digit + +# Globals +my $force = 0; +my $serverwizFile = ""; +my $debug = 0; +my $outputFile = ""; +my $verbose = 0; + +# Command line argument parsing +GetOptions( +"f" => \$force, # numeric +"i=s" => \$serverwizFile, # string +"o=s" => \$outputFile, # string +"d" => \$debug, +"v" => \$verbose, +) +or printUsage(); + +if (($serverwizFile eq "") or ($outputFile eq "")) +{ + printUsage(); +} + +# Hashmap of all the OCCs and their sensor IDs +my %occHash; + +# API used to access parsed XML data +my $targetObj = Targets->new; +if($verbose == 1) +{ + $targetObj->{debug} = 1; +} + +if($force == 1) +{ + $targetObj->{force} = 1; +} + +$targetObj->loadXML($serverwizFile); +print "Loaded MRW XML: $serverwizFile \n"; + +# Process all the targets in the XML +foreach my $target (sort keys %{$targetObj->getAllTargets()}) +{ + # Only take the instances having 'OCC" as TYPE + if ("OCC" ne $targetObj->getAttribute($target, "TYPE")) + { + next; + } + + # OCC instance and sensor ID to insert into output file + my $instance = ""; + my $sensor = ""; + + # Now that we are in OCC target instance, get the instance number + $instance = $targetObj->getAttribute($target, "IPMI_INSTANCE"); + + # Each OCC would have occ_active_sensor child that would have + # more information, such as Sensor ID. + # This would be an array of children targets + my $children = $targetObj->getTargetChildren($target); + + for my $child (@{$children}) + { + $sensor = $targetObj->getAttribute($child, "IPMI_SENSOR_ID"); + } + + # Populate a hashmap with OCC and its sensor ID + $occHash{$instance} = $sensor; + +} # All the targets + +# Generate the yaml file +generateYamlFile(); +##------------------------------------END OF MAIN----------------------- + +sub generateYamlFile +{ + my $fileName = $outputFile; + open(my $fh, '>', $fileName) or die "Could not open file '$fileName' $!"; + + foreach my $instance (sort keys %occHash) + { + # If the instance is not a digit, then error + isdigit($instance) or die "'$instance' does not have instance number"; + + # YAML with list of {Instance:SensorID} dictionary + print $fh "- Instance: "; + print $fh "$instance\n"; + print $fh " SensorID: "; + print $fh "$occHash{$instance}\n"; + } + close $fh; +} + +# Helper function to put debug statements. +sub printDebug +{ + my $str = shift; + print "DEBUG: ", $str, "\n" if $debug; +} + +# Usage +sub printUsage +{ + print " + $0 -i [XML filename] -o [Output filename] [OPTIONS] +Options: + -f = force output file creation even when errors + -d = debug mode + -v = verbose mode - for verbose o/p from Targets.pm + +PS: mrw::Targets can be found in https://github.com/open-power/serverwiz/ + mrw::Inventory can be found in https://github.com/openbmc/phosphor-mrw-tools/ + \n"; + exit(1); +} +#------------------------------------END OF SUB----------------------- |