Ofir Sonsino | 1cfb087 | 2018-01-31 17:19:00 +0200 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | usage() { echo -e "Usage: $0 [-o <ADD|DELETE|GET>] [-p <FILE_PATH>]\nCSV File Format: VNF_UUID,VNF_invariantUUID,workflowName" 1>&2; exit 1; } |
| 3 | while getopts ":o:p:" opt; do |
| 4 | case ${opt} in |
| 5 | o) |
| 6 | OPERATION=${OPTARG} |
| 7 | ;; |
| 8 | p) |
| 9 | FILE=${OPTARG} |
| 10 | ;; |
| 11 | *) |
| 12 | usage |
| 13 | ;; |
| 14 | esac |
| 15 | done |
| 16 | shift $((OPTIND-1)) |
| 17 | if [ -z "${FILE}" ] || [ -z "${OPERATION}" ]; then |
| 18 | usage |
| 19 | fi |
| 20 | if [ ${OPERATION} != 'ADD' ] && [ ${OPERATION} != 'DELETE' ] && [ ${OPERATION} != 'GET' ]; then |
| 21 | usage |
| 22 | fi |
| 23 | if [ ${OPERATION} = 'ADD' ]; then |
| 24 | OPERATION='POST' |
| 25 | fi |
| 26 | URL="http://127.0.0.1:8080/vid/change-management/vnf_workflow_relation" |
| 27 | if [ ${OPERATION} = 'GET' ]; then |
| 28 | echo "Sending request for get all vnf_workflow_relation" |
| 29 | echo -e "------------------------\nwget output:" |
| 30 | wget -nv -O "${FILE}" "${URL}" |
| 31 | RC=$? |
| 32 | echo "---------------------------" |
| 33 | if [ $RC -eq 0 ]; then |
| 34 | echo "Result saved to ${FILE}" |
| 35 | else |
| 36 | echo "Failed to get vnf to workflows relations" |
| 37 | fi |
| 38 | else |
| 39 | BODY=$(cat ${FILE} | awk ' BEGIN { FS=","; print " {\"workflowsDetails\" : [ "} { gsub(/ /, "", $1) ; gsub(/ /, "", $2) ; gsub(/^[ \t]+/,"",$3); gsub(/[ \t]+$/,"",$3); printf "%s{\"vnfDetails\":{\"UUID\":\"%s\",\"invariantUUID\":\"%s\"},\"workflowName\":\"%s\"}",separator,$1,$2,$3 ;separator = ", ";} END { printf " ]} "}') |
| 40 | echo "Sending request: ${OPERATION} ${BODY}" |
| 41 | echo -e "------------------------\nwget output:" |
| 42 | wget --method="${OPERATION}" --body-data="${BODY}" --header=Content-Type:application/json --content-on-error -nv -O - "${URL}" |
| 43 | RC=$? |
| 44 | echo "---------------------------" |
| 45 | if [ $RC -ne 0 ]; then |
| 46 | echo "Failed to ADD/DELETE vnf to workflows relations" |
| 47 | fi |
| 48 | fi |
| 49 | |