aboutsummaryrefslogtreecommitdiffstats
path: root/aai-resources/src/main/scripts/vmUpdateExport.sh
blob: f492d2cd92ff1dde24dbc3216892541cb12cd737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/ksh
#
###
# ============LICENSE_START=======================================================
# org.onap.aai
# ================================================================================
# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
###

#
# vmUpdateExport.sh  -- This tool updates the files generated in A&AI to
# match what is expected in narad
# The script takes no arguments

addTemplates() {
	jq -n --arg dsl "pserver('hostname','change-this-to-hostname') > p-interface > [ sriov-pf* ]" \
'{"dsl": "\($dsl)"}' > sriovpfquery-template.json
}

COMMON_ENV_PATH=$( cd "$(dirname "$0")" ; pwd -P )
. ${COMMON_ENV_PATH}/common_functions.sh

. /etc/profile.d/aai.sh

PROJECT_HOME=/opt/app/aai-resources
PROGNAME=$(basename $0)

CHECK_USER="aaiadmin"
userid=$( id | cut -f2 -d"(" | cut -f1 -d")" )
if [ "${userid}" != $CHECK_USER ]; then
    echo "You must be  $CHECK_USER to run $0. The id used $userid."
    exit 1
fi
VMEXPORTDIR=$PROJECT_HOME/resources/etc/scriptdata/addmanualdata/vm_export
cd $VMEXPORTDIR
addTemplates
URIS=`cat *vserver-validate-pserver*tx | sort -u`
for uri in $URIS
do
        hostname=`echo $uri | cut -d "/" -f 4`
	shortname=`echo $hostname | cut -d "." -f1`
	sed -i -e "s#relationship-value\": \"$hostname#relationship-value\" : \"$shortname#" *json
	sed -i -e "s#property-value\": \"$hostname#property-value\" : \"$shortname#" *json
	sed -i -e "s#pserver/$hostname#pserver/$shortname#" *json
	sed -i -e "s#pserver/$hostname#pserver/$shortname#" *tx
	cat sriovpfquery-template.json | sed -e "s/change-this-to-hostname/$shortname/" > sriovf.query.$shortname.json
	res=`$PROJECT_HOME/scripts/putTool.sh "/dsl?format=pathed" sriovf.query.$shortname.json -display | sed '1d;$d'`
	echo $res | jq '.results|.[]|."resource-link"' | sed -e 's/\"//g' | cut -d"/" -f4- >  sriovf.result.$shortname
done
txfiles=`ls *sriovvf-validate-sriov-pf-*tx`
for txfile in $txfiles
do
	uri=`cat $txfile`
        hostname=`echo $uri | cut -d "/" -f 4`
	pfPciId=`echo $uri | cut -d "/" -f 10`
	interfacename=`echo $uri | cut -d "/" -f 7`
	newuri=`grep $pfPciId sriovf.result.$hostname`
	#echo "old uri " + $uri
	#echo "new uri " + $newuri
	sed -i -e "s#$uri#$newuri#" *sriovvf-related-to-sriov-pf*.json
	sed -i -e "s#$uri#$newuri#" *sriovvf-validate-sriov-pf*.tx
done