#!/usr/bin/perl
# Change History:                                                        
# Defect   Modifier            MM/DD/YYYY  Description                   
# ------   ------------------  ----------  ----------------------------- 
# 522812   Adrian Sotomayor    02/09/2007  Add BPC levels to vpd collection
# 594812   Adrian Sotomayor    03/14/2007  Turn debug off
# --------------------------------------------------------------------------------
$cInvScout_DataDirectory = "/var/adm/invscout/";
$cInvScout_VPD_Directory = "VPD/";
$cCommand_lshsc          = "/opt/hsc/bin/lshsc";

$cModuleName            = $0;
$cModuleName            =~ s/.+?\///g;  # -- Program Name only, No Path --

# --------------------------------------------------------------------------------
$gcDEBUG = 0;
if ( $gcDEBUG )
{
    print "-" x 40;
    print "\n";
}


# --------------------------------------------------------------------------------
# -- lslic -m 9119-590*02AB33C -t power  -F activated_level:installed_level:accepted_level:mtms    
# -- 72:72:72:9458-100*02AB33C        
# --
# -- /opt/hsc/bin/lslic -m 9119-590*02AB33C -t power
# -- lic_type=Power Subsystem,management_status=Enabled,disabled_reason=,activated_level=99,installed_level=99,accepted_level=99,ecnumber=02BP230,mtms=9458-100*02AB33C
# -- 
# -- /opt/hsc/bin/lslic -m 9406-520*100072A -t power
# -- No results were found.
# -- 
# --------------------------------------------------------------------------------
$rc = 2;  # -- Standard RC for InvScout Complex Module --

# --------------------------------------------------------------------------------
%inArgv = &processInputParameters ( );
my ( $cecMTMS ) = &get_MTMS ( *inArgv );
my ( $cecMachineType, $cecMachineModel, $cecMachineSerial ) = &split_MTMS ( $cecMTMS );

# -- Fix CEC MTMS format: MT-M-S (for XML output) --
$cecMTMS = $cecMachineType . "-" . $cecMachineModel . "-" . $cecMachineSerial;

# -- Create a proper output FileName --
my ( $outputFileName ) = 
    "$cInvScout_DataDirectory" . 
    "$cInvScout_VPD_Directory" . 
    $cModuleName .
    "_" .
    $cecMachineType . "-" . $cecMachineModel . "_" . $cecMachineSerial .
    ".VPD.xml";

# ----------------------------------------
if ( $gcDEBUG )
{
    print "Input : \n" . 
	"\tMachineType   = $cecMachineType\n" .
	"\tMachineModel  = $cecMachineModel\n" . 
	"\tMachineSerial = $cecMachineSerial\n" . 
	"\n";

    print "XML mtms = $cecMTMS\n";
    print "Designated OutputFileName = $outputFileName\n";
    print "\n";
}
$xml_BPA_VPD = &vpdSurvey_BulkPowerAssembly ( $cecMachineType, $cecMachineModel, $cecMachineSerial );

# ----------------------------------------
if ( $gcDEBUG )
{
    print "-" x 40;
    print "\n";
}


my ( @xmlData ) = &createXML_InventoryEnclosure ( $cecMTMS, $xml_BPA_VPD );


$" = "";
open ( fOUT, "> $outputFileName" );
print fOUT @xmlData;
close ( fOUT );

# -- InvScout Complex Module (rc = 2) prints the output FileName into STDOUT
print "$outputFileName\n";

exit ( $rc );



# --------------------------------------------------------------------------------
sub get_TimeStamp
{
    # ----------------------------------------
    # -- www.perl.com : --
    #    0    1    2     3     4    5     6     7     8
    # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    # ----------------------------------------
    my ( @date ) = localtime();
    $#date    = 5;     # -- Truncate the unwanted elements (past $year) --
    $date[5] += 1900;  # -- Year += 1900
    $date[4] += 1;     # -- Month January = 0
    
    # -- Pad 0 for single digit numbers --
    map { $_ =~ s/\b(\d)\b/0$1/ } @date;

    unshift ( @date, "000" );      # -- add milisecond --

    return (  join ( "", ( reverse @date ) ) );
}


# --------------------------------------------------------------------------------
sub createXML_BPA_Enclosure
{
    my ( $inBPA_MTMS, $inXML_Begin ) = @_;
    my ( $xml );

    if ( $inXML_Begin )
    {
	$xml = <<XML
            <Resource displayName="BULK POWER ASSEMBLY" uniqueId="U$inBPA_MTMS">
               BULK POWER ASSEMBLY
               <ResourceList displayName="Global Resources">
XML
;
    }
    else
    {
	$xml = <<XML
               </ResourceList>
            </Resource>
XML
;
    }

    return ( $xml );
}

# --------------------------------------------------------------------------------
sub createXML_BPA_Managed_Enclosure
{
    my ( $inBPA_MTMS, $inXML_Begin ) = @_;
    my ( $xml );

    if ( $inXML_Begin )
    {
	$xml = <<XML
            <Resource displayName="MANAGED SYSTEM" uniqueId="U$inBPA_MTMS">
               MANAGED SYSTEM
               <ResourceList displayName="Global Resources">
XML
;
    }
    else
    {
	$xml = <<XML
               </ResourceList>
            </Resource>
XML
;
    }

    return ( $xml );
}

# --------------------------------------------------------------------------------
#sub createXML_BPA_Resource
#{
#    # -- inLocation is either "-P1-C4" or "-P2-C4" --
#    my (  $inBPA_MTMS, $inActivatedLevel, $inInstalledLevel, $inAcceptedLevel, $inLocation ) = @_;
#
#    my ( $xml ) = <<XML
#                  <Resource displayName="Bulk Pwr Cont E0" uniqueId="U$inBPA_MTMS$inLocation">
#		  Bulk Pwr Cont E0
#                     <Property displayName="Microcode Level" name="RX">
#                        RX
#                        <Value type="string">$inInstalledLevel</Value>
#                     </Property>
#                  </Resource>
#XML
#;
#
#    return ( $xml );
#}

# --------------------------------------------------------------------------------
sub createXML_BPA_Resource_Set
{
    my ( $inBPA_MTMS, $inLocation, $inXML_Begin ) = @_;
    my ( $xml );

    if ( $inXML_Begin )
    {
	$xml = <<XML
                  <Resource displayName="Bulk Pwr Cont E0" uniqueId="U$inBPA_MTMS$inLocation">
		  Bulk Pwr Cont E0
XML
;
    }
    else
    {
	$xml = <<XML
                  </Resource>
XML
;
    }

    return ( $xml );
}

# --------------------------------------------------------------------------------
sub createXML_BPA_Single_Resource
{
    # -- inLocation is either "-P1-C4" or "-P2-C4" --
    my (  $displayName, $name, $value ) = @_;

    my ( $xml ) = <<XML
                     <Property displayName="$displayName" name="$name">
                        $name
                        <Value type="string">$value</Value>
                     </Property>
XML
;

    return ( $xml );
}

# --------------------------------------------------------------------------------
sub createXML_BPA_Managed_Resource_Set
{
    my ( $inBPA_MTMS, $inLocation, $inXML_Begin ) = @_;
    my ( $xml );

    if ( $inXML_Begin )
    {
	$xml = <<XML
                  <Resource displayName="Managed Pwr Cont E0" uniqueId="U$inBPA_MTMS$inLocation">
		  Managed Pwr Cont E0
XML
;
    }
    else
    {
	$xml = <<XML
                  </Resource>
XML
;
    }

    return ( $xml );
}

# --------------------------------------------------------------------------------
sub createXML_InventoryEnclosure
{
    my ( $inCEC_MTMS, $inXML_BPA_VPD ) = @_;
    my ( $timestamp ) = &get_TimeStamp ();
    my ( $xmlBegin ) = <<XML
<?xml version="1.0" encoding="UTF-8"?>
<com.ibm.inventory version="1.0">
   <ResourceSet class="com.ibm.inventory.Hardware" timestamp="$timestamp" type="Hardware" version="1.0">
      <Resource displayName="$inCEC_MTMS" uniqueId="$inCEC_MTMS">
         $inCEC_MTMS
         <ResourceList displayName="Enclosures">

XML
;

    my ( $xmlEnd ) = <<XML
	 </ResourceList>
      </Resource>
   </ResourceSet>
</com.ibm.inventory>
XML
;

    my ( @xmlData ) = ( $xmlBegin, $inXML_BPA_VPD, $xmlEnd );

    return ( @xmlData );
}

# --------------------------------------------------------------------------------
sub vpdSurvey_BulkPowerAssembly
{
    my ( $inCEC_MachineType, $inCEC_MachineModel, $inCEC_MachineSerial ) = @_;
    my ( $cecMTMS ) = $inCEC_MachineType . "-" . $inCEC_MachineModel . "*" . $inCEC_MachineSerial;

    # --------------------------------------------------------------------------------
    # -- lslic -m 9119-590*02AB33C -t power  -F lic_type:mtms:activated_level:installed_level:accepted_level
    #											:curr_level_a:curr_ecnumber_a:curr_power_on_side_a:pend_power_on_side_a:temp_level_a:temp_ecnumber_a:perm_level_a:perm_ecnumber_a
    #											:curr_level_b:curr_ecnumber_b:curr_power_on_side_b:pend_power_on_side_b:temp_level_b:temp_ecnumber_b:perm_level_b:perm_ecnumber_b
    # -- Power Subsystem:9458-100*02AB33C:197:197:197    
    # --------------------------------------------------------------------------------
    my ( $lslicCommand ) = '/opt/hsc/bin/lslic -m ' . $cecMTMS . ' -t power -F lic_type:mtms:activated_level:installed_level:accepted_level:curr_level_a:curr_ecnumber_a:curr_power_on_side_a:pend_power_on_side_a:temp_level_a:temp_ecnumber_a:perm_level_a:perm_ecnumber_a:curr_level_b:curr_ecnumber_b:curr_power_on_side_b:pend_power_on_side_b:temp_level_b:temp_ecnumber_b:perm_level_b:perm_ecnumber_b';

    # --------------------------------------------------------------------------------
    # -- lslic -m 9119-590*02AB33C -t sys  -F lic_type:mtms:activated_level:installed_level:accepted_level
    #                                         :curr_level_primary:curr_ecnumber_primary:curr_power_on_side_primary:pend_power_on_side_primary:temp_level_primary:temp_ecnumber_primary:perm_level_primary:perm_ecnumber_primary
    #                                         :curr_level_secondary:curr_ecnumber_secondary:curr_power_on_side_secondary:pend_power_on_side_secondary:temp_level_secondary:temp_ecnumber_secondary:perm_level_secondary:perm_ecnumber_secondary
    # -- Managed System:9119-590*02AB33C:282:282:282
    # --------------------------------------------------------------------------------
    my ( $lslicCommand_managed ) = '/opt/hsc/bin/lslic -m ' . $cecMTMS . ' -t sys -F lic_type:mtms:activated_level:installed_level:accepted_level::curr_level_primary:curr_ecnumber_primary:curr_power_on_side_primary:pend_power_on_side_primary:temp_level_primary:temp_ecnumber_primary:perm_level_primary:perm_ecnumber_primary:curr_level_secondary:curr_ecnumber_secondary:curr_power_on_side_secondary:pend_power_on_side_secondary:temp_level_secondary:temp_ecnumber_secondary:perm_level_secondary:perm_ecnumber_secondary';


    # ----------------------------------------
    if ( $gcDEBUG )
    {
		print "- power, running ->|$lslicCommand|<--\n";
		print "- sys,   running ->|$lslicCommand_managed|<--\n";
    }

    my ( @lslic ) = `$lslicCommand`;
    my ( @lslic_managed ) = `$lslicCommand_managed`;

    # ----------------------------------------
    if ( $gcDEBUG )
    {
		print "power -->|$lslic[0]|<--\n";
		print "sys   -->|$lslic_managed[0]|<--\n";
    }

    # -- Must contain "Power Subsystem" or "Managed System" in the beginning of return value
    unless ( $lslic[0] =~ /^Power Subsystem:/ || $lslic_managed[0] =~ /^Managed System:/)
    {
		if ( $gcDEBUG )
		{
		    print "ERROR : lslic -t power output nothing : $lslic[0]\n";
		    print "ERROR : lslic -t sys output nothing : $lslic_managed[0]\n";
		}
		exit ( 0 );
    }

    my ( $xml_BPA_VPD );

    # -- Must contain "Power Subsystem" in the beginning of return value
    if ( $lslic[0] =~ /^Power Subsystem:/ )
    {
	    foreach $level ( @lslic )
	    {
			$level =~ s/\s//g;
			my ( $licType, $bpaMTMS, $activatedLevel, $installedLevel, $acceptedLevel,
			     $curr_level_a, $curr_ecnumber_a, $curr_power_on_side_a, $pend_power_on_side_a,
			     $temp_level_a, $temp_ecnumber_a, $perm_level_a,         $perm_ecnumber_a,
			     $curr_level_b, $curr_ecnumber_b, $curr_power_on_side_b, $pend_power_on_side_b,
			     $temp_level_b, $temp_ecnumber_b, $perm_level_b,         $perm_ecnumber_b) = split ( /\:/, $level );
			# -- Need to correct BPA MTMS format ( MT.M.S ) --
			$bpaMTMS = join ( ".", &split_MTMS ( $bpaMTMS ) );
		
			$xml_BPA_VPD .= &createXML_BPA_Enclosure ( $bpaMTMS, 1 );   # -- Begin Power Subsystem --

			$xml_BPA_VPD .= &createXML_BPA_Resource_Set ($bpaMTMS, "-P1-C4", 1 );  # -- Begin Resources --
			$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Microcode Level", "RX", $installedLevel );

			if((length $curr_level_a) != 0)
			{
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Level A", "CLA", $curr_level_a );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr EC Number A", "CEA", $curr_ecnumber_a );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Power On Side A", "CPA", $curr_power_on_side_a );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Pend Power On Side A", "PPA", $pend_power_on_side_a );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp Level A", "TLA", $temp_level_a );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp EC Number A", "TEA", $temp_ecnumber_a );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm Level A", "PLA", $perm_level_a );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm EC Number A", "PEA", $perm_ecnumber_a );
			}
			else
			{
				if ( $gcDEBUG )
				{
					print "Power, No information available for A\n";
				}
			}

			if((length $curr_level_b) != 0)
			{
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Level B", "CLA", $curr_level_b );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr EC Number B", "CEA", $curr_ecnumber_b );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Power On Side B", "CPA", $curr_power_on_side_b );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Pend Power On Side B", "PPA", $pend_power_on_side_b );
			
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp Level B", "TLA", $temp_level_b );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp EC Number B", "TEA", $temp_ecnumber_b );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm Level B", "PLA", $perm_level_b );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm EC Number B", "PEA", $perm_ecnumber_b );
			}
			else
			{
				if ( $gcDEBUG )
				{
					print "Power, No information available for B\n";
				}
			}
			
			$xml_BPA_VPD .= &createXML_BPA_Resource_Set ($bpaMTMS, "-P1-C4", 0 );  # -- End Resources --
			
			#$xml_BPA_VPD .= &createXML_BPA_Resource  ( $bpaMTMS, $activatedLevel, $installedLevel, $acceptedLevel, "-P1-C4"  );
			#$xml_BPA_VPD .= &createXML_BPA_Resource  ( $bpaMTMS, $activatedLevel, $installedLevel, $acceptedLevel, "-P2-C4"  );

			$xml_BPA_VPD .= &createXML_BPA_Resource_Set ($bpaMTMS, "-P2-C4", 1 );  # -- Begin Resources --
			$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Microcode Level", "RX", $installedLevel );

			if((length $curr_level_a) != 0)
			{
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Level A", "CLA", $curr_level_a );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr EC Number A", "CEA", $curr_ecnumber_a );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Power On Side A", "CPA", $curr_power_on_side_a );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Pend Power On Side A", "PPA", $pend_power_on_side_a );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp Level A", "TLA", $temp_level_a );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp EC Number A", "TEA", $temp_ecnumber_a );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm Level A", "PLA", $perm_level_a );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm EC Number A", "PEA", $perm_ecnumber_a );
			}
			else
			{
				if ( $gcDEBUG )
				{
					print "Power, No information available for A\n";
				}
			}

			if((length $curr_level_b) != 0)
			{
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Level B", "CLA", $curr_level_b );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr EC Number B", "CEA", $curr_ecnumber_b );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Power On Side B", "CPA", $curr_power_on_side_b );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Pend Power On Side B", "PPA", $pend_power_on_side_b );
			
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp Level B", "TLA", $temp_level_b );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp EC Number B", "TEA", $temp_ecnumber_b );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm Level B", "PLA", $perm_level_b );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm EC Number B", "PEA", $perm_ecnumber_b );
			}
			else
			{
				if ( $gcDEBUG )
				{
					print "Power, No information available for B\n";
				}
			}

			$xml_BPA_VPD .= &createXML_BPA_Resource_Set ($bpaMTMS, "-P2-C4", 0 );  # -- End Resources --

			$xml_BPA_VPD .= &createXML_BPA_Enclosure ( $bpaMTMS, 0 );   # -- End Power Subsystem --
			$xml_BPA_VPD .= "\n";
	    }
    }

    # -- Must contain "Managed System" in the beginning of return value
    if ( $lslic_managed[0] =~ /^Managed System:/)
    {
	    foreach $level ( @lslic_managed )
	    {
			$level =~ s/\s//g;
			my ( $licType, $bpaMTMS, $activatedLevel, $installedLevel, $acceptedLevel, 
				 $curr_level_primary,   $curr_ecnumber_primary,   $curr_power_on_side_primary,   $pend_power_on_side_primary,
				 $temp_level_primary,   $temp_ecnumber_primary,   $perm_level_primary,           $perm_ecnumber_primary,
                 $curr_level_secondary, $curr_ecnumber_secondary, $curr_power_on_side_secondary, $pend_power_on_side_secondary,
                 $temp_level_secondary, $temp_ecnumber_secondary, $perm_level_secondary,         $perm_ecnumber_secondary ) = split ( /\:/, $level );

			# -- Need to correct BPA MTMS format ( MT.M.S ) --
			$bpaMTMS = join ( ".", &split_MTMS ( $bpaMTMS ) );

			$xml_BPA_VPD .= &createXML_BPA_Managed_Enclosure ( $bpaMTMS, 1 );   # -- Begin Managed System --

			$xml_BPA_VPD .= &createXML_BPA_Managed_Resource_Set ($bpaMTMS, "-P1-C4", 1 );  # -- Begin Resources --
			$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Microcode Level", "MX", $installedLevel );

			if((length $curr_level_primary) != 0)
			{
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Level Primary", "CLP", $curr_level_primary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr EC Number Primary", "CEP", $curr_ecnumber_primary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Power On Side Primary", "CPP", $curr_power_on_side_primary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Pend Power On Side Primary", "PPP", $pend_power_on_side_primary );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp Level Primary", "TLP", $temp_level_primary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp EC Number Primary", "TEP", $temp_ecnumber_primary );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm Level Primary", "PLP", $perm_level_primary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm EC Number Primary", "PEP", $perm_ecnumber_primary );
			}
			else
			{
				if ( $gcDEBUG )
				{
					print "Managed System, No information available for Primary\n";
				}
			}

			if((length $curr_level_secondary) != 0)
			{
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Level Secondary", "CLS", $curr_level_secondary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr EC Number Secondary", "CES", $curr_ecnumber_secondary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Power On Side Secondary", "CPS", $curr_power_on_side_secondary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Pend Power On Side Secondary", "PPS", $pend_power_on_side_secondary );
			
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp Level Secondary", "TLS", $temp_level_secondary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp EC Number Secondary", "TES", $temp_ecnumber_secondary );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm Level Secondary", "PLS", $perm_level_secondary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm EC Number Secondary", "PES", $perm_ecnumber_secondary );
			}
			else
			{
				if ( $gcDEBUG )
				{
					print "Managed System, No information available for Secondary\n";
				}
			}
			
			$xml_BPA_VPD .= &createXML_BPA_Managed_Resource_Set ($bpaMTMS, "-P1-C4", 0 );  # -- End Resources --

			$xml_BPA_VPD .= &createXML_BPA_Managed_Resource_Set ($bpaMTMS, "-P2-C4", 1 );  # -- Begin Resources --
			$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Microcode Level", "MX", $installedLevel );

			if((length $curr_level_primary) != 0)
			{
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Level Primary", "CLP", $curr_level_primary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr EC Number Primary", "CEP", $curr_ecnumber_primary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Power On Side Primary", "CPP", $curr_power_on_side_primary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Pend Power On Side Primary", "PPP", $pend_power_on_side_primary );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp Level Primary", "TLP", $temp_level_primary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp EC Number Primary", "TEP", $temp_ecnumber_primary );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm Level Primary", "PLP", $perm_level_primary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm EC Number Primary", "PEP", $perm_ecnumber_primary );
			}
			else
			{
				if ( $gcDEBUG )
				{
					print "Managed System, No information available for Primary\n";
				}
			}

			if((length $curr_level_secondary) != 0)
			{
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Level Secondary", "CLS", $curr_level_secondary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr EC Number Secondary", "CES", $curr_ecnumber_secondary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Curr Power On Side Secondary", "CPS", $curr_power_on_side_secondary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Pend Power On Side Secondary", "PPS", $pend_power_on_side_secondary );
			
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp Level Secondary", "TLS", $temp_level_secondary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Temp EC Number Secondary", "TES", $temp_ecnumber_secondary );

				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm Level Secondary", "PLS", $perm_level_secondary );
				$xml_BPA_VPD .= &createXML_BPA_Single_Resource  ( "Perm EC Number Secondary", "PES", $perm_ecnumber_secondary );
			}
			else
			{
				if ( $gcDEBUG )
				{
					print "Managed System, No information available for Secondary\n";
				}
			}

			$xml_BPA_VPD .= &createXML_BPA_Managed_Resource_Set ($bpaMTMS, "-P2-C4", 0 );  # -- End Resources --

			$xml_BPA_VPD .= &createXML_BPA_Managed_Enclosure ( $bpaMTMS, 0 );   # -- End Managed System --
			$xml_BPA_VPD .= "\n";
	    }
    }

    return ( $xml_BPA_VPD );
}


# --------------------------------------------------------------------------------
sub split_MTMS
{
    my ( $inMTMS ) = @_;
    my ( $mtmsSeparator ) = '[^a-zA-Z0-9]';
    my ( $machineType, $machineModel, $machineSerial ) = split ( /$mtmsSeparator/, $inMTMS );

    return ( $machineType, $machineModel, $machineSerial );
}

# --------------------------------------------------------------------------------
sub get_MTMS
{
    local ( *inArgv, $outMachineType, $outMachineModel, $outMachineSerial ) = @_;
    # ------------------------------------------------------------
    # -- Requires             "-c MachineType-Model_Serial"
    # -- or [deprecated]      "-m MachineType-Model -s Serial" 
    # ------------------------------------------------------------
    my ( $mtms ) = ();
    if ( defined $inArgv{'-c'} )
    {
	$mtms = $inArgv{'-c'};
    }
    elsif ( ( defined $inArgv{'-m'} ) && ( defined $inArgv{'-s'} ) )
    {
	$mtms = $inArgv{'-m'} . "_" . $inArgv{'-s'};
    }
    else
    {
	$rc = 255;  # -- Error: MTMS is not specified --
	print STDERR "Error: MTMS is not specified\n";
	exit ( $rc );
    }
    
    return ( $mtms );

    my ( $mtmsPattern ) = '[a-zA-Z0-9]';   # -- "\w" won't work because it includes underscore ("_") --
    # ----------MachineType----MachineModel---MachineSerial--
    $mtms =~ s/($mtmsPattern+).($mtmsPattern+).($mtmsPattern+)//;
    ${$outMachineType}   = $1;
    ${$outMachineModel}  = $2;
    ${$outMachineSerial} = $3;

}


# --------------------------------------------------------------------------------
sub processInputParameters
{
    my ( %argvTable ) = ( );
    my ( $flag ) = ( );
    foreach $argv ( @ARGV )
    {
	if ( $argv =~ /^-/ )
	{
	    $flag = $argv;
	    $argvTable{$argv} = "";  # -- defined --
	}
	else
	{
	    $argvTable{$flag} .= " " if ( $argvTable{$flag} );
	    $argvTable{$flag} .= $argv;
	}
    }
    
    return ( %argvTable );
}
