1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/tools/villas-api.sh
Alexandra b39e4a0ace feat: new smu node-type
Signed-off-by: Alexandra <alexandra.bach@eonerc.rwth-aachen.de>
2025-01-14 14:42:39 +00:00

33 lines
850 B
Bash
Executable file

#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
# SPDX-License-Identifier: Apache-2.0
# Check if all required commands exist
if ! command -v curl &> /dev/null; then
echo "curl could not be found"
exit 1
fi
if ! command -v jq &> /dev/null; then
echo "jq could not be found"
exit 1
fi
if [ $# -lt 1 ]; then
echo "usage: villas-api ACTION [REQUEST-JSON]"
exit 1
fi
ACTION=$1
REQUEST=${2:-\{\}}
ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
ENDPOINT=${ENDPOINT:-http://localhost:80/api/v1}
echo "Issuing API request: action=${ACTION}, id=${ID}, request=${REQUEST}, endpoint=${ENDPOINT}"
curl -s -X POST --data "{
\"action\" : \"${ACTION}\",
\"id\": \"${ID}\",
\"request\": ${REQUEST}
}" ${ENDPOINT} | jq .