由于 RGM 向 Validate 方法传递了一组与其他回调方法不同的参数,因此 Validate 需要与其他方法不同的函数来解析这些参数。有关传递给 Validate 和其他回调方法的参数的更多信息,请参见 rt_callbacks(1HA) 手册页。以下样例代码显示了 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 是要更新的属性之一,其值将被放于 shell 变量 CONFDIR 中,并且变量 CONFDIR_FOUND 将被设置为 1 (TRUE)。