2014-04-15 13:53:08 +00:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
|
|
|
|
# Get all the parameters
|
|
|
|
for i in $@
|
|
|
|
do
|
|
|
|
if [ "$paramname" = "USER" ]; then
|
|
|
|
USER=$i
|
|
|
|
paramname=
|
|
|
|
fi
|
|
|
|
if [ "$paramname" = "PW" ]; then
|
|
|
|
PW=$i
|
|
|
|
paramname=
|
|
|
|
fi
|
|
|
|
if [ "$paramname" = "HOST" ]; then
|
|
|
|
HOST=$i
|
|
|
|
paramname=
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $i = '-u' ]; then
|
|
|
|
paramname=USER
|
|
|
|
fi
|
|
|
|
if [ $i = '-p' ]; then
|
|
|
|
paramname=PW
|
|
|
|
fi
|
|
|
|
if [ $i = '-h' ]; then
|
|
|
|
paramname=HOST
|
|
|
|
fi
|
|
|
|
if [ $i = '-c' ]; then
|
|
|
|
cert=yes
|
|
|
|
fi
|
|
|
|
if [ $i = '-t' ]; then
|
|
|
|
token=yes
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
# display the usage message
|
|
|
|
function usage {
|
|
|
|
echo "Usage:"
|
|
|
|
echo " xcatws-test.sh -u <USER> -p <pw> [-t]"
|
|
|
|
echo " xcatws-test.sh -u <USER> -p <pw> -h <FQDN - Full hostname of server> [-c] [-t]"
|
|
|
|
echo " -u The username of xCAT user which is used to access xCAT resource"
|
|
|
|
echo " -p The password of username"
|
|
|
|
echo " <FQDN of xCAT MN> The fully qualified hostname of xCAT management node. It can be an IP if using -k."
|
|
|
|
echo " -c Check the server identity. The server certificate authentication must be enabled."
|
|
|
|
echo " -t Using token authentication method."
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$USER" = "" ] || [ "$PW" = "" ]; then
|
|
|
|
echo "Error: Miss username or password"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$cert" = "yes" ] && [ "$HOST" = "" ]; then
|
|
|
|
echo "Error: -c must be used with -h that user needs specify the FQDN of xCAT MN"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$HOST" = "" ]; then
|
|
|
|
HOST="127.0.0.1"
|
2014-02-27 00:34:16 +00:00
|
|
|
fi
|
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
|
2014-02-27 00:34:16 +00:00
|
|
|
ctype='-H Content-Type:application/json'
|
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
# Perform the REST API request
|
|
|
|
function REST {
|
|
|
|
METHOD=$1 # it should be GET/PUT/POST/DELETE
|
|
|
|
SRC=$2 # The resource path like /nodes/node1
|
|
|
|
DATA=$3 # The operation data for PUT/POST/DELETE
|
|
|
|
if [ "$DATA" != "" ]; then
|
|
|
|
datamsg="$ctype -d $DATA"
|
|
|
|
fi
|
|
|
|
if [ "$cert" = "yes" ]; then
|
|
|
|
if [ "$token" = "yes" ]; then
|
|
|
|
CMD="curl -X $METHOD --cacert /tmp/ca-cert.pem -H X-Auth-Token:$TOKENID $datamsg https://$HOST/xcatws$SRC?pretty=1"
|
|
|
|
else
|
|
|
|
CMD="curl -X $METHOD --cacert /tmp/ca-cert.pem $datamsg https://$HOST/xcatws$SRC?pretty=1&userName=$USER&password=$PW"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ "$token" = "yes" ]; then
|
|
|
|
CMD="curl -X $METHOD -k -H X-Auth-Token:$TOKENID $datamsg https://$HOST/xcatws$SRC?pretty=1"
|
|
|
|
else
|
|
|
|
CMD="curl -X $METHOD -k $datamsg https://$HOST/xcatws$SRC?pretty=1&userName=$USER&password=$PW"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "-------------------------------------------------------------------------------"
|
|
|
|
echo "Run: [$RESTMSG]"
|
|
|
|
echo " $CMD"
|
|
|
|
echo "Output:"
|
|
|
|
`$CMD 2>/dev/null >/tmp/xcatws-test.log`
|
|
|
|
cat "/tmp/xcatws-test.log"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
ERROR=`grep "errorcode" "/tmp/xcatws-test.log"`
|
|
|
|
if [ "$ERROR" != "" ]; then
|
|
|
|
echo "FAILED to continue. See the error message in 'error' section."
|
|
|
|
echo ""
|
|
|
|
exit 2
|
|
|
|
fi
|
2014-02-27 00:34:16 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
function PUT {
|
|
|
|
SRC=$1
|
|
|
|
}
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
# echo debug message
|
|
|
|
echo "***********************************************************"
|
|
|
|
echo "** Username: $USER"
|
|
|
|
echo "** Password: $PW"
|
|
|
|
echo "** Hostname: $HOST"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
# get the CA of server certificate
|
|
|
|
if [ "$cert" = "yes" ]; then
|
|
|
|
rm -f /tmp/ca-cert.pem
|
|
|
|
cd /tmp
|
|
|
|
wget http://$HOST/install/postscripts/ca/ca-cert.pem 2>1 1>/dev/null
|
|
|
|
echo "** Using CA /tmp/ca-cert.pem for server certificate checking"
|
|
|
|
fi
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
# get a token
|
|
|
|
if [ "$token" = "yes" ]; then
|
|
|
|
TOKENID=$(curl -X POST -k "https://$HOST/xcatws/tokens?pretty=1" -H Content-Type:application/json --data "{\"userName\":\"$USER\",\"password\":\"$PW\"}" 2>/dev/null | grep '"id"' | awk -F: {'print $2'} | awk -F \" {'print $2'})
|
|
|
|
echo "** Using Token: $TOKENID to authenticate"
|
|
|
|
fi
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
echo "***********************************************************"
|
|
|
|
echo ""
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
# clean the env
|
|
|
|
rmdef -t node restapinode[1-9] 1>/dev/null 2>1
|
|
|
|
rmdef -t group restapi 1>/dev/null 2>1
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
# get all resources
|
|
|
|
RESTMSG="Get all available resource"
|
|
|
|
REST GET "/"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
# test global conf
|
|
|
|
RESTMSG="Get all global configuration resource"
|
|
|
|
REST GET "/globalconf"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Change the global configuration domain to cluster.com"
|
|
|
|
REST PUT "/globalconf/attrs/domain" '{"domain":"cluster.com"}'
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Get the global configuration domain"
|
|
|
|
REST GET "/globalconf/attrs/domain"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
# test node create/change/list/delete
|
|
|
|
RESTMSG="Create node restapinode1"
|
|
|
|
REST POST "/nodes/restapinode1" '{"groups":"restapi","arch":"x86_64","mgt":"ipmi","netboot":"xnba"}'
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Display the node restapinode1"
|
|
|
|
REST GET "/nodes/restapinode1"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Change the attributes for node restapinode1"
|
|
|
|
REST PUT "/nodes/restapinode1" '{"mgt":"fsp","netboot":"yaboot"}'
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Display the node restapinode1"
|
|
|
|
REST GET "/nodes/restapinode1"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Delete node restapinode1"
|
|
|
|
REST DELETE "/nodes/restapinode1"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
# test multiple nodes manipulation
|
|
|
|
RESTMSG="Create node restapinode1 and restapinode2"
|
|
|
|
REST POST "/nodes/restapinode1,restapinode2" '{"groups":"restapi","arch":"x86_64","mgt":"ipmi","netboot":"xnba"}'
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Display the node restapinode1 and restapinode2"
|
|
|
|
REST GET "/nodes/restapinode1,restapinode2"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Change the attributes for node restapinode1 and restapinode2"
|
|
|
|
REST PUT "/nodes/restapinode1,restapinode2" '{"mgt":"hmc","netboot":"grub2"}'
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Display the node restapinode1 and restapinode2"
|
|
|
|
REST GET "/nodes/restapinode1,restapinode2"
|
2014-03-16 23:54:00 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Display all the nodes in the cluster"
|
|
|
|
REST GET "/nodes"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
# test group
|
|
|
|
RESTMSG="Display the group restapi"
|
|
|
|
REST GET "/groups/restapi"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Change attributes for group restapi"
|
|
|
|
REST PUT "/groups/restapi" '{"os":"rh7"}'
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Display the group restapi"
|
|
|
|
REST GET "/groups/restapi"
|
2014-02-27 00:34:16 +00:00
|
|
|
|
2014-04-15 13:53:08 +00:00
|
|
|
RESTMSG="Display the nodes in group restapi"
|
|
|
|
REST GET "/nodes/restapi"
|
2014-02-23 09:13:15 +00:00
|
|
|
|