blob: aa98b5684946b951560de2efc457b5e3ec8ae0c0 [file] [log] [blame]
Matt Spinler8df7be82017-01-09 15:42:05 -06001package Util;
2
3#Holds common utility functions for MRW processing.
4
5use strict;
6use warnings;
7
8use mrw::Targets;
9
10#Returns the BMC target for a system.
11# param[in] $targetObj = The Targets object
12sub getBMCTarget
13{
14 my ($targetObj) = @_;
15
16 for my $target (keys %{$targetObj->getAllTargets()}) {
17 if ($targetObj->getType($target) eq "BMC") {
18 return $target;
19 }
20 }
21
22 die "Could not find BMC target in the MRW XML\n";
23}
24
25
26#Returns an array of child units based on their Target Type.
27# param[in] $targetObj = The Targets object
28# param[in] $unitTargetType = The target type of the units to find
29# param[in] $chip = The chip target to find the units on
30sub getChildUnitsWithTargetType
31{
32 my ($targetObj, $unitTargetType, $chip) = @_;
33 my @units;
34
35 my @children = $targetObj->getAllTargetChildren($chip);
36
37 for my $child (@children) {
38 if ($targetObj->getTargetType($child) eq $unitTargetType) {
39 push @units, $child;
40 }
41 }
42
43 return @units;
44}
45
Deepak Kodihalli6225e932017-02-07 12:14:55 -060046# Returns OBMC name corresponding to a Target name
47# param[in] \@inventory = reference to array of inventory items
48# param[in] $targetName = A Target name
49sub getObmcName
50{
51 my ($inventory_ref, $targetName) = @_;
52 my @inventory = @{ $inventory_ref };
53
54 for my $item (@inventory)
55 {
56 if($item->{TARGET} eq $targetName)
57 {
58 return $item->{OBMC_NAME};
59 }
60 }
61 return undef;
62}
63
Matt Spinler8df7be82017-01-09 15:42:05 -0600641;
65
66=head1 NAME
67
68Util
69
70=head1 DESCRIPTION
71
72Contains utility functions for the MRW parsers.
73
74=head1 METHODS
75
76=over 4
77
78=item getBMCTarget(C<TargetsObj>)
79
80Returns the target string for the BMC chip. If it can't find one,
81it will die. Currently supports single BMC systems.
82
83=item getChildUnitsWithTargetType(C<TargetsObj>, C<TargetType>, C<ChipTarget>)
84
85Returns an array of targets that have target-type C<TargetType>
86and are children (any level) of target C<ChipTarget>.
87
Deepak Kodihalli6225e932017-02-07 12:14:55 -060088=item getObmcName(C<InventoryItems>, C<TargetName>)
89
90Returns an OBMC name corresponding to a Target name. Returns
91undef if the Target name is not found.
92
Matt Spinler8df7be82017-01-09 15:42:05 -060093=back
94
95=cut