aboutsummaryrefslogtreecommitdiffstats
path: root/aai-resources/src/main/scripts
diff options
context:
space:
mode:
authorKajur, Harish (vk250x) <vk250x@att.com>2020-02-29 22:17:05 -0500
committerjimmy <jf2512@att.com>2020-03-03 13:20:06 -0500
commit3a27813b663c34df52b2b1b50df7f0754dcfe134 (patch)
tree1f962778cd649286f70ae7ec8dbc5d868a668a7b /aai-resources/src/main/scripts
parent50315fe106b88e0cd556b8b6fab1dbdd4c9856a4 (diff)
Update resources to use aai-common changes
Issue-ID: AAI-2750 Change-Id: I33ea2b3d7b4b706edc59c3d45c9957d05effd306 Signed-off-by: Kajur, Harish (vk250x) <vk250x@att.com>
Diffstat (limited to 'aai-resources/src/main/scripts')
-rw-r--r--aai-resources/src/main/scripts/bulkprocess.sh8
-rw-r--r--aai-resources/src/main/scripts/common_functions.sh23
-rw-r--r--aai-resources/src/main/scripts/install/addManualData.sh85
-rw-r--r--aai-resources/src/main/scripts/updatePem.sh20
-rw-r--r--aai-resources/src/main/scripts/updateTool.sh24
-rw-r--r--aai-resources/src/main/scripts/vmExportCloudRegions.sh517
-rw-r--r--aai-resources/src/main/scripts/vmUpdateExport.sh75
-rw-r--r--aai-resources/src/main/scripts/vmValidateCloudRegions.sh328
8 files changed, 1019 insertions, 61 deletions
diff --git a/aai-resources/src/main/scripts/bulkprocess.sh b/aai-resources/src/main/scripts/bulkprocess.sh
index 5611bf7..c4bca27 100644
--- a/aai-resources/src/main/scripts/bulkprocess.sh
+++ b/aai-resources/src/main/scripts/bulkprocess.sh
@@ -43,10 +43,10 @@ if [ -z "$2" ]; then
exit 1
fi
-[[ "$XFROMAPPID" =~ [a-zA-Z0-9][a-zA-Z0-9]*-[a-zA-Z0-9][a-zA-Z0-9]* ]] || {
- echo "XFROMAPPID doesn't match the following regex [a-zA-Z0-9][a-zA-Z0-9]*-[a-zA-Z0-9][a-zA-Z0-9]*";
- exit 1;
-}
+case "${XFROMAPPID}" in
+ [a-zA-Z0-9][a-zA-Z0-9]*-[a-zA-Z0-9][a-zA-Z0-9]*) ;;
+ *) echo "XFROMAPPID doesn't match the following regex [a-zA-Z0-9][a-zA-Z0-9]*-[a-zA-Z0-9][a-zA-Z0-9]*"; exit 1; ;;
+esac
XTRANSID=$3
diff --git a/aai-resources/src/main/scripts/common_functions.sh b/aai-resources/src/main/scripts/common_functions.sh
index e99746d..14358d9 100644
--- a/aai-resources/src/main/scripts/common_functions.sh
+++ b/aai-resources/src/main/scripts/common_functions.sh
@@ -60,16 +60,19 @@ execute_spring_jar(){
JAVA_OPTS="$JAVA_OPTS -Dlogback.configurationFile=${logbackFile}";
export SOURCE_NAME=$(grep '^schema.source.name=' ${PROJECT_HOME}/resources/application.properties | cut -d"=" -f2-);
- # Needed for the schema ingest library beans
- eval $(grep '^schema\.' ${PROJECT_HOME}/resources/application.properties | \
- sed 's/^\(.*\)$/JAVA_OPTS="$JAVA_OPTS -D\1"/g' | \
- sed 's/${server.local.startpath}/${PROJECT_HOME}\/resources/g'| \
- sed 's/${schema.source.name}/'${SOURCE_NAME}'/g'\
- )
-
- JAVA_OPTS="${JAVA_OPTS} ${JAVA_POST_OPTS}";
-
- ${JAVA_HOME}/bin/java ${JVM_OPTS} ${JAVA_OPTS} -jar ${EXECUTABLE_JAR} "$@"
+ # Needed for the schema ingest library beans
+ eval $(egrep '^(schema|server)\.' ${PROJECT_HOME}/resources/application.properties | \
+ sed 's/^\(.*\)$/JAVA_OPTS="$JAVA_OPTS -D\1"/g' | \
+ sed 's/${server.local.startpath}/${PROJECT_HOME}\/resources/g'| \
+ sed 's/${schema.source.name}/'${SOURCE_NAME}'/g'\
+ )
+
+ JAVA_OPTS="${JAVA_OPTS} ${JAVA_POST_OPTS}";
+
+ "${JAVA_HOME}/bin/java" ${JVM_OPTS} ${JAVA_OPTS} -jar ${EXECUTABLE_JAR} "$@" || {
+ echo "Failed to run the tool $0 successfully";
+ exit 1;
+ }
}
# Prints the start date and the script that the user called
diff --git a/aai-resources/src/main/scripts/install/addManualData.sh b/aai-resources/src/main/scripts/install/addManualData.sh
index 016c5c3..bd7f7bd 100644
--- a/aai-resources/src/main/scripts/install/addManualData.sh
+++ b/aai-resources/src/main/scripts/install/addManualData.sh
@@ -75,41 +75,66 @@ error_exit () {
rel="/"$1"/"
k=0
-TEXT_PATH=$PROJECT_HOME/resources/etc/scriptdata/addmanualdata/*/*.txt
-COMMAND=`ls ${TEXT_PATH} | sort -f`
-
-ls ${TEXT_PATH} >/dev/null 2>&1
-if [ $? -ne 0 ]
+if [ "$1" = "tenant_isolation" ]
then
-echo "No manual data to add for $1";
-exit 0;
+ COMPLEX_TEXT_PATH=`find $PROJECT_HOME/resources/etc/scriptdata/addmanualdata/tenant_isolation/complex -name "*.txt" -print | sort -f`
+ ZONE_TEXT_PATH=`find $PROJECT_HOME/resources/etc/scriptdata/addmanualdata/tenant_isolation/zone -name "*.txt" -print | sort -f`
+ CR_TEXT_PATH=`find $PROJECT_HOME/resources/etc/scriptdata/addmanualdata/tenant_isolation/cloud-region -name "*.txt" -print | sort -f`
+ TENANT_TEXT_PATH=`find $PROJECT_HOME/resources/etc/scriptdata/addmanualdata/tenant_isolation/tenant -name "*.txt" -print | sort -f`
+ AZ_TEXT_PATH=`find $PROJECT_HOME/resources/etc/scriptdata/addmanualdata/tenant_isolation/availability-zone -name "*.txt" -print | sort -f`
+ PSERVER_TEXT_PATH=`find $PROJECT_HOME/resources/etc/scriptdata/addmanualdata/tenant_isolation/pserver -name "*.txt" -print | sort -f`
+ CUSTOMER_TEXT_PATH=`find $PROJECT_HOME/resources/etc/scriptdata/addmanualdata/tenant_isolation/customer -name "*.txt" -print | sort -f`
+ SERVICESUB_TEXT_PATH=`find $PROJECT_HOME/resources/etc/scriptdata/addmanualdata/tenant_isolation/service-subscription -name "*.txt" -print | sort -f`
+ SERVICE_TEXT_PATH=`find $PROJECT_HOME/resources/etc/scriptdata/addmanualdata/tenant_isolation/service -name "*.txt" -print | sort -f`
+
+ TEXT_PATH="${COMPLEX_TEXT_PATH} ${ZONE_TEXT_PATH} ${CR_TEXT_PATH} ${CUSTOMER_TEXT_PATH} ${SERVICE_TEXT_PATH} ${SERVICESUB_TEXT_PATH} ${TENANT_TEXT_PATH} ${AZ_TEXT_PATH} ${PSERVER_TEXT_PATH}"
+ COMMAND=${TEXT_PATH}
+elif [ "$1" = "vm_export" ]
+then
+ TEXT_PATH=$PROJECT_HOME/resources/etc/scriptdata/addmanualdata/vm_export/*.txt
+ COMMAND=`ls ${TEXT_PATH} | sort -rf`
+else
+ TEXT_PATH=$PROJECT_HOME/resources/etc/scriptdata/addmanualdata/*/*.txt
+ COMMAND=`ls ${TEXT_PATH} | sort -f`
fi
+#ls ${TEXT_PATH} >/dev/null 2>&1
+#if [ $? -ne 0 ]
+#then
+#echo "No manual data to add for $1";
+#exit 0;
+#fi
+
for filepath in ${COMMAND}
do
-contains $filepath $rel
-if [ $? -eq 0 ]
-then
-jsonfile=${filepath%???}json
-j=0
-while IFS=\n read -r i
-do
-echo "##### Begin putTool for $i ##### from file $filepath" | tee -a $OUTFILE
-resource=`echo $i | tr -d '\r'`
-errorcode=412
-$PROJECT_HOME/scripts/putTool.sh $resource $jsonfile $errorcode 1 0 na 1 >> $OUTFILE 2>&1 || error_exit "$resource" $j $filepath
-echo "##### End putTool for $resource #####" | tee -a $OUTFILE
-echo "Begin getTool for $resource" | tee -a $OUTFILE
-$PROJECT_HOME/scripts/getTool.sh $resource >> $OUTFILE 2>&1 || error_exit "$i" $j $filepath
-echo "End getTool for $resource" | tee -a $OUTFILE
-
-j=$(expr "$j" + 1)
-k=$(expr "$k" + 1)
-done < $filepath
-
-fi
-
-done
+ echo "File path ${filepath}"
+ contains $filepath $rel
+ if [ $? -eq 0 ]
+ then
+ jsonfile=${filepath%???}json
+ j=0
+ while IFS=\n read -r i
+ do
+ echo "##### Begin putTool for $i ##### from file $filepath" | tee -a $OUTFILE
+ resource=`echo $i | tr -d '\r'`
+ errorcode=412
+ $PROJECT_HOME/scripts/putTool.sh $resource $jsonfile $errorcode >> $OUTFILE 2>&1 || error_exit "$resource" $j $filepath
+ echo "##### End putTool for $resource #####" | tee -a $OUTFILE
+ contains $resource "relationship-list"
+ if [ $? -eq 0 ]
+ then
+ echo "skip getTool for $resource" | tee -a $OUTFILE
+ else
+ echo "Begin getTool for $resource" | tee -a $OUTFILE
+ $PROJECT_HOME/scripts/getTool.sh $resource >> $OUTFILE 2>&1 || error_exit "$i" $j $filepath
+ echo "End getTool for $resource" | tee -a $OUTFILE
+ fi
+
+ j=$(expr "$j" + 1)
+ k=$(expr "$k" + 1)
+ done < $filepath
+ fi
+ done
if [ $k -eq 0 ]
then
echo "No manual data to add for release $1";
diff --git a/aai-resources/src/main/scripts/updatePem.sh b/aai-resources/src/main/scripts/updatePem.sh
index 6e6ac6f..81ba65b 100644
--- a/aai-resources/src/main/scripts/updatePem.sh
+++ b/aai-resources/src/main/scripts/updatePem.sh
@@ -27,12 +27,24 @@ start_date;
check_user;
source_profile;
-CERTPATH=$PROJECT_HOME/resources/etc/auth/
+prop_file=$PROJECT_HOME/resources/application.properties
+
+CERTPATH=${PROJECT_HOME}/resources/etc/auth/
KEYNAME=aaiClientPrivateKey.pem
CERTNAME=aaiClientPublicCert.pem
+CERTIFICATE_FILE=${CERTPATH}aai-client-cert.p12
+
+CERTMAN_PATH=`grep ^server.certs.location $prop_file |cut -d'=' -f2 |tr -d "\015"`
+if [ -z $CERTMAN_PATH ]; then
+ echo "Property [server.certs.location] not found in file $prop_file, continuing with default"
+ pw=$(execute_spring_jar org.onap.aai.util.AAIConfigCommandLinePropGetter "" "aai.keystore.passwd" 2> /dev/null | tail -1)
+else
+ # Assume AAF certificate container use
+ pw=$(< ${CERTMAN_PATH}/.password)
+ CERTIFICATE_FILE=${CERTMAN_PATH}/certificate.pkcs12
+fi
-pw=$(execute_spring_jar org.onap.aai.util.AAIConfigCommandLinePropGetter "" "aai.keystore.passwd" 2> /dev/null | tail -1)
-openssl pkcs12 -in ${CERTPATH}/aai-client-cert.p12 -out $CERTPATH$CERTNAME -clcerts -nokeys -passin pass:$pw
-openssl pkcs12 -in ${CERTPATH}/aai-client-cert.p12 -out $CERTPATH$KEYNAME -nocerts -nodes -passin pass:$pw
+openssl pkcs12 -in ${CERTIFICATE_FILE} -out $CERTPATH$CERTNAME -nokeys -nodes -passin pass:$pw
+openssl pkcs12 -in ${CERTIFICATE_FILE} -nocerts -out $CERTPATH$KEYNAME -nodes -passin pass:$pw
end_date;
exit 0
diff --git a/aai-resources/src/main/scripts/updateTool.sh b/aai-resources/src/main/scripts/updateTool.sh
index e79edd1..ce0a8f6 100644
--- a/aai-resources/src/main/scripts/updateTool.sh
+++ b/aai-resources/src/main/scripts/updateTool.sh
@@ -129,36 +129,34 @@ fi
#or
#'physical-location-id:complex-id, city:New York'
thirdarg=$3
-isjson = false
+isjson=false
if [[ "$thirdarg" == *json || "$thirdarg" == *JSON ]]; then
- isjson = true
+ isjson=true
else
#For Usage 2, format input into JSON string format
JSONSTRING="{"
INPUT=$3
#replace any spaces with %20
- INPUT=${INPUT// /%20}
+ INPUT=$(echo ${INPUT} | sed 's/ /%20/g');
- for i in ${INPUT//,/ };
+ for i in $(echo ${INPUT} | sed 's/,/ /g');
do
#change any %20 back to space )
- i=${i//%20/ }
- #echo "after change to space=$i"
+ i=$(echo ${i} | sed 's/%20/ /g');
#trim modstring to remove any beginning spaces (" city" becomes "city")
- i="${i##*( )}"
-
+ i=$(echo ${i} | sed 's/^[ \t]*//');
+
#add JSON quotes
MODSTRING=" \"$i\","
- MODSTRING=${MODSTRING//[:]/'": "'}
- #echo "MODSTRING=$MODSTRING"
+ MODSTRING=$(echo ${MODSTRING} | sed 's/:/": "/g');
- JSONSTRING+=$MODSTRING
+ JSONSTRING="${JSONSTRING}${MODSTRING}"
done
JSONSTRING="${JSONSTRING%?}"
- JSONSTRING+=" }"
+ JSONSTRING="${JSONSTRING} }"
echo "JSON string is $JSONSTRING"
fi
@@ -225,4 +223,4 @@ else
fi
echo `date` " Done $0, returning $RC"
-exit $RC \ No newline at end of file
+exit $RC
diff --git a/aai-resources/src/main/scripts/vmExportCloudRegions.sh b/aai-resources/src/main/scripts/vmExportCloudRegions.sh
new file mode 100644
index 0000000..95ec969
--- /dev/null
+++ b/aai-resources/src/main/scripts/vmExportCloudRegions.sh
@@ -0,0 +1,517 @@
+#!/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=========================================================
+###
+
+#
+# vmExportCloudRegions.sh -- This tool is used to generate script payloads of
+# vm and interfaces linked to a specific cloud-owner to be imported
+# to the same cloud-region in a instance with its own data model and existing
+# dependent objects. This script maps predefined objects and relationsships
+# beteen the two instances. An archive is generated and manually
+# copied to the target instance. A second script, vmValidateCloudRegions.sh,
+# is run on the target instance that applies validations and replaces
+# values needed in the generated scripss.
+# generated files. The script takes 2 arguments
+
+# usage: $0 <cloud-owner> <target-basepath> <target-version>
+# <cloud-owner> is the cloud-region-owner
+# <target-version> is the replacement to be applied to aai/$version in
+# resource links from the source instance.
+
+# scriptdata/addmanualdata/vm_export/payload is populated with the target
+# files, that include json/txt files applied by addManualData script and tx
+# files which represent validations to be applied before running addManualData.
+# The naming convention of json/txt files ensures the ordering used to correctly
+# apply dependent objects. The archive is generated in
+# scriptdata/addmanualdata/vm_export/archive
+
+addTemplates() {
+ jq -n --arg related vlan-tag --arg rlabel org.onap.relationships.inventory.Uses \
+--arg rlink /aai/v1x/cloud-infrastructure/cloud-regions/cloud-region/change-this-to-cloud-owner/change-this-to-cloud-region-id/vlan-ranges/vlan-range/change-this-to-vlan-range-id/vlan-tags/vlan-tag/change-this-to-vlan-tag-id \
+'{"related-to": "\($related)", "relationship-label": "\($rlabel)", "related-link": "\($rlink)"}' > $TARGETDIR/vlan-tag-relationship-template.json
+
+ jq -n --arg related lag-interface --arg rlabel org.onap.relationships.inventory.Uses \
+--arg rlink /aai/v1x/cloud-infrastructure/pservers/pserver/change-this-to-hostname/lag-interfaces/lag-interface/bond1 \
+'{"related-to": "\($related)", "relationship-label": "\($rlabel)", "related-link": "\($rlink)"}' > $TARGETDIR/lag-interface-relationship-template.json
+
+ jq -n --arg dsl "cloud-region('cloud-owner','change-this-to-cloud-owner')('cloud-region-id','change-this-to-cloud-region-id') > vlan-range > [ vlan-tag*('vlan-id-inner', change-this-to-inner), vlan-tag*('vlan-id-outer', change-this-to-outer) ]" \
+'{"dsl": "\($dsl)"}' > $TARGETDIR/vlantagquery-template.json
+}
+
+getFileSize() {
+ echo `wc -c < $1`
+}
+
+getCloudRegions() {
+ res="cloud-infrastructure/cloud-regions?cloud-owner="$1"&format=pathed"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh "${res}" | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '.results'`
+ if [ "$hasResults" = null ]; then
+ hasResults="No-cloud-region"
+ fi
+ if [ "$hasResults" = "No-cloud-region" ]; then
+ echo "No-cloud-region"
+ else
+ echo $cloudres | jq '.results|.[]|."resource-link"' | sed -e 's/\"//g' | cut -d"/" -f4-
+ fi
+}
+
+getTenants() {
+ res=""$1"/tenants?format=pathed"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '.results'`
+ if [ "$hasResults" = null ]; then
+ hasResults="No-tenant"
+ fi
+ if [ "$hasResults" = "No-tenant" ]; then
+ echo "No-tenant"
+ else
+ echo $cloudres | jq '.results|.[]|."resource-link"' | sed -e 's/\"//g' | cut -d"/" -f4-
+ fi
+}
+
+getVservers() {
+ res=""$1"/vservers?format=pathed"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '.results'`
+ if [ "$hasResults" = null ]; then
+ hasResults="No-vserver"
+ fi
+ if [ "$hasResults" = "No-vserver" ]; then
+ echo "No-vserver"
+ else
+ echo $cloudres | jq '.results|.[]|."resource-link"' | sed -e 's/\"//g' | cut -d"/" -f4-
+ fi
+}
+
+getLInterfaces() {
+ res=""$1"/l-interfaces?format=pathed"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '.results'`
+ if [ "$hasResults" = null ]; then
+ hasResults="No-l-interface"
+ fi
+ if [ "$hasResults" = "No-l-interface" ]; then
+ echo "No-l-interface"
+ else
+ echo $cloudres | jq '.results|.[]|."resource-link"' | sed -e 's/\"//g' | cut -d"/" -f4-
+ fi
+}
+
+getVlans() {
+ res=""$1"/vlans?format=pathed"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '.results'`
+ if [ "$hasResults" = null ]; then
+ hasResults="No-vlan"
+ fi
+ if [ "$hasResults" = "No-vlan" ]; then
+ echo "No-vlan"
+ else
+ echo $cloudres | jq '.results|.[]|."resource-link"' | sed -e 's/\"//g' | cut -d"/" -f4-
+ fi
+}
+
+getSriovVfs() {
+ res=""$1"/sriov-vfs?format=pathed"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '.results'`
+ if [ "$hasResults" = null ]; then
+ hasResults="No-sriov-vfs"
+ fi
+ if [ "$hasResults" = "No-sriov-vfs" ]; then
+ echo "No-sriov-vfs"
+ else
+ echo $cloudres | jq '.results|.[]|."resource-link"' | sed -e 's/\"//g' | cut -d"/" -f4-
+ fi
+}
+
+getTenant() {
+ res=""$1"?depth=0"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ filepath=$TARGETDIR/$regioncnt-$tenantcnt-tenant
+ echo "/"$1 > ${filepath}.txt
+ echo $cloudres | jq 'del(."resource-version")' > ${filepath}.json
+ echo $filepath
+}
+
+getVserver() {
+ res=""$1"?depth=0"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ filepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-1-vserver
+ echo "/"$1 > ${filepath}.txt
+ echo $cloudres | jq 'del(."resource-version")|del(."relationship-list")' > ${filepath}.json
+ validatepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-vserver-validate-notexists
+ echo "/"$1 > ${validatepath}.tx
+ echo $filepath
+}
+
+getVfModule() {
+ res=""$1"?depth=0"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ heatStackId=`echo $cloudres | jq '."heat-stack-id"' | sed 's/\"//g'`
+ if [ "$heatStackId" = "null" ]
+ then
+ echo $heatStackId
+ else
+ heatStackIdUri=`echo $heatStackId | jq -sRr @uri`
+ uri=`echo ${heatStackIdUri%???}`
+ filepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-1-instance-group-$vfmodulecnt
+ echo "/network/instance-groups/instance-group/$uri" > ${filepath}.txt
+ # no need to validate, since instance-group is created if not present
+ #validatepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-vserver-validate-vfmodule-$vfmodulecnt.tx
+ echo $cloudres | jq '{"heat-stack-id": ."heat-stack-id", "vf-module-name": ."vf-module-name"} | .["id"] = ."heat-stack-id" | .["instance-group-name"] = ."vf-module-name" | del(."heat-stack-id", ."vf-module-name") | .+ {"instance-group-type": "HEAT-STACK"}' > ${filepath}.json
+ echo $uri
+ fi
+}
+
+getVserverRelatedTo() {
+ res=""$1"?depth=0"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '."relationship-list"'`
+ if [ "$hasResults" = null ]; then
+ hasResults="No-related-vf-module-or-pserver"
+ fi
+ if [ "$hasResults" = "No-related-vf-module-or-pserver" ]; then
+ echo "No-related-vf-module-or-pserver"
+ else
+ validatepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-vserver-validate.tx
+ echo $cloudres | jq '[ ."relationship-list".relationship[] | select(."related-to" | contains("pserver")) ]' > ${validatepath}
+ sz=`getFileSize $validatepath`
+ pservercnt=0
+ if [ $sz = "3" ]; then
+ rm ${validatepath}
+ else
+ PSERVERS=`cat ${validatepath} | jq '.[]|."related-link"'|sed -e 's/\"//g' | cut -d"/" -f4-`
+ rm ${validatepath}
+ for pserver in ${PSERVERS}
+ do
+ validatepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-vserver-validate-pserver-$pservercnt-exists.tx
+ echo $pserver > $validatepath
+ filepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-0-vserver-related-to-pserver-$pservercnt
+ #echo $cloudres | jq '."relationship-list".relationship[] | select(."related-to" | contains("pserver"))' > ${filepath}.json
+ echo $cloudres | jq '."relationship-list".relationship[] | select(."related-to" | contains("pserver"))' | jq 'del(."relationship-data")' | jq 'del(."related-to-property")' > ${filepath}.json
+ echo "/"$1/relationship-list/relationship > ${filepath}.txt
+ pservercnt=$(expr "$pservercnt" + 1)
+ done
+ fi
+ validatepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-vserver-validate.tx
+ echo $cloudres | jq '[ ."relationship-list".relationship[] | select(."related-to" | contains("vf-module")) ]' > ${validatepath}
+ sz=`getFileSize ${validatepath}`
+ if [ $sz = "3" ]; then
+ rm ${validatepath}
+ else
+ VFMODULES=`cat ${validatepath} | jq '.[]|."related-link"'|sed -e 's/\"//g' | cut -d"/" -f4-`
+ vfmodulecnt=0
+ rm ${validatepath}
+ for vfmodule in ${VFMODULES}
+ do
+ heatId=`getVfModule $vfmodule`
+ # add instance-group and keep pserver relationships
+ if [ `expr $pservercnt` -ne 0 ]; then
+ filepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-0-vserver-related-to-instance-group
+ echo $cloudres | jq '."relationship-list".relationship |= .+ [{ "related-to": "instance-group", "relationship-label": "org.onap.relationships.inventory.MemberOf", "related-link": "/aai/v1x/network/instance-groups/instance-group/change-this-instance-group-id" }]' | jq '."relationship-list".relationship[] | select(."related-to" | contains("instance-group"))' | sed "s#change-this-instance-group-id#$heatId#" > ${filepath}.json
+echo $cloudres | jq '."relationship-list".relationship |= .+ [{ "related-to": "instance-group", "relationship-label": "org.onap.relationships.inventory.MemberOf", "related-link": "/aai/v1x/network/instance-groups/instance-group/change-this-instance-group-id" }]' | jq '."relationship-list".relationship[] | select(."related-to" | contains("instance-group"))'
+ echo "/"$1/relationship-list/relationship > ${filepath}.txt
+ vfmodulecnt=$(expr "$vfmodulecnt" + 1)
+ fi
+ done
+ fi
+ echo $filepath
+ fi
+}
+
+getLInterface() {
+ res=""$1"?depth=0"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ filepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-$linterfacecnt-1-l-interface
+ echo "/"$1 > ${filepath}.txt
+ echo $cloudres | jq 'del(."resource-version")|del(."relationship-list")' > ${filepath}.json
+ echo "/"$1 > ${filepath}.txt
+ echo $cloudres | jq 'del(."resource-version")|del(."relationship-list")' > ${filepath}.json
+ echo $filepath
+}
+
+getVlan() {
+ res=""$1"?depth=0"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ filepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-$linterfacecnt-0-$vlancnt-vlan-validate-vlantag.tx
+ echo $cloudres | jq 'del(."resource-version")|del(."relationship-list")' > ${filepath}
+ relpath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-$linterfacecnt-0-$vlancnt-vlantag-related-to
+ echo "$2/relationship-list/relationship" > ${relpath}.txt
+ # payload
+ cloudreg=`cat $TARGETDIR/$regioncnt-cloud-region.validate.exists.tx`
+ owner=`echo $cloudreg | cut -f 5 -d "/"`
+ cid=`echo $cloudreg | cut -f 6 -d "/"`
+ cat $TEMPLATEDIR/vlan-tag-relationship-template.json | sed -e "s/change-this-path-element/$targetVersion/" -e "s/change-this-to-cloud-owner/$owner/" -e "s/change-this-to-cloud-region-id/$cid/" > ${relpath}.json
+ echo $filepath
+}
+
+getSriovVf() {
+ res=""$1"?depth=0"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ filepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-$linterfacecnt-$sriovvfcnt-1-sriov-vf
+ echo "/"$1 > ${filepath}.txt
+ echo $cloudres | jq 'del(."resource-version")|del(."relationship-list")' > ${filepath}.json
+ echo $filepath
+}
+
+getLagInterfaceRelatedTo() {
+ filepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-$linterfacecnt-0-laginterface-related-to
+ pserverpath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-vserver-validate-pserver-0-exists.tx
+ if [ -s $pserverpath ];
+ then
+ server=`cat $pserverpath`
+ echo "$1/relationship-list/relationship" > ${filepath}.txt
+ hostname=`echo $server | cut -f4 -d"/"`
+ cat $TEMPLATEDIR/lag-interface-relationship-template.json | sed -e "s/change-this-path-element/$targetVersion/" -e "s/change-this-to-hostname/$hostname/" > ${filepath}.json
+ validatepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-$linterfacecnt-laginterface-validate-exists
+ echo "/cloud-infrastructure/pservers/pserver/$hostname/lag-interfaces/lag-interface/bond1" > ${validatepath}.tx
+ fi
+}
+
+getSriovVfRelatedTo() {
+ res=""$1"?depth=0"
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '."relationship-list"'`
+ if [ "$hasResults" = null ]; then
+ hasResults="No-related-to-sriov-pf"
+ fi
+ if [ "$hasResults" = "No-related-to-sriov-pf" ]; then
+ echo "No-related-to-sriov-pf"
+ else
+ validatepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-$linterfacecnt-$sriovvfcnt-sriovvf-validate-sriov-pf.tx
+ #echo "getSrioVfRelatedTo:" $validatepath $res >> /tmp/test.out
+ #echo "getSrioVfRelatedTo:" $validatepath $cloudres >> /tmp/test.out
+ echo $cloudres | jq '[ ."relationship-list".relationship[] | select(."related-to" | contains("sriov-pf")) ]' > ${validatepath}
+ sz=`getFileSize ${validatepath}`
+ sriovpfcnt=0
+ if [ $sz = "3" ]; then
+ rm ${validatepath}
+ else
+ SRIOVPFS=`cat ${validatepath} | jq '.[]|."related-link"'|sed -e 's/\"//g' | cut -d"/" -f4-`
+ rm ${validatepath}
+ for sriovpf in ${SRIOVPFS}
+ do
+ validatepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-$linterfacecnt-$sriovvfcnt-sriovvf-validate-sriov-pf-$sriovpfcnt.tx
+ echo $sriovpf > $validatepath
+ #echo "getSrioVfRelatedTo:" $validatepath $sriovpf >> /tmp/test.out
+ filepath=$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-$linterfacecnt-$sriovvfcnt-0-sriovvf-related-to-sriov-pf-$sriovpfcnt
+ echo $cloudres | jq '."relationship-list".relationship[] | select(."related-to" | contains("sriov-pf"))' | jq 'del(."relationship-label")' | jq 'del(."relationship-data")' > ${filepath}.json
+ echo "/"$1/relationship-list/relationship > ${filepath}.txt
+ #echo "getSrioVfRelatedTo:" $filepath $cloudres >> /tmp/test.out
+ sriovpfcnt=$(expr "$sriovpfcnt" + 1)
+ done
+ fi
+ echo $filepath
+ fi
+}
+
+addValidateCloudRegion() {
+ filepath=$TARGETDIR/$regioncnt-cloud-region
+ echo "/"$1 > ${filepath}.validate.exists.tx
+}
+
+addValidateVserver() {
+ filepath=$TARGETDIR/$regioncnt-cloud-region
+ echo "/"$1 > ${filepath}.validate.exists.tx
+}
+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)
+
+TS=$(date "+%Y_%m_%d_%H_%M_%S")
+
+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
+TARGETDIR=$PROJECT_HOME/resources/etc/scriptdata/addmanualdata/vm_export/payload
+TEMPLATEDIR=$TARGETDIR
+mkdir -p $TARGETDIR
+rm -f $TARGETDIR/*
+
+if [ "$#" -ne 3 ]; then
+ echo "usage: $0 <cloud-owner> <target-basepath> <target-verson>"
+ exit 1
+fi
+
+addTemplates
+
+targetVersion="$2\/$3"
+
+echo "${TS}, getting vms and interfaces for cloud-region-owner: $1 with targetVersion $2/$3"
+regioncnt=0
+tenantcnt=0
+vservercnt=0
+linterfacecnt=0
+vlancnt=0
+sriovvfcnt=0
+totaltenants=0
+totalvms=0
+totalinterfaces=0
+totalvlans=0
+totalsriovvfs=0
+
+missingvms=0
+missinginterfaces=0
+missingvlans=0
+missingsriovvfs=0
+
+
+
+CLOUDS=`getCloudRegions $1`
+for cloud in ${CLOUDS}
+do
+ if [ $cloud = "No-cloud-region" ]; then
+ echo "No cloud-region found for owner " $1
+ else
+ addValidateCloudRegion $cloud
+ TENANTS=`getTenants $cloud`
+ for tenant in ${TENANTS}
+ do
+ if [ $tenant = "No-tenant" ]; then
+ echo "No tenant found for cloud-region " $cloud
+ else
+ #echo "Process tenant " $tenant
+ add=`getTenant $tenant`
+ #echo "adding tenant: " $add
+ VSERVERS=`getVservers $tenant`
+ for vserver in ${VSERVERS}
+ do
+ if [ $vserver = "No-vserver" ]; then
+ #echo "No vserver found for tenant " $tenant
+ missingvms=$(expr "$missingvms" + 1)
+ else
+ #echo "Process vserver " $vserver
+ add=`getVserver $vserver`
+ #echo "adding vserver: " $add
+ add=`getVserverRelatedTo $vserver`
+ #echo "adding vserver: related-to " $add
+ LINTERFACES=`getLInterfaces $vserver`
+ linterfacecnt=0
+ for linterface in ${LINTERFACES}
+ do
+ if [ $linterface = "No-l-interface" ]; then
+ #echo "No l-interface found for vserver " $vserver
+ missinginterfaces=$(expr "$missinginterfaces" + 1)
+ else
+ #echo "Process l-interface " $linterface
+ add=`getLInterface $linterface`
+ #echo "adding l-interface: " $add
+ VLANS=`getVlans $linterface`
+ for vlan in ${VLANS}
+ do
+ if [ $vlan = "No-vlan" ]; then
+ #echo "No vlan found for l-interface " $linterface
+ missingvlans=$(expr "$missingvlans" + 1)
+ else
+ #echo "Process vlan " $vlan
+ add=`getVlan $vlan $linterface`
+ #echo "adding vlan: " $add
+ vlancnt=$(expr "$vlancnt" + 1)
+ totalvlans=$(expr "$totalvlans" + 1)
+ fi
+ done
+ SRIOVVFS=`getSriovVfs $linterface`
+ for sriovvf in ${SRIOVVFS}
+ do
+ if [ $sriovvf = "No-sriov-vfs" ]; then
+ #echo "No sriov-vf found for l-interface " $linterface
+ # need to add relationship for pserver/lag-interface bond1
+ getLagInterfaceRelatedTo $linterface
+ missingsriovvfs=$(expr "$missingsriovvfs" + 1)
+ else
+ #echo "Processing l-interface" $linterface >> /tmp/test.out
+ #echo "Processing with sriov-vf" $sriovvf >> /tmp/test.out
+ add=`getSriovVf $sriovvf`
+ #echo "adding sriovvf: " $add
+ add=`getSriovVfRelatedTo $sriovvf`
+ #echo "adding sriovvf: related-to " $add
+ sriovvfcnt=$(expr "$sriovvfcnt" + 1)
+ totalsriovvfs=$(expr "$totalsriovvfs" + 1)
+ fi
+ done
+ vlancnt=0
+ sriovvfcnt=0
+ linterfacecnt=$(expr "$linterfacecnt" + 1)
+ totalinterfaces=$(expr "$totalinterfaces" + 1)
+ fi
+ done
+ linterfacecnt=0
+ # check that vserver related-to is present
+ if [ -e "$TARGETDIR/$regioncnt-$tenantcnt-$vservercnt-0-vserver-related-to-instance-group.json" ]; then
+ vservercnt=$(expr "$vservercnt" + 1)
+ totalvms=$(expr "$totalvms" + 1)
+ else
+ rm $TARGETDIR/$regioncnt-$tenantcnt-$vservercnt*
+ echo "no related vf-module, skip export for $vserver"
+ fi
+ fi
+ done
+ vservercnt=0
+ tenantcnt=$(expr "$tenantcnt" + 1)
+ totaltenants=$(expr "$totaltenants" + 1)
+ fi
+ done
+ tenantcnt=0
+ regioncnt=$(expr "$regioncnt" + 1)
+ fi
+done
+sed -i "s/aai\/v1./$targetVersion/g" $TARGETDIR/*related-to*.json
+echo "Total cloud-regions to process " $regioncnt
+echo "Total tenants to add " $totaltenants
+echo "Total vms to add " $totalvms
+#echo "Total interfaces to add " $totalinterfaces
+#echo "Total vlans to add " $totalvlans
+#echo "Total sriovvfs to add " $totalsriovvfs
+
+TS=$(date "+%Y_%m_%d_%H_%M_%S")
+ARCHIVEDIR=$PROJECT_HOME/resources/etc/scriptdata/addmanualdata/vm_export/archive
+if [ ! -d ${ARCHIVEDIR} ]
+then
+ mkdir -p ${ARCHIVEDIR}
+ chown aaiadmin:aaiadmin ${ARCHIVEDIR}
+ chmod u+w ${ARCHIVEDIR}
+fi
+cd ${TARGETDIR}
+tar c * -f ${ARCHIVEDIR}/vmExportArchive_${TS}.tar --exclude=payload
+if [ $? -ne 0 ]
+then
+ echo " Unable to tar ${TARGETDIR}"
+ exit 1
+fi
+cd ${ARCHIVEDIR}
+gzip ${ARCHIVEDIR}/vmExportArchive_${TS}.tar
+
+if [ $? -ne 0 ]
+then
+ echo " Unable to gzip ${ARCHIVE_DIRECTORY}/vmExportArchive_${TS}.tar"
+ exit 1
+fi
+echo "Completed successfully: ${ARCHIVE_DIRECTORY}/vmExportArchive_${TS}.tar"
+exit 0 \ No newline at end of file
diff --git a/aai-resources/src/main/scripts/vmUpdateExport.sh b/aai-resources/src/main/scripts/vmUpdateExport.sh
new file mode 100644
index 0000000..f492d2c
--- /dev/null
+++ b/aai-resources/src/main/scripts/vmUpdateExport.sh
@@ -0,0 +1,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 \ No newline at end of file
diff --git a/aai-resources/src/main/scripts/vmValidateCloudRegions.sh b/aai-resources/src/main/scripts/vmValidateCloudRegions.sh
new file mode 100644
index 0000000..a8189e3
--- /dev/null
+++ b/aai-resources/src/main/scripts/vmValidateCloudRegions.sh
@@ -0,0 +1,328 @@
+#!/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=========================================================
+###
+
+# this script now requires a release parameter.
+# the tool finds and sorts *.txt files within the
+# resources/etc/scriptdata/addmanualdata/$release directory containing
+# one resource to be added to the graph. The directory contains a second
+# file with the same name, but the extension is .json. This json file
+# is passed to the PutTool as the payload. The parameters passed to the
+# PutTool will have 412 failures ignored. After calling the PutTool, the
+# GetTool is called to include the object put into the graph.
+# this script is run at every installation, logging the manual data applied.
+
+# Returns 0 if the specified string contains the specified substring,
+# otherwise returns 1.
+contains() {
+ string="$1"
+ substring="$2"
+ if test "${string#*$substring}" != "$string"
+ then
+ return 0 # $substring is in $string
+ else
+ return 1 # $substring is not in $string
+ fi
+}
+
+updateRenames () {
+ echo $1 >> $PAYLOADDIR/rename.txt
+}
+
+renamefiles() {
+ FILESTORENAME=`ls $PAYLOADDIR/$1*$2`
+ for f in $FILESTORENAME
+ do
+ mv $f $f.bak
+ done
+
+}
+
+. /etc/profile.d/aai.sh
+PROJECT_HOME=/opt/app/aai-resources
+
+PROGNAME=$(basename $0)
+OUTFILE=$PROJECT_HOME/logs/misc/${PROGNAME}.log.$(date +\%Y-\%m-\%d)
+#OUTFILE=/c/temp/${PROGNAME}.log.$(date +\%Y-\%m-\%d)
+
+TS=$(date "+%Y-%m-%d %H:%M:%S")
+
+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
+
+error_exit () {
+ echo "${PROGNAME}: failed for ${1:-"Unknown error"} on cmd $2 in $3" 1>&2
+ echo "${PROGNAME}: failed for ${1:-"Unknown error"} on cmd $2 in $3" >> $OUTFILE
+# exit ${2:-"1"}
+}
+
+notfound="not-found"
+found="found"
+
+getCloudRegion() {
+ res=$1?depth=0
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '."cloud-owner"'`
+ if [ "$hasResults" = null ]; then
+ echo $notfound
+ else
+ echo $found
+ fi
+}
+
+getVserver() {
+ res=$1?depth=0
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '."vserver-id"'`
+ if [ "$hasResults" = null ]; then
+ echo $notfound
+ else
+ echo $found
+ fi
+}
+
+getPserver() {
+ res=$1?depth=0
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '."hostname"'`
+ if [ "$hasResults" = null ]; then
+ echo $notfound
+ else
+ echo $found
+ fi
+}
+
+getSriovPf() {
+ res=$1?depth=0
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '."pf-pci-id"'`
+ if [ "$hasResults" = null ]; then
+ echo $notfound
+ else
+ echo $found
+ fi
+}
+
+getLagInterface() {
+ res=$1?depth=0
+ cloudres=`$PROJECT_HOME/scripts/getTool.sh $res | sed '1d;$d'`
+ hasResults=`echo $cloudres | jq '."interface-name"'`
+ if [ "$hasResults" = null ]; then
+ echo $notfound
+ else
+ echo $found
+ fi
+}
+
+getVlanTag() {
+ vlanindex=`echo $1 | cut -f 10 -d "/" | cut -f 1-6 -d "-"`
+ cloudindex=`echo $vlanindex | cut -f 1 -d "-"`
+ cloudregion=`cat $PAYLOADDIR/$cloudindex-cloud-region.validate.exists.tx`
+ cowner=`echo $cloudregion | cut -f 5 -d "/"`
+ cid=`echo $cloudregion | cut -f 6 -d "/"`
+ inner=`cat $1 | jq '."vlan-id-inner"' | sed 's/\"//g'`
+ outer=`cat $1 | jq '."vlan-id-outer"' | sed 's/\"//g'`
+ cat $TEMPLATEDIR/vlantagquery-template.json | sed -e "s/change-this-to-cloud-owner/$cowner/" -e "s/change-this-to-cloud-region-id/$cid/" -e "s/change-this-to-inner/$inner/" -e "s/change-this-to-outer/$outer/" > $PAYLOADDIR/$vlanindex-vlan-validate-vlantag.json
+ $PROJECT_HOME/scripts/putTool.sh "/dsl?format=pathed" $PAYLOADDIR/$vlanindex-vlan-validate-vlantag.json -display > $PAYLOADDIR/$vlanindex-vlan-validate-vlantag-result.json 2>&1
+ cloudres=`cat $PAYLOADDIR/$vlanindex-vlan-validate-vlantag-result.json | sed '1,4d;$d'`
+ hasResults=`echo $cloudres | jq '.results'`
+ if [ "$hasResults" = null ]; then
+ hasResults=$notfound
+ fi
+ if [ "$hasResoults" = $notfound ]; then
+ echo $notfound
+ else
+ len=`echo $cloudres | jq '.results | length'`
+ if [ $len -eq 0 ];
+ then
+ echo "vlan-tag-not-found"
+ elif [ $len -gt 1 ];
+ then
+ echo "multiple-vlan-tag-found"
+ else
+ vlantag=`echo $cloudres | jq '.results|.[]|."resource-link"' | sed -e 's/\"//g' | cut -d"/" -f4-`
+ rangeId=`echo $vlantag| cut -f 8 -d "/"`
+ tagId=`echo $vlantag | cut -f 11 -d "/"`
+ sed -i -e "s/change-this-to-vlan-range-id/$rangeId/" -e "s/change-this-to-vlan-tag-id/$tagId/" $PAYLOADDIR/$vlanindex-vlantag-related-to.json
+ echo $found
+ fi
+ fi
+
+}
+
+PAYLOADDIR=$PROJECT_HOME/resources/etc/scriptdata/addmanualdata/vm_export
+TEMPLATEDIR=$PROJECT_HOME/resources/etc/scriptdata/addmanualdata/vm_export
+COMMAND=`find $PAYLOADDIR -name "*cloud-region.validate.exists.tx" -print | sort -f`
+
+skipValidations=$1
+if [ -z $skipValidations ]; then
+ skipValidations="1"
+fi
+
+validatecnt=0
+validcnt=0
+
+echo "${TS}, starting validations"
+
+for filepath in ${COMMAND}
+do
+ cloudindex=`echo ${filepath} | cut -f 10 -d "/" | cut -f 1 -d "-"`
+ while IFS=\n read -r i
+ do
+ cloudregion=`getCloudRegion $i`
+ if [[ $cloudregion == $found ]]
+ then
+ validcnt=$(expr $validcnt + 1)
+ else
+ echo "not importing vms under region $i"
+ renamefiles "$cloudindex" "txt"
+ renamefiles "$cloudindex" "tx"
+ fi
+ validatecnt=$(expr $validatecnt + 1)
+ done < $filepath
+done
+
+skipvalidate=false
+contains $skipValidations "vserver-validate-notexists"
+if [ $? -eq 0 ] ; then
+ skipvalidate=true
+fi
+
+COMMAND=`find $PAYLOADDIR -name "*vserver-validate-notexists.tx" -print | sort -f`
+for filepath in ${COMMAND}
+do
+ cloudindex=`echo ${filepath} | cut -f 10 -d "/" | cut -f 1-3 -d "-"`
+ while IFS=\n read -r i
+ do
+ vserver=`getVserver $i`
+ if [[ $vserver == $notfound || $skipvalidate = true ]]
+ then
+ validcnt=$(expr $validcnt + 1)
+ else
+ echo "vm exists, $i not importing vm"
+ updateRenames "$cloudindex"
+ fi
+ validatecnt=$(expr $validatecnt + 1)
+ done < $filepath
+done
+
+COMMAND=`find $PAYLOADDIR -name "*vserver-validate-pserver-*-exists.tx" -print | sort -f`
+
+for filepath in ${COMMAND}
+do
+ cloudindex=`echo ${filepath} | cut -f 10 -d "/" | cut -f 1-3 -d "-"`
+ while IFS=\n read -r i
+ do
+ pserver=`getPserver $i`
+ if [[ $pserver == $found ]]
+ then
+ validcnt=$(expr $validcnt + 1)
+ else
+ echo "missing pserver, $i, not importing related vms"
+ updateRenames "$cloudindex"
+ fi
+ validatecnt=$(expr $validatecnt + 1)
+ done < $filepath
+done
+
+COMMAND=`find $PAYLOADDIR -name "*sriovvf-validate-sriov-pf-*.tx" -print | sort -f`
+
+for filepath in ${COMMAND}
+do
+ cloudindex=`echo ${filepath} | cut -f 10 -d "/" | cut -f 1-3 -d "-"`
+ while IFS=\n read -r i
+ do
+ pserver=`getSriovPf $i`
+ if [[ $pserver == $found ]]
+ then
+ validcnt=$(expr $validcnt + 1)
+ else
+ echo "missing sriov-pf, $i, not importing related vms"
+ updateRenames "$cloudindex"
+ fi
+ validatecnt=$(expr $validatecnt + 1)
+ done < $filepath
+done
+
+COMMAND=`find $PAYLOADDIR -name "*laginterface-validate-exists.tx" -print | sort -f`
+
+for filepath in ${COMMAND}
+do
+ cloudindex=`echo ${filepath} | cut -f 10 -d "/" | cut -f 1-3 -d "-"`
+ while IFS=\n read -r i
+ do
+ laginterface=`getLagInterface $i`
+ if [[ $laginterface == $found ]]
+ then
+ validcnt=$(expr $validcnt + 1)
+ else
+ echo "missing lag-interface, $i, not importing related vms"
+ updateRenames "$cloudindex"
+ fi
+ validatecnt=$(expr $validatecnt + 1)
+ done < $filepath
+done
+
+COMMAND=`find $PAYLOADDIR -name "*vlan-validate-vlantag.tx" -print | sort -f`
+
+for filepath in ${COMMAND}
+do
+ cloudindex=`echo ${filepath} | cut -f 10 -d "/" | cut -f 1-3 -d "-"`
+ vlantag=`getVlanTag ${filepath}`
+ if [[ $vlantag == $found ]]
+ then
+ validcnt=$(expr $validcnt + 1)
+ elif [[ $vlantag == "vlan-tag-not-found" ]]
+ then
+ echo "no matching vlan-tag, $filepath, not importing related vms"
+ updateRenames "$cloudindex"
+ elif [[ $vlantag == "multiple-vlan-tag-found" ]]
+ then
+ echo "multipe vlan-tag matches, $filepath, not importing related vms"
+ updateRenames "$cloudindex"
+ else
+ echo "missing vlan-tag, $filepath, not importing related vms"
+ updateRenames "$cloudindex"
+ fi
+ validatecnt=$(expr $validatecnt + 1)
+done
+
+if [ -s $PAYLOADDIR/rename.txt ];
+then
+ cat $PAYLOADDIR/rename.txt | sed 's/^$//' | sort -u > $PAYLOADDIR/renamed.txt
+
+ while IFS=\n read -r i
+ do
+ renamefiles $i "txt"
+ renamefiles $i "tx"
+ done < "$PAYLOADDIR/renamed.txt"
+ rm $PAYLOADDIR/rename*
+fi
+TS=$(date "+%Y-%m-%d %H:%M:%S")
+echo "${TS}, validations completed"
+echo "Total validations done " $validatecnt
+echo "Total validations passed " $validcnt
+
+exit 0