由於 RGM 傳送至 Validate 方法的引數集與傳送至其他回呼方法的引數集不同,所以 Validate 需要與其他方法不同的函數來剖析引數。請參閱 rt_callbacks(1HA) 線上手冊,以取得有關傳送至 Validate 和其他回呼方法之引數的更多資訊。以下程式碼範例顯示了 Validate parse_args() 函數。
#########################################################################
# Parse Validate arguments.
#
function parse_args # [args...]
{
typeset opt
while getopts 'cur:x:g:R:T:G:' opt
do
case "$opt" in
R)
# Name of the DNS resource.
RESOURCE_NAME=$OPTARG
;;
G)
# Name of the resource group in which the resource is
# configured.
RESOURCEGROUP_NAME=$OPTARG
;;
T)
# Name of the resource type.
RESOURCETYPE_NAME=$OPTARG
;;
r)
# The method is not accessing any system defined
# properties so this is a no-op
;;
g)
# The method is not accessing any resource group
# properties, so this is a no-op
;;
c)
# Indicates the Validate method is being called while
# creating the resource, so this flag is a no-op.
;;
u)
# Indicates the updating of a property when the
# resource already exists. If the update is to the
# Confdir property then Confdir should appear in the
# command-line arguments. If it does not, the method must
# look for it specifically using scha_resource_get.
UPDATE_PROPERTY=1
;;
x)
# Extension property list. Separate the property and
# value pairs using "=" as the separator.
PROPERTY=`echo $OPTARG | awk -F= '{print $1}'`
VAL=`echo $OPTARG | awk -F= '{print $2}'`
# If the Confdir extension property is found on the
# command line, note its value.
if [ $PROPERTY == "Confdir" ]; then
CONFDIR=$VAL
CONFDIR_FOUND=1
fi
;;
*)
logger -p ${SYSLOG_FACILITY}.err \
-t [$SYSLOG_TAG] \
"ERROR: Option $OPTARG unknown"
exit 1
;;
esac
done
}
正如其他方法具有 parse_args() 函數一樣,此函數提供了旗標 (R) 來擷取資源名稱,(G) 來擷取資源群組名稱和 (T) 來擷取由 RGM 傳送的資源類型。
忽略 r 旗標 (表示系統定義的特性)、g 旗標 (表示資源群組特性) 以及 c 旗標 (表示在建立資源的過程中進行驗證)。忽略它們是因為正在更新資源時會呼叫此方法來驗證延伸特性。
u 旗號將 UPDATE_PROPERTY shell 變數的值設定為 1 (TRUE)。x 旗標將擷取正在更新的特性之名稱和值。如果 Confdir 是正在更新的特性之一,則其值將被放入 CONFDIR shell 變數中,變數 CONFDIR_FOUND 將設定為 1 (TRUE)。