#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/lib/ksh93/db2/KLIB_DB2_rm_instance_metadata.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2005,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)05	1.4 src/43haes/lib/ksh93/db2/KLIB_DB2_rm_instance_metadata.sh, hacmp.assist, 61haes_r714 11/28/11 14:58:48
#
#=head1 NAME
#
# KLIB_DB2_rm_instance_metadata - Remove the DB2 instance metadata for
#                                 the specified instance
#
#=head1 SYNOPSIS
#
# KLIB_DB2_rm_instance_metadata "db2inst1"
#
#=head1 DESCRIPTION
#
# Removes the DB2 instance metadata added by the
# KLIB_DB2_add_instance_to_metadata function.
# Does not remove all of the associated metadata for an instance,
# clrmgrp performs this function
#
#=head1 ARGUMENTS
#
#   1: [scalar] DB2 instance name to remove metadata for
#
#=head1 RETURN
#
#   0: success
#   1: failed
#
#=head1 COPYRIGHT
#
#(C) COPYRIGHT International Business Machines Corp. 2005
#All Rights Reserved
#
#=cut
#
function KLIB_DB2_rm_instance_metadata
{
	. /usr/es/lib/ksh93/func_include

	instance=$1
	if [[ -z $instance ]]; then
		return 1
	fi

	typeset -A odm_fields

	# These are the ODM fields and mappings to the discovery content
	odm_fields=( \
		[HOME_FILESYSTEM]="INSTHOME"
		[HOME_VOLUME_GROUP]="DB2HOME_VG"
		[USER_NAME]="INSTANCE_OWNER_USER"
		[GROUP_NAME]="INSTANCE_OWNER_GROUP"
		[UID]="INSTANCE_OWNER_UID"
		[GID]="INSTANCE_OWNER_GID"
		[DASADM_USER]="DASADM_USER"
		[DASADM_GROUP]="DASADM_GROUP"
		[DASADM_UID]="DASADM_UID"
		[DASADM_GID]="DASADM_GID"
		[FENCED_USER]="FENCED_USER"
		[FENCED_GROUP]="FENCED_GROUP"
		[FENCED_UID]="FENCED_UID"
		[FENCED_GID]="FENCED_GID"
		[DATABASES]="DATABASES"
	)

	sa_type="SA_DB2Instance"
	key=$instance 	# key is the name of the DB2 instance
	for name in ${!odm_fields[*]}; do
		odmdelete -q "sa_type=$sa_type and key=$key and name=$name" -o HACMPsa_metadata >/dev/null 2>&1
	done

	return 0
}
