blob: d85726a33d429bb30796370c0813dcbf66da57c8 [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
461;
47
48=head1 NAME
49
50Util
51
52=head1 DESCRIPTION
53
54Contains utility functions for the MRW parsers.
55
56=head1 METHODS
57
58=over 4
59
60=item getBMCTarget(C<TargetsObj>)
61
62Returns the target string for the BMC chip. If it can't find one,
63it will die. Currently supports single BMC systems.
64
65=item getChildUnitsWithTargetType(C<TargetsObj>, C<TargetType>, C<ChipTarget>)
66
67Returns an array of targets that have target-type C<TargetType>
68and are children (any level) of target C<ChipTarget>.
69
70=back
71
72=cut