summaryrefslogtreecommitdiffstats
path: root/gen_fru_properties.pl
blob: 43cc753588f461481c2696e3cac3aa4e3b6b5a2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#! /usr/bin/perl
use strict;
use warnings;


use mrw::Targets;
use mrw::Inventory;
use mrw::Util;
use Getopt::Long;
use YAML::Tiny qw(LoadFile);


my $mrwFile = "";
my $outFile = "";
my $configFile = "";


GetOptions(
"m=s" => \$mrwFile,
"c=s" => \$configFile,
"o=s" => \$outFile,
)
or printUsage();


if (($mrwFile eq "") or ($configFile eq "") or ($outFile eq ""))
{
    printUsage();
}


# Load system MRW
my $targets = Targets->new;
$targets->loadXML($mrwFile);
my @inventory = Inventory::getInventory($targets);


# Parse config YAML
my $targetItems = LoadFile($configFile);


# Targets we're interested in, from the config YAML
my @targetNames = keys %{$targetItems};
my %targetHash;
@targetHash{@targetNames} = ();


# Target Type : Target inventory path
my %defaultPaths = (
    "ETHERNET",
     Util::getObmcName(
         \@inventory,
         Util::getBMCTarget($targets))."/ethernet"
);


open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!";
# Retrieve OBMC path of targets we're interested in
for my $item (@inventory) {
    my $targetType = "";
    my $path = "";

    if (!$targets->isBadAttribute($item->{TARGET}, "TYPE")) {
        $targetType = $targets->getAttribute($item->{TARGET}, "TYPE");
    }
    next if (not exists $targetItems->{$targetType});

    writeOutput($targetType,
                $item,
                $targetItems);
    delete($targetHash{$targetType});
}
writeRemaining($targetItems);
close $fh;


sub writeRemaining
{
    my ($yamlDict) = @_;
    for my $type (keys %targetHash)
    {
        print $fh $defaultPaths{$type}.":";
        print $fh "\n";
        while (my ($interface,$propertyMap) = each %{$yamlDict->{$type}})
        {
            print $fh "    ".$interface.":";
            print $fh "\n";
            while (my ($property,$value) = each %{$propertyMap})
            {
                $value = "'".$value."'";
                print $fh "        ".$property.": ".$value;
                print $fh "\n";
            }
        }
    }
}


sub writeOutput
{
    my ($type, $item, $yamlDict) = @_;
    print $fh $item->{OBMC_NAME}.":";
    print $fh "\n";
    while (my ($interface,$propertyMap) = each %{$yamlDict->{$type}})
    {
        print $fh "    ".$interface.":";
        print $fh "\n";
        while (my ($property,$value) = each %{$propertyMap})
        {
            $value = getValue($item, $property, $value);
            print $fh "        ".$property.": ".$value;
            print $fh "\n";
        }
    }
}


sub getValue
{
    my ($item, $property, $value) = @_;
    $value = "'".$value."'";

    if ($property eq "FieldReplaceable")
    {
        $value = "'false'";
        if (!$targets->isBadAttribute($item->{TARGET}, "RU_TYPE"))
        {
            my $ruType = $targets->getAttribute($item->{TARGET}, "RU_TYPE");
            if (($ruType eq "FRU") || ($ruType eq "CRU"))
            {
                $value = "'true'";
            }
        }
    }

    return $value;
}


sub printUsage
{
    print "
    $0 -m [MRW file] -c [Config yaml] -o [Output filename]\n";
    exit(1);
}
OpenPOWER on IntegriCloud