Ratan Gupta | fa70dc9 | 2017-01-17 00:09:04 +0530 | [diff] [blame^] | 1 | #! /usr/bin/perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | |
| 5 | use mrw::Targets; |
| 6 | use mrw::Inventory; |
| 7 | use Getopt::Long; # For parsing command line arguments |
| 8 | use YAML::XS 'LoadFile'; # For loading and reading of YAML file |
| 9 | |
| 10 | # Globals |
| 11 | my $serverwizFile = ""; |
| 12 | my $debug = 0; |
| 13 | |
| 14 | # Command line argument parsing |
| 15 | GetOptions( |
| 16 | "i=s" => \$serverwizFile, # string |
| 17 | "d" => \$debug, |
| 18 | ) |
| 19 | or printUsage(); |
| 20 | |
| 21 | if (($serverwizFile eq "")) |
| 22 | { |
| 23 | printUsage(); |
| 24 | } |
| 25 | |
| 26 | my $targetObj = Targets->new; |
| 27 | $targetObj->loadXML($serverwizFile); |
| 28 | |
| 29 | #open the mrw xml Fetch the FRU id,type,object path from the mrw. |
| 30 | |
| 31 | my @inventory = Inventory::getInventory($targetObj); |
| 32 | for my $item (@inventory) { |
| 33 | my $isFru = 0, my $fruID = 0, my $fruType = ""; |
| 34 | my $isChildFru = 0; |
| 35 | |
| 36 | #Fetch the fruid. |
| 37 | if (!$targetObj->isBadAttribute($item->{TARGET}, "FRU_ID")) { |
| 38 | $fruID = $targetObj->getAttribute($item->{TARGET}, "FRU_ID"); |
| 39 | $isFru = 1; |
| 40 | } |
| 41 | |
| 42 | #Fech the fru type. |
| 43 | if (!$targetObj->isBadAttribute($item->{TARGET}, "TYPE")) { |
| 44 | $fruType = $targetObj->getAttribute($item->{TARGET}, "TYPE"); |
| 45 | } |
| 46 | |
| 47 | #skip those entries whose type is NA and is not fru. |
| 48 | next if ( $fruType eq 'NA' or not($isFru) or $fruType eq 'BMC'); |
| 49 | |
| 50 | printDebug ("FRUID => $fruID, FRUType => $fruType, ObjectPath => $item->{OBMC_NAME}"); |
| 51 | |
| 52 | } |
| 53 | #------------------------------------END OF MAIN----------------------- |
| 54 | |
| 55 | # Usage |
| 56 | sub printUsage |
| 57 | { |
| 58 | print " |
| 59 | $0 -i [MRW filename] [OPTIONS] |
| 60 | Options: |
| 61 | -d = debug mode |
| 62 | \n"; |
| 63 | exit(1); |
| 64 | } |
| 65 | |
| 66 | # Helper function to put debug statements. |
| 67 | sub printDebug |
| 68 | { |
| 69 | my $str = shift; |
| 70 | print "DEBUG: ", $str, "\n" if $debug; |
| 71 | } |