Edit CIB

You can use the following shell script to edit the cib.xml file while heartbeat is running. It will verify the file afterwards and give an option to edit it again when verify fails.

cibvi.sh

#!/bin/sh
#
# cibvi.sh - cib.xml editor
#
# April 5, 2007 Vincent van Gelder - vincent@dauphin-mm.nl
#

CIBADMIN="/usr/sbin/cibadmin"
EDITOR=${EDITOR:-"/usr/bin/vim"}
CRMVERIFY=/usr/sbin/crm_verify

case "$1" in 
        'resources'|'constraints'|'nodes'|'crm_config'|'status' )
                SECTION=$1
        ;;
        *)
                echo "Unknown section"
                echo "Valid values are: nodes, resources, constraints, crm_config, status"
                exit 1
        ;;
esac

TMPFILE=`mktemp -t cib_$SECTION.XXXXXXXXXX` || exit 1


function cleanup {
        rm -f $TMPFILE
}

function get_cib {
        echo "Get cib..."
        $CIBADMIN -o $SECTION -Q > $TMPFILE
#       $CIBADMIN -o $SECTION -Q > cib_$SECTION.previous.xml
}

function cib_edit {
        $EDITOR $TMPFILE
        echo "Verify..."
        $CRMVERIFY -x $TMPFILE 2>&1 | grep ERROR && cib_fail
        echo "Write cib"
        $CIBADMIN -o $SECTION -R -x $TMPFILE
        echo "Done."
        cleanup
        exit
}

function cib_fail {
        echo "Verify failed..."
        read -p "[e]dit, [c]ontinu: " ans
        case "$ans" in
                e|E) cib_edit;;
                c|C) cleanup;
                         exit;;
                *) cib_fail;;
        esac
}

get_cib
cib_edit

CIB/EditCIB (last edited 2007-04-05 14:06:37 by Vincent)