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