Hi!
Some comments:
1) Could you try to align the command parameters to be more similar to
the existing immfind, immlist and immadm commands? I.e.:
- A (non-option) parameter shall be a DN
- Other things like lock and unlock shall be options (preceded by a
dash, or a long option preceded by two dashes). Compare with immadm
which has two options -o and -O for specifying the admin op, either by
number or name.
2) I think the commands clm-find and clm-state should do something
sensible when called without any arguments. When called without
arguments, clm-find should probably list all configured nodes and
clm-state should print the state of all nodes.
3) Can we really have more than one CLM cluster configured at the same
time? Maybe instead of saying "clm-find cluster" we could have an option
for printing the name of the (one and only) cluster, e.g. "clm-find
--cluster-name". So instead of having a mandatory first parameter that
shall be either "cluster" or "node", clm-find would have an optional
parameter "--cluster-name" and without this option it will by default
list all the nodes.
4) The -t option to clm-adm doesn't seem to work? I tried "clm-adm -t 50
lock safNode=PL-5,safCluster=myClmCluster" and got "error - wrong number
of arguments"
5) Maybe all commands shall have a -t option? You can pass the time-out
value on to the immfind and immlist commands.
6) Please run shellcheck (see www.shellcheck.net). I got the following
warnings:
-------------
Warnings for clm-adm:
Line 19:
echo "usage: $(basename $0) [-t timeout]
<lock|unlock|shutdown|reset> <object DN>"
^-- SC2086: Double quote to prevent globbing
and word splitting.
Line 26:
if [ $# -ne 2 -a $# -ne 4 ]; then
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not
well defined.
-------------
Warnings for clm-find:
Line 27:
if [ $# -ne 1 -a $# -ne 2 ] || [ "$1" = "-h" -o "$1" = "--help" ]; then
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not
well defined.
^-- SC2166: Prefer [ p ]
|| [ q ] as [ p -o q ] is not well defined.
Line 32:
if [ $# -eq 2 -a "$1" = "cluster" ]; then
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not
well defined.
Line 37:
if [ $# -eq 2 -a "$1" = "node" -a "$2" != "locked" -a "$2" != "unlocked"
-a "$2" != "member" -a "$2" != "nonmember" ]
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
^-- SC2166: Prefer [
p ] && [ q ] as [ p -a q ] is not well defined.
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not
well defined.
^-- SC2166: Prefer [ p ] && [ q ] as [ p
-a q ] is not well defined.
Line 59:
if [ "$2" = "locked" -o "$2" = "unlocked" ]; then
^-- SC2166: Prefer [ p ] || [ q ] as [ p -o q
] is not well defined.
Line 61:
if [ "$2" = "locked" -a "$value" -eq 2 ] || [ "$2" = "unlocked"
-a "$value" -eq 1 ]; then
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a
q ] is not well defined.
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Line 69:
if [ "$2" = "nonmember" -a "$value" -eq 0 ] || [ "$2" = "member"
-a "$value" -eq 1 ]; then
^-- SC2166: Prefer [ p ] && [ q ] as [ p
-a q ] is not well defined.
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
-------------
Warnings for clm-state:
Line 28:
if [ $# -ne 2 ] || [ "$1" = "-h" -o "$1" = "--help" ]; then
^-- SC2166: Prefer [ p ] || [ q ] as [
p -o q ] is not well defined.
Line 33:
if [ "$2" != "adm" -a "$2" != "mem" -a "$2" != "id" -a "$2" != "all" ]; then
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is
not well defined.
^-- SC2166: Prefer [ p ] && [ q ]
as [ p -a q ] is not well defined.
^-- SC2166: Prefer
[ p ] && [ q ] as [ p -a q ] is not well defined.
Line 43:
if [ $? -ne 0 ]; then
^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not
indirectly with $?.
regards,
Anders Widell
On 04/05/2017 02:31 PM, [email protected] wrote:
> opensaf.spec.in | 3 +
> src/clm/Makefile.am | 5 ++
> src/clm/tools/clm-adm | 67 ++++++++++++++++++++++++++++++
> src/clm/tools/clm-find | 83 +++++++++++++++++++++++++++++++++++++
> src/clm/tools/clm-state | 107
> ++++++++++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 265 insertions(+), 0 deletions(-)
>
>
> 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.
>
> diff --git a/opensaf.spec.in b/opensaf.spec.in
> --- a/opensaf.spec.in
> +++ b/opensaf.spec.in
> @@ -1444,6 +1444,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
> --- 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
> --- /dev/null
> +++ b/src/clm/tools/clm-adm
> @@ -0,0 +1,67 @@
> +#! /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 timeout] <lock|unlock|shutdown|reset>
> <object DN>"
> + echo ""
> + echo " -t: command timeout in seconds (default=60)"
> + echo " Note: specify options in same order as given in usage."
> + echo ""
> +}
> +
> +if [ $# -ne 2 -a $# -ne 4 ]; then
> + usage
> + exit 1
> +fi
> +
> +if [ $# -eq 4 ]; then
> + if [ "$1" = "-t" ]; then
> + CMD=$3
> + args="$1 $2 $4"
> + else
> + echo "Invalid option or command as not per usage"
> + usage
> + exit 1
> + fi
> +elif [ $# -eq 2 ]; then
> + CMD=$1
> + args=$2
> +fi
> +
> +UNLOCK=1
> +LOCK=2
> +SHUTDOWN=3
> +RESET=4
> +case $CMD in
> + "unlock")
> + immadm -o $UNLOCK "$args"
> + ;;
> + "lock")
> + immadm -o $LOCK "$args"
> + ;;
> + "shutdown")
> + immadm -o $SHUTDOWN "$args"
> + ;;
> + "reset")
> + immadm -o $RESET "$args"
> + ;;
> + *)
> + echo "invalid admin operation: $CMD"
> + exit 1
> +esac
> +exit $?
> +
> diff --git a/src/clm/tools/clm-find b/src/clm/tools/clm-find
> new file mode 100644
> --- /dev/null
> +++ b/src/clm/tools/clm-find
> @@ -0,0 +1,83 @@
> +#! /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") <cluster|node>
> [<locked|unlocked|member|nonmember>]"
> + echo ""
> + echo " cluster|node: CLM class names"
> + echo " locked|unlocked|member|nonmember: list nodes with this status."
> + echo ""
> +}
> +
> +if [ $# -ne 1 -a $# -ne 2 ] || [ "$1" = "-h" -o "$1" = "--help" ]; then
> + usage
> + exit 1
> +fi
> +
> +if [ $# -eq 2 -a "$1" = "cluster" ]; then
> + usage
> + exit 1
> +fi
> +
> +if [ $# -eq 2 -a "$1" = "node" -a "$2" != "locked" -a "$2" != "unlocked" -a
> "$2" != "member" -a "$2" != "nonmember" ]
> +then
> + usage
> + exit 1
> +fi
> +
> +CLASS=""
> +case "$1" in
> + cluster)
> + CLASS="SaClmCluster"
> + ;;
> + node)
> + CLASS="SaClmNode"
> + ;;
> + *)
> + usage
> + exit 1
> +esac
> +
> +list_with_states ()
> +{
> + for i in $(immfind -c "$1"); do
> + if [ "$2" = "locked" -o "$2" = "unlocked" ]; then
> + value=$(immlist -a "saClmNodeAdminState" "$i" | cut -d = -f2)
> + if [ "$2" = "locked" -a "$value" -eq 2 ] || [ "$2" = "unlocked" -a
> "$value" -eq 1 ]; then
> + echo "$i"
> + fi
> + else
> + value=$(immlist -a "saClmNodeIsMember" "$i" | cut -d = -f2)
> + if [ "$value" = "<Empty>" ]; then
> + value=0
> + fi
> + if [ "$2" = "nonmember" -a "$value" -eq 0 ] || [ "$2" = "member" -a
> "$value" -eq 1 ]; then
> + echo "$i"
> + fi
> + fi
> + done
> +}
> +
> +if [ $# -eq 1 ]; then
> + immfind -c "$CLASS"
> +else
> + list_with_states "$CLASS" "$2"
> +fi
> +
> +exit $?
> +
> diff --git a/src/clm/tools/clm-state b/src/clm/tools/clm-state
> new file mode 100644
> --- /dev/null
> +++ b/src/clm/tools/clm-state
> @@ -0,0 +1,107 @@
> +#! /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") <dn|all> <attr>"
> + echo ""
> + echo " dn|all: to list for dn or for all nodes."
> + echo " attr:<adm|mem|id|all> for adminstate, membership, nodeId and
> all three."
> + echo ""
> +}
> +node_dns=""
> +
> +if [ $# -ne 2 ] || [ "$1" = "-h" -o "$1" = "--help" ]; then
> + usage
> + exit 1
> +fi
> +
> +if [ "$2" != "adm" -a "$2" != "mem" -a "$2" != "id" -a "$2" != "all" ]; then
> + usage
> + exit 1
> +fi
> +
> +if [ "$1" = "all" ]; then
> + node_dns=$(immfind -c SaClmNode)
> +else
> + node_dns=$1
> + immfind "$1" > /dev/null 2>&1
> + if [ $? -ne 0 ]; then
> + echo "invalid dn"
> + exit $?
> + fi
> +fi
> +
> +if [ "$2" = "all" ]; then
> + states="adm mem id"
> +else
> + states=$2
> +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"
> + for state in $states; do
> + if [ "$state" = "adm" ]; then
> + list_adminstate "$node_dn"
> + elif [ "$state" = "mem" ]; then
> + list_membership "$node_dn"
> + else
> + list_nodeid "$node_dn"
> + fi
> + done
> +done
> +exit $?
> +
------------------------------------------------------------------------------
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