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
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to