Hello,
I wrote an ocf script for iscsitarget, largely inspired by the iscsi script
by Dejan Muhamedagic, thanks to him.
Juste create /usr/lib/ocf/resource.d/atarakt/ietadm and you could use it to
manage independantly some initiators, the corresponding xml is a the end of
the message.
the space caracters between 'cat <<-!' and '!' must be a tabulation.
Atarakt.
#!/bin/sh
#
# IETDADM OCF resource agent
# Description: manage iscsi initiators (add/remove) using iscsitarget
#
#
# Author: Atarakt
# License: GNU General Public License (GPL)
#
# This code significantly inspired by the ocf iscsi resource
# script by Dejan Muhamedagic
#
# See usage() and meta_data() below for more details...
# OCF instance parameters:
# OCF_RESKEY_tid:
# OCF_RESKEY_lun:
# OCF_RESKEY_name:
# OCF_RESKEY_path:
# OCF_RESKEY_type :
#
# Initialization:
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
usage() {
methods=`iet_methods`
methods=`echo $methods | tr ' ' '|'`
cat <<-!
usage: $0 {$methods}
$0 manages an iSCSI initiator
The 'start' operation starts (adds) the iSCSI initiator.
The 'stop' operation stops (removes) the iSCSI initiator.
The 'status' operation reports whether the iSCSI initiator is
connected
The 'monitor' operation reports whether the iSCSI initiator is
connected
The 'validate-all' operation reports whether the parameters are
valid
The 'methods' operation reports on the methods $0 supports
!
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="ietadm">
<version>1.0</version>
<longdesc lang="en">
OCF Resource Agent for ietadm. Add (start) or remove (stop) iSCSI
initiators.
</longdesc>
<shortdesc lang="en">initiator resource agent</shortdesc>
<parameters>
<parameter name="tid" unique="1" required="1">
<longdesc lang="en">
target id
</longdesc>
<shortdesc lang="en">tid</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="lun" unique="0" required="1">
<longdesc lang="en">
lun number
</longdesc>
<shortdesc lang="en">lun</shortdesc>
<content type="string" default="0" />
</parameter>
<parameter name="name" unique="1" required="1">
<longdesc lang="en">
initiator name
</longdesc>
<shortdesc lang="en">name</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="path" unique="0" required="1">
<longdesc lang="en">
full path
</longdesc>
<shortdesc lang="en">path</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="type" unique="0" required="1">
<longdesc lang="en">
type blockio or fileio
</longdesc>
<shortdesc lang="en">type</shortdesc>
<content type="string" default="fileio" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="120" />
<action name="stop" timeout="120" />
<action name="status" timeout="30" />
<action name="monitor" depth="0" timeout="30" interval="120"
start-delay="10" />
<action name="validate-all" timeout="5" />
<action name="methods" timeout="5" />
<action name="meta-data" timeout="5" />
</actions>
</resource-agent>
END
}
iet_methods() {
cat <<-!
start
stop
status
monitor
validate-all
methods
meta-data
usage
!
}
#
# iscsitarget interface
#
iet_daemon() {
if ps -e -o cmd | grep -qs 'ietd'; then
return 0
else
ocf_log err "ietd not running; please start iscsi-target utilities"
return 1
fi
}
iet_setup() {
start_initiator=ietadm_add
remove_initiator=ietadm_remove
initiator_status=ietadm_status
ietadm=${OCF_RESKEY_ietadm:-"ietadm"}
which $ietadm >/dev/null || {
ocf_log err "ietadm not available; please set OCF_RESKEY_ietadm"
return $OCF_ERR_INSTALLED
}
iet_daemon ||
return $OCF_ERR_INSTALLED
}
ietadm_add() {
$ietadm --op new --tid=$1 --params Name=$3
$ietadm --op new --tid=$1 --lun=$2 --params Path=$4,Type=$5
}
ietadm_remove() {
$ietadm --op delete --tid=$1
}
ietadm_status() {
$ietadm --op show --tid=$1 > /dev/null 2>&1
}
iet_status() {
if $initiator_status $OCF_RESKEY_tid; then
return $OCF_SUCCESS
else
return $OCF_NOT_RUNNING
fi
}
iet_start() {
if iet_status; then
ocf_log info "initiator $OCF_RESKEY_name already running"
return $OCF_SUCCESS
else
$start_initiator $OCF_RESKEY_tid $OCF_RESKEY_lun $OCF_RESKEY_name
$OCF_RESKEY_path $OCF_RESKEY_type || return $OCF_ERR_GENERIC
if iet_status; then
return $OCF_SUCCESS
else
return $OCF_ERR_GENERIC
fi
fi
}
iet_stop() {
if iet_status; then
$remove_initiator $OCF_RESKEY_tid ||
return $OCF_ERR_GENERIC
if iet_status; then
return $OCF_ERR_GENERIC
else
return $OCF_SUCCESS
fi
else
ocf_log info "initiator $OCF_RESKEY_name already stopped"
return $OCF_SUCCESS
fi
}
iet_monitor() {
if $initiator_status $OCF_RESKEY_tid; then
return $OCF_SUCCESS
else
return $OCF_NOT_RUNNING
fi
}
#
# 'main' starts here...
if [ $# -ne 1 ]; then
usage
exit $OCF_ERR_ARGS
fi
# These operations don't require OCF instance parameters to be set
case "$1" in
meta-data) meta_data
exit $OCF_SUCCESS;;
usage) usage
exit $OCF_SUCCESS;;
methods) iet_methods
exit $OCF_SUCCESS;;
esac
case `uname` in
Linux) setup=iet_setup
;;
*) ocf_log info "platform `uname` may not be supported"
setup=iet_setup
;;
esac
LSB_STATUS_STOPPED=3
$setup
rc=$?
if [ $rc -ne 0 ]; then
ocf_log info "iscsi initiator utilities not installed or not setup"
case "$1" in
stop) exit $OCF_SUCCESS;;
monitor) exit $OCF_NOT_RUNNING;;
status) exit $LSB_STATUS_STOPPED;;
*) exit $rc;;
esac
fi
if [ `id -u` != 0 ]; then
ocf_log err "$0 must be run as root"
exit $OCF_ERR_PERM
fi
case $? in
0) ;;
1) [ "$1" = stop ] && exit $OCF_SUCCESS
[ "$1" = monitor ] && exit $OCF_NOT_RUNNING
[ "$1" = status ] && exit $LSB_STATUS_STOPPED
exit $OCF_ERR_GENERIC
;;
[23]) exit $OCF_ERR_GENERIC;;
esac
# which method was invoked?
case "$1" in
meta-data) meta_data
;;
start) iet_start
;;
stop) iet_stop
;;
status) if iet_status
then
echo initiator $OCF_RESKEY_name running
exit $OCF_SUCCESS
else
echo initiator $OCF_RESKEY_name stopped
exit $OCF_NOT_RUNNING
fi
;;
monitor) iet_status
;;
validate-all) # everything already validated
# just exit successfully here.
exit $OCF_SUCCESS;;
*) iet_methods
exit $OCF_ERR_UNIMPLEMENTED;;
esac
#
# vim:tabstop=4:shiftwidth=4:textwidth=0:wrapmargin=0
resources.xml :
<primitive id="initiator_test" class="ocf" type="ietadm" provider="atarakt">
<meta_attributes id="initiator-test_meta_attrs">
<attributes>
<nvpair id="initiator-test_metaattr_target_role" name="target_role"
value="stopped"/>
</attributes>
</meta_attributes>
<instance_attributes id="initiator-test_instance_attrs">
<attributes>
<nvpair id="initiator_test-tid" name="tid" value="1"/>
<nvpair id="initiator_test-lun" name="lun" value="0"/>
<nvpair id="initiator_test-name" name="name" value="test"/>
<nvpair id="initiator_test-path" name="path" value="/dev/data/test"/>
<nvpair id="initiator_test-type" name="type" value="fileio"/>
</attributes>
</instance_attributes>
<operations>
<op id="initiator_test-op" name="monitor" interval="120" timeout="30"
start_delay="10" on_fail="restart"/>
</operations>
</primitive>
--
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems