Add cores to the inventory

Change-Id: Ic600bfd95eba76744c99ccdc1c1300983a748212
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/Inventory.pm b/Inventory.pm
index 4efc38b..b5d4144 100644
--- a/Inventory.pm
+++ b/Inventory.pm
@@ -4,7 +4,7 @@
 use warnings;
 
 #Target types to always include in the inventory if present
-my %TYPES = (SYS => 1, NODE => 1, PROC => 1, BMC => 1, GPU => 1);
+my %TYPES = (SYS => 1, NODE => 1, PROC => 1, BMC => 1, GPU => 1, CORE => 1);
 
 #RU_TYPES of cards to include
 #FRU = field replaceable unit, CRU = customer replaceable unit
@@ -119,6 +119,9 @@
     #Don't need card segments for non-FRUs
     removeNonFRUCardSegments($targetObj, $inventory);
 
+    #Don't need to show the middle units between proc & core
+    removeIntermediateUnits($targetObj, $inventory);
+
     #Certain parts have standard naming
     renameSegmentWithType("PROC", "cpu", $targetObj, $inventory);
     renameSegmentWithType("SYS", "system", $targetObj, $inventory);
@@ -208,6 +211,34 @@
 }
 
 
+#Units, typically cores, can be subunits of other subunits of
+#their parent chip.  We can remove all of these intermediate
+#units.  For example, cpu0/someunit1/someunit2/core3 ->
+#cpu0/core3.
+sub removeIntermediateUnits
+{
+    my ($targetObj, $inventory) = @_;
+
+    for my $item (@$inventory) {
+
+        my $class = $targetObj->getAttribute($item->{TARGET}, "CLASS");
+        next unless ($class eq "UNIT");
+
+        my $parent = $targetObj->getTargetParent($item->{TARGET});
+
+        #Remove all of these intermediate units until we find
+        #something that isn't a unit (most likely a chip).
+        while ($targetObj->getAttribute($parent, "CLASS") eq "UNIT") {
+
+            my $name = $targetObj->getInstanceName($parent);
+            $item->{OBMC_NAME} =~ s/$name(-)*(\d+)*\///;
+
+            $parent = $targetObj->getTargetParent($parent);
+        }
+    }
+}
+
+
 #Renames segments of the paths to the name passed in
 #based on the type of the segment.
 #For example:
@@ -367,6 +398,8 @@
 
 =item * All targets of type PROC
 
+=item * All targets of type CORE
+
 =item * All targets of type BMC
 
 =item * All targets of type GPU