aboutsummaryrefslogtreecommitdiffstats
path: root/aai-resources/src/main/scripts/vmExportCloudRegions.sh
blob: a8d14e30be687f06f8fe6ea1b0b09bb210a4cebd (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
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



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