#!/usr/bin/perl

#
# @(#)03        1.1  src/bos/usr/sbin/drmgr/sample_scripts/IBM_template.pl.S, cmdcfg, bos720 8/22/02 11:44:41
#
# COMPONENT_NAME: (CMDCFG)
#
# FUNCTIONS: 
#
# ORIGINS: 27
#
# (C) COPYRIGHT International Business Machines Corp. 2000, 2002
# All Rights Reserved
# Licensed Materials - Property of IBM
# 
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
# FILE NAME: IBM_template.pl
#
# FILE DESCRIPTION: 
# This perl script will provide a template for DLPAR script developers
# to develop their custom perl scripts.
#
# It is the basic test script.  It implements all the commands of DLPAR
# script and for all them returns success.  It identifies itself with
# distinct details.

%DR_script_commands = (
			scriptinfo => 0,
			register => 1,
			usage => 2,
			checkrelease => 3,
			prerelease => 4,
			postrelease => 5,
			undoprerelease => 6,
			checkacquire => 7,
			preacquire => 8,
			postacquire => 9,
			undopreacquire => 10
		  );
%SCRIPT_DATA = (
		 SCRIPT_INFO => "AIX ",
		 SCRIPT_VERSION => "1",
		 SCRIPT_VENDOR => "IBM Corp.",
		 SCRIPT_TIMEOUT => 5
	);

%REGISTER_DATA = (
			CPU_RESOURCE => "cpu"
	);

%USAGE_DATA = (
		CPU_USAGE => "Testing DRAF on CPU removal"
	);

sub str_to_cmd {
	
	$s_cmd = $_[0];
	$DR_script_commands{$s_cmd};
}

sub process_scriptinfo {

	print "DR_SCRIPTINFO=$SCRIPT_DATA{SCRIPT_INFO}\n";
	print "DR_VERSION=$SCRIPT_DATA{SCRIPT_VERSION}\n";
	print "DR_DATE=04192002\n";
	print "DR_VENDOR=$SCRIPT_DATA{SCRIPT_VENDOR}\n";
	print "DR_TIMEOUT=$SCRIPT_DATA{SCRIPT_TIMEOUT}\n";
	0;
}

sub process_register {

	foreach $key (keys %REGISTER_DATA){
		print "DR_RESOURCE=$REGISTER_DATA{$key}\n";
	}
	0;
}

sub process_usage {

	$res = $_[0];

USE_SWITCH: {
	if ($res eq $REGISTER_DATA{CPU_RESOURCE}) 
		{ print "DR_USAGE=$USAGE_DATA{CPU_USAGE}\n"; 
		  last USE_SWITCH; }
	1;
}
	0;
}

sub process_checkrelease {

	10;
}

sub process_prerelease {

	10;
}

sub process_undoprerelease {

	10;
}

sub process_postrelease {

	10;
}

ARG_SWITCH: {
	if ($#ARGV == -1) { $rc = -1; last ARG_SWITCH; }
	if ($#ARGV == 0) { $command_str = $ARGV[0] ; last ARG_SWITCH; }
	if ($#ARGV == 1) { $command_str = $ARGV[0]; 
					   $res_name = $ARGV[1]; 
					   last ARG_SWITCH; }
	$rc = -2;
}

$command = str_to_cmd $command_str;

CMD_SWITCH: {
	if ($command == 0) {$rc = process_scriptinfo; last CMD_SWITCH }
	if ($command == 1) {$rc = process_register; last CMD_SWITCH }
	if ($command == 2) {$rc = process_usage $res_name; last CMD_SWITCH }
	if ($command == 3) {$rc = process_checkrelease $res_name; 
					last CMD_SWITCH }
	if ($command == 4) {$rc = process_prerelease $res_name; 
					last CMD_SWITCH }
	if ($command == 5) {$rc = process_postrelease $res_name; 
					last CMD_SWITCH }
	if ($command == 6) {$rc = process_undoprerelease $res_name; 
					last CMD_SWITCH }
	if ($command == 7) {$rc = process_checkacquire $res_name; 
					last CMD_SWITCH }
	if ($command == 8) {$rc = process_preacquire $res_name; 
					last CMD_SWITCH }
	if ($command == 9) {$rc = process_postacquire $res_name; 
					last CMD_SWITCH }
	if ($command == 10) {$rc = process_undopreacquire $res_name; 
					last CMD_SWITCH }
}

$rc;