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 | { |
Santosh Puranik | 715c97e | 2019-09-19 16:37:54 +0530 | [diff] [blame] | 67 | if(defined $defaultPaths{$type}) |
| 68 | { |
| 69 | # One or more targets wasn't present in the inventory |
| 70 | push @targetTypes, $type; |
| 71 | push @paths, $defaultPaths{$type}; |
| 72 | } |
Deepak Kodihalli | 6225e93 | 2017-02-07 12:14:55 -0600 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!"; |
| 76 | print $fh "FRUS=".join ',',@targetTypes; |
| 77 | print $fh "\n"; |
| 78 | print $fh "PATHS=".join ',',@paths; |
| 79 | close $fh; |
| 80 | |
| 81 | sub printUsage |
| 82 | { |
| 83 | print " |
| 84 | $0 -m [MRW file] -c [Config yaml] -o [Output filename]\n"; |
| 85 | exit(1); |
| 86 | } |