Ack with one comment: --admin_op should be renamed to --admin-op (dash instead
of underscore as word separator).
regards,
Anders Widell
On 05/12/2017 11:54 AM, Praveen wrote:
> This is V2 which incorporates comments given on V1.
>
> clm-adm: for performing CLM admin operations on CLM node and cluser.
> clm-find: for finding out object(s) configured for CLM classes SaClmCluster
> and SaClmNode. Additional options like membership status and admin
> state
> can also be given to find out objects which satisfy this criteria.
> clm-state: for listing CLM node(s) and their important attributes.
> ---
> opensaf.spec.in | 3 +
> src/clm/Makefile.am | 5 ++
> src/clm/tools/clm-adm | 105 ++++++++++++++++++++++++++++++++++
> src/clm/tools/clm-find | 84 +++++++++++++++++++++++++++
> src/clm/tools/clm-state | 148
> ++++++++++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 345 insertions(+)
> create mode 100644 src/clm/tools/clm-adm
> create mode 100644 src/clm/tools/clm-find
> create mode 100644 src/clm/tools/clm-state
>
> diff --git a/opensaf.spec.in b/opensaf.spec.in
> index 0078fc2..70056b6 100644
> --- a/opensaf.spec.in
> +++ b/opensaf.spec.in
> @@ -1445,6 +1445,9 @@ fi
> %{_bindir}/ntfsubscribe
> %{_bindir}/ntfread
> %{_bindir}/saflogger
> +%{_bindir}/clm-adm
> +%{_bindir}/clm-find
> +%{_bindir}/clm-state
> %if %is_ais_smf
> %{_bindir}/smf-adm
> %{_bindir}/smf-find
> diff --git a/src/clm/Makefile.am b/src/clm/Makefile.am
> index ad9f90a..da2d7d9 100644
> --- a/src/clm/Makefile.am
> +++ b/src/clm/Makefile.am
> @@ -166,6 +166,11 @@ bin_osafclmna_LDADD = \
> lib/libSaAmf.la \
> lib/libopensaf_core.la
>
> +dist_bin_SCRIPTS += \
> + src/clm/tools/clm-adm \
> + src/clm/tools/clm-find \
> + src/clm/tools/clm-state
> +
> if ENABLE_TESTS
>
> bin_PROGRAMS += bin/clmtest
> diff --git a/src/clm/tools/clm-adm b/src/clm/tools/clm-adm
> new file mode 100644
> index 0000000..ae75fe5
> --- /dev/null
> +++ b/src/clm/tools/clm-adm
> @@ -0,0 +1,105 @@
> +#! /bin/sh
> +# -*- OpenSAF -*-
> +#
> +# Copyright (C) 2017, Oracle and/or its affiliates. All rights reserved.
> +#
> +# This program is distributed in the hope that it will be useful, but
> +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
> +# or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed
> +# under the GNU Lesser General Public License Version 2.1, February 1999.
> +# The complete license can be accessed from the following location:
> +# http://opensource.org/licenses/lgpl-license.php
> +# See the Copying file included with the OpenSAF distribution for full
> +# licensing terms.
> +#
> +
> +usage()
> +{
> + echo ""
> + echo "USAGE: $(basename "$0") [-t value] <-o op_name> <DN>"
> + echo ""
> + echo "OPTIONS:"
> + echo " -t or --timeout : command timeout in seconds (default=60)
> (optional)"
> + echo " -o or --admin_op: operation name (mandatory)"
> + echo " 'lock' for admin lock "
> + echo " 'unlock' for admin unlock "
> + echo " 'shutdown' for admin shutdown "
> + echo " 'reset' for admin reset of cluster"
> + echo " DN : a valid DN name of CLM node or cluster
> (mandatory)"
> + echo ""
> + echo ""
> +}
> +
> +options=$(getopt -o t:o:h -l timeout:,admin_op:,help -- "$@")
> +status=$?
> +if [ $status -ne 0 ] ; then
> + echo "Try '$(basename "$0") -h or --help' for more information"
> + exit 1
> +fi
> +eval set -- "$options"
> +
> +DN=""
> +CMD=""
> +TIMEOUT=""
> +
> +while true; do
> + case $1 in
> + -t|--timeout)
> + shift 1
> + TIMEOUT=$1;
> + shift 1
> + ;;
> + -o|--admin_op)
> + shift 1
> + if [ "$1" = "unlock" ]; then
> + CMD=1
> + elif [ "$1" = "lock" ]; then
> + CMD=2
> + elif [ "$1" = "shutdown" ]; then
> + CMD=3
> + elif [ "$1" = "reset" ]; then
> + CMD=4
> + else
> + echo "Invalid operation name"
> + exit 1
> + fi
> + shift 1
> + ;;
> + -h|--help)
> + usage
> + exit 0
> + ;;
> + \?)
> + echo "Invalid option"
> + exit 1
> + ;;
> + --)
> + shift;
> + break;
> + ;;
> + esac
> +done
> +
> +if [ "$CMD" = "" ]; then
> + echo "operation name is mandatory"
> + echo "Try '$(basename "$0") -h or --help' for more information"
> + exit 1
> +fi
> +
> +shift $((OPTIND -1))
> +
> +DN="$*"
> +if [ "$DN" = "" ]; then
> + echo "DN name is mandatory"
> + echo "Try '$(basename "$0") -h or --help' for more information"
> + exit 1
> +fi
> +
> +if [ "$TIMEOUT" = "" ]; then
> + immadm -o "$CMD" "$DN"
> +else
> + immadm -t "$TIMEOUT" -o "$CMD" "$DN"
> +fi
> +
> +exit $?
> +
> diff --git a/src/clm/tools/clm-find b/src/clm/tools/clm-find
> new file mode 100644
> index 0000000..3073fb5
> --- /dev/null
> +++ b/src/clm/tools/clm-find
> @@ -0,0 +1,84 @@
> +#! /bin/sh
> +
> +# -*- OpenSAF -*-
> +#
> +# Copyright (C) 2017, Oracle and/or its affiliates. All rights reserved.
> +#
> +# This program is distributed in the hope that it will be useful, but
> +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
> +# or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed
> +# under the GNU Lesser General Public License Version 2.1, February 1999.
> +# The complete license can be accessed from the following location:
> +# http://opensource.org/licenses/lgpl-license.php
> +# See the Copying file included with the OpenSAF distribution for full
> +# licensing terms.
> +#
> +
> +usage()
> +{
> + echo ""
> + echo "USAGE: $(basename "$0") [ option ]"
> + echo ""
> + echo "OPTIONS:"
> + echo " -c, --cluster-name : display DN of CLM cluster"
> + echo " -l, --locked : display DNs of locked nodes."
> + echo " -u, --unlocked : display DNs of unlocked nodes."
> + echo " -m, --member : display DNs of member nodes."
> + echo " -n, --nonmember : display DNs of non-member nodes."
> + echo " -h, --help : display this help"
> + echo ""
> + echo " Note: Without any option, DNs of all Nodes will be
> displayed."
> + echo ""
> +}
> +
> +list_with_states ()
> +{
> + for i in $(immfind -c "SaClmNode"); do
> + if [ "$1" = "locked" ] || [ "$1" = "unlocked" ]; then
> + value=$(immlist -a "saClmNodeAdminState" "$i" | cut -d = -f2)
> + if ([ "$1" = "locked" ] && [ "$value" -eq 2 ]) || ([ "$1" = "unlocked"
> ] && [ "$value" -eq 1 ]); then
> + echo "$i"
> + fi
> + else
> + value=$(immlist -a "saClmNodeIsMember" "$i" | cut -d = -f2)
> + if [ "$value" = "<Empty>" ]; then
> + value=0
> + fi
> + if ([ "$1" = "nonmember" ] && [ "$value" -eq 0 ]) || ([ "$1" =
> "member" ] && [ "$value" -eq 1 ]); then
> + echo "$i"
> + fi
> + fi
> + done
> +}
> +
> +case $1 in
> + -c|--cluster-name)
> + immfind -c "SaClmCluster"
> + ;;
> + -l|--locked)
> + list_with_states "locked"
> + ;;
> + -u|--unlocked)
> + list_with_states "unlocked"
> + ;;
> + -m|--member)
> + list_with_states "member"
> + ;;
> + -n|--nonmember)
> + list_with_states "nonmember"
> + ;;
> + -h|--help)
> + usage
> + exit 0
> + ;;
> + -?*)
> + echo "Invalid option"
> + echo "Try '$(basename "$0") -h or --help' for more
> information"
> + exit 1
> + ;;
> + *)
> + immfind -c "SaClmNode"
> + ;;
> +esac
> +exit $?
> +
> diff --git a/src/clm/tools/clm-state b/src/clm/tools/clm-state
> new file mode 100644
> index 0000000..5ef8685
> --- /dev/null
> +++ b/src/clm/tools/clm-state
> @@ -0,0 +1,148 @@
> +#! /bin/sh
> +
> +# -*- OpenSAF -*-
> +#
> +# Copyright (C) 2017, Oracle and/or its affiliates. All rights reserved.
> +#
> +# This program is distributed in the hope that it will be useful, but
> +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
> +# or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed
> +# under the GNU Lesser General Public License Version 2.1, February 1999.
> +# The complete license can be accessed from the following location:
> +# http://opensource.org/licenses/lgpl-license.php
> +# See the Copying file included with the OpenSAF distribution for full
> +# licensing terms.
> +#
> +
> +usage()
> +{
> + echo ""
> + echo "USAGE: $(basename "$0") [ options ] [ DN ]"
> + echo ""
> + echo "OPTIONS:"
> + echo " -a, --admin : display admin state of node"
> + echo " -m, --membership : display membership status of node"
> + echo " -i, --nodeid : display CLM nodeid of node"
> + echo " -h, --help : display this help"
> + echo " DN : CLM node DN. If given, state(s) of only
> this node will be displayed."
> + echo ""
> + echo " Note: Without options, it displays three states for all
> nodes."
> + echo ""
> +}
> +
> +options=$(getopt -o a,m,i,h -l admin,membership,nodeid,help -- "$@")
> +status=$?
> +if [ $status -ne 0 ] ; then
> + echo "Try '$(basename "$0") -h or --help' for more information"
> + exit 1
> +fi
> +eval set -- "$options"
> +
> +ADMIN=0
> +MEMBERSHIP=0
> +NODEID=0
> +DN=""
> +
> +while true; do
> + case $1 in
> + -a|--admin)
> + ADMIN=1
> + shift
> + ;;
> + -m|--membership)
> + MEMBERSHIP=1
> + shift
> + ;;
> + -i|--nodeid)
> + NODEID=1
> + shift
> + ;;
> + -h|--help)
> + usage
> + exit 0
> + ;;
> + \?)
> + echo "Invalid option"
> + exit 1
> + ;;
> + --)
> + shift;
> + break;
> + ;;
> + esac
> +done
> +
> +shift $((OPTIND -1))
> +
> +DN="$*"
> +node_dns=""
> +
> +if [ "$DN" = "" ]; then
> + node_dns=$(immfind -c SaClmNode)
> +else
> + node_dns="$DN"
> + if ! (immfind "$DN" > /dev/null 2>&1); then
> + echo "invalid dn"
> + exit $?
> + fi
> +fi
> +
> +list_adminstate()
> +{
> + value=$(immlist -a "saClmNodeAdminState" "$1" | cut -d = -f2)
> + if [ "$value" = "<Empty>" ]; then
> + echo " saClmNodeAdminState=$value"
> + elif [ "$value" -eq 1 ]; then
> + echo " saClmNodeAdminState=UNLOCKED(1)"
> + elif [ "$value" -eq 2 ]; then
> + echo " saClmNodeAdminState=LOCKED(2)"
> + elif [ "$value" -eq 3 ]; then
> + echo " saClmNodeAdminState=SHUTTING-DOWN(3)"
> + else
> + echo " saClmNodeAdminState=UNKNOWN($value)"
> + fi
> +}
> +
> +list_nodeid()
> +{
> + value=$(immlist -a "saClmNodeID" "$1" | cut -d = -f2)
> + if [ "$value" != "<Empty>" ]; then
> + in_hex=$(printf %05x "$value")
> + echo " saClmNodeID=$value(0x$in_hex) "
> + else
> + echo " saClmNodeID=$value"
> + fi
> +}
> +
> +list_membership()
> +{
> + value=$(immlist -a "saClmNodeIsMember" "$1" | cut -d = -f2)
> + if [ "$value" = "<Empty>" ]; then
> + echo " saClmNodeIsMember=$value"
> + elif [ "$value" -eq 1 ]; then
> + echo " saClmNodeIsMember=MEMBER(1)"
> + elif [ "$value" -eq 0 ]; then
> + echo " saClmNodeIsMember=NON_MEMBER(0)"
> + fi
> +}
> +
> +for node_dn in $node_dns; do
> + echo "$node_dn"
> + if [ $ADMIN -eq 0 ] && [ $MEMBERSHIP -eq 0 ] && [ $NODEID -eq 0 ]; then
> + list_adminstate "$node_dn"
> + list_membership "$node_dn"
> + list_nodeid "$node_dn"
> + else
> + if [ $ADMIN -eq 1 ]; then
> + list_adminstate "$node_dn"
> + fi
> + if [ $MEMBERSHIP -eq 1 ]; then
> + list_membership "$node_dn"
> + fi
> + if [ $NODEID -eq 1 ]; then
> + list_nodeid "$node_dn"
> + fi
> + fi
> +done
> +
> +exit 0
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel