gen_ipmi_fru.pl : Fetch FRU information from MRW

This commit serves as a building block since the script can now just
print certain attributes (see output example below) for FRU elements
defined in the MRW.

Typically, FRUs of interest to IPMI will have a non-zero FRU id
defined.

Output example:
FRUID => 1, FRUType => SYS, ObjectPath => /system
FRUID => 2, FRUType => NODE, ObjectPath => /system/chassis

Change-Id: I3f27f905b2a366277e8a6120142c3fb136a44ad5
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/gen_ipmi_fru.pl b/gen_ipmi_fru.pl
new file mode 100755
index 0000000..34b19ee
--- /dev/null
+++ b/gen_ipmi_fru.pl
@@ -0,0 +1,71 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+
+use mrw::Targets;
+use mrw::Inventory;
+use Getopt::Long; # For parsing command line arguments
+use YAML::XS 'LoadFile'; # For loading and reading of YAML file
+
+# Globals
+my $serverwizFile  = "";
+my $debug           = 0;
+
+# Command line argument parsing
+GetOptions(
+"i=s" => \$serverwizFile,    # string
+"d"   => \$debug,
+)
+or printUsage();
+
+if (($serverwizFile eq ""))
+{
+    printUsage();
+}
+
+my $targetObj = Targets->new;
+$targetObj->loadXML($serverwizFile);
+
+#open the mrw xml Fetch the FRU id,type,object path from the mrw.
+
+my @inventory = Inventory::getInventory($targetObj);
+for my $item (@inventory) {
+    my $isFru = 0, my $fruID = 0, my $fruType = "";
+    my $isChildFru = 0;
+
+    #Fetch the fruid.
+    if (!$targetObj->isBadAttribute($item->{TARGET}, "FRU_ID")) {
+        $fruID = $targetObj->getAttribute($item->{TARGET}, "FRU_ID");
+        $isFru = 1;
+    }
+
+    #Fech the fru type.
+    if (!$targetObj->isBadAttribute($item->{TARGET}, "TYPE")) {
+        $fruType = $targetObj->getAttribute($item->{TARGET}, "TYPE");
+    }
+
+    #skip those entries whose type is NA and is not fru.
+    next if ( $fruType eq 'NA' or not($isFru) or $fruType eq 'BMC');
+
+    printDebug ("FRUID => $fruID, FRUType => $fruType, ObjectPath => $item->{OBMC_NAME}");
+
+}
+#------------------------------------END OF MAIN-----------------------
+
+# Usage
+sub printUsage
+{
+    print "
+    $0 -i [MRW filename] [OPTIONS]
+Options:
+    -d = debug mode
+        \n";
+    exit(1);
+}
+
+# Helper function to put debug statements.
+sub printDebug
+{
+    my $str = shift;
+    print "DEBUG: ", $str, "\n" if $debug;
+}