Deepak Kodihalli | 6225e93 | 2017-02-07 12:14:55 -0600 | [diff] [blame] | 1 | #! /usr/bin/perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | |
| 5 | use mrw::Targets; |
| 6 | use mrw::Inventory; |
| 7 | use mrw::Util; |
| 8 | use Getopt::Long; |
| 9 | use YAML::Tiny qw(LoadFile); |
| 10 | |
| 11 | my $mrwFile = ""; |
| 12 | my $outFile = ""; |
| 13 | my $configFile = ""; |
| 14 | |
| 15 | GetOptions( |
| 16 | "m=s" => \$mrwFile, |
| 17 | "c=s" => \$configFile, |
| 18 | "o=s" => \$outFile, |
| 19 | ) |
| 20 | or printUsage(); |
| 21 | |
| 22 | if (($mrwFile eq "") or ($configFile eq "") or ($outFile eq "")) |
| 23 | { |
| 24 | printUsage(); |
| 25 | } |
| 26 | |
| 27 | # Load system MRW |
| 28 | my $targets = Targets->new; |
| 29 | $targets->loadXML($mrwFile); |
| 30 | my @inventory = Inventory::getInventory($targets); |
| 31 | |
| 32 | # Target Type : Target inventory path |
| 33 | my %defaultPaths = ( |
| 34 | "ETHERNET", |
| 35 | Util::getObmcName( |
| 36 | \@inventory, |
| 37 | Util::getBMCTarget($targets))."/ethernet" |
| 38 | ); |
| 39 | |
| 40 | # Parse config YAML |
| 41 | my $targetItems = LoadFile($configFile); |
| 42 | |
| 43 | # Targets we're interested in, from the config YAML |
| 44 | my @targetNames = keys %{$targetItems}; |
| 45 | my %targetHash; |
| 46 | @targetHash{@targetNames} = (); |
| 47 | my @targetTypes; |
| 48 | my @paths; |
| 49 | |
| 50 | # Retrieve OBMC path of targets we're interested in |
| 51 | for my $item (@inventory) { |
| 52 | my $targetType = ""; |
| 53 | my $path = ""; |
| 54 | |
| 55 | if (!$targets->isBadAttribute($item->{TARGET}, "TYPE")) { |
| 56 | $targetType = $targets->getAttribute($item->{TARGET}, "TYPE"); |
| 57 | } |
| 58 | next if (not exists $targetHash{$targetType}); |
| 59 | |
| 60 | push @targetTypes, $targetType; |
| 61 | push @paths, $item->{OBMC_NAME}; |
| 62 | delete($targetHash{$targetType}); |
| 63 | } |
| 64 | |
| 65 | for my $type (keys %targetHash) |
| 66 | { |
| 67 | # One or more targets wasn't present in the inventory |
| 68 | push @targetTypes, $type; |
| 69 | push @paths, $defaultPaths{$type}; |
| 70 | } |
| 71 | |
| 72 | open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!"; |
| 73 | print $fh "FRUS=".join ',',@targetTypes; |
| 74 | print $fh "\n"; |
| 75 | print $fh "PATHS=".join ',',@paths; |
| 76 | close $fh; |
| 77 | |
| 78 | sub printUsage |
| 79 | { |
| 80 | print " |
| 81 | $0 -m [MRW file] -c [Config yaml] -o [Output filename]\n"; |
| 82 | exit(1); |
| 83 | } |