blob: 43cc753588f461481c2696e3cac3aa4e3b6b5a2b [file] [log] [blame]
Deepak Kodihalli9f3e1c12017-02-19 23:39:15 -06001#! /usr/bin/perl
2use strict;
3use warnings;
4
5
6use mrw::Targets;
7use mrw::Inventory;
8use mrw::Util;
9use Getopt::Long;
10use YAML::Tiny qw(LoadFile);
11
12
13my $mrwFile = "";
14my $outFile = "";
15my $configFile = "";
16
17
18GetOptions(
19"m=s" => \$mrwFile,
20"c=s" => \$configFile,
21"o=s" => \$outFile,
22)
23or printUsage();
24
25
26if (($mrwFile eq "") or ($configFile eq "") or ($outFile eq ""))
27{
28 printUsage();
29}
30
31
32# Load system MRW
33my $targets = Targets->new;
34$targets->loadXML($mrwFile);
35my @inventory = Inventory::getInventory($targets);
36
37
38# Parse config YAML
39my $targetItems = LoadFile($configFile);
40
41
42# Targets we're interested in, from the config YAML
43my @targetNames = keys %{$targetItems};
44my %targetHash;
45@targetHash{@targetNames} = ();
46
47
48# Target Type : Target inventory path
49my %defaultPaths = (
50 "ETHERNET",
51 Util::getObmcName(
52 \@inventory,
53 Util::getBMCTarget($targets))."/ethernet"
54);
55
56
57open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!";
58# Retrieve OBMC path of targets we're interested in
59for my $item (@inventory) {
60 my $targetType = "";
61 my $path = "";
62
63 if (!$targets->isBadAttribute($item->{TARGET}, "TYPE")) {
64 $targetType = $targets->getAttribute($item->{TARGET}, "TYPE");
65 }
66 next if (not exists $targetItems->{$targetType});
67
68 writeOutput($targetType,
69 $item,
70 $targetItems);
71 delete($targetHash{$targetType});
72}
73writeRemaining($targetItems);
74close $fh;
75
76
77sub writeRemaining
78{
79 my ($yamlDict) = @_;
80 for my $type (keys %targetHash)
81 {
82 print $fh $defaultPaths{$type}.":";
83 print $fh "\n";
84 while (my ($interface,$propertyMap) = each %{$yamlDict->{$type}})
85 {
86 print $fh " ".$interface.":";
87 print $fh "\n";
88 while (my ($property,$value) = each %{$propertyMap})
89 {
90 $value = "'".$value."'";
91 print $fh " ".$property.": ".$value;
92 print $fh "\n";
93 }
94 }
95 }
96}
97
98
99sub writeOutput
100{
101 my ($type, $item, $yamlDict) = @_;
102 print $fh $item->{OBMC_NAME}.":";
103 print $fh "\n";
104 while (my ($interface,$propertyMap) = each %{$yamlDict->{$type}})
105 {
106 print $fh " ".$interface.":";
107 print $fh "\n";
108 while (my ($property,$value) = each %{$propertyMap})
109 {
110 $value = getValue($item, $property, $value);
111 print $fh " ".$property.": ".$value;
112 print $fh "\n";
113 }
114 }
115}
116
117
118sub getValue
119{
120 my ($item, $property, $value) = @_;
121 $value = "'".$value."'";
122
123 if ($property eq "FieldReplaceable")
124 {
125 $value = "'false'";
126 if (!$targets->isBadAttribute($item->{TARGET}, "RU_TYPE"))
127 {
128 my $ruType = $targets->getAttribute($item->{TARGET}, "RU_TYPE");
129 if (($ruType eq "FRU") || ($ruType eq "CRU"))
130 {
131 $value = "'true'";
132 }
133 }
134 }
135
136 return $value;
137}
138
139
140sub printUsage
141{
142 print "
143 $0 -m [MRW file] -c [Config yaml] -o [Output filename]\n";
144 exit(1);
145}