blob: 69cb595b5e8f5bbd5e6dbb9d6b3003c467575068 [file] [log] [blame]
Ofir Sonsino1cfb0872018-01-31 17:19:00 +02001#!/bin/bash
2usage() { echo -e "Usage: $0 [-o <ADD|DELETE|GET>] [-p <FILE_PATH>]\nCSV File Format: VNF_UUID,VNF_invariantUUID,workflowName" 1>&2; exit 1; }
3while 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
15done
16shift $((OPTIND-1))
17if [ -z "${FILE}" ] || [ -z "${OPERATION}" ]; then
18 usage
19fi
20if [ ${OPERATION} != 'ADD' ] && [ ${OPERATION} != 'DELETE' ] && [ ${OPERATION} != 'GET' ]; then
21 usage
22fi
23if [ ${OPERATION} = 'ADD' ]; then
24 OPERATION='POST'
25fi
26URL="http://127.0.0.1:8080/vid/change-management/vnf_workflow_relation"
27if [ ${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
38else
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
48fi
49