Bug 806, System test exception handled!
[osm/devops.git] / descriptor-packages / tools / generate_descriptor_pkg.sh
1 #!/bin/bash
2
3 ############################################################################
4 # Copyright 2016 RIFT.io Inc #
5 # #
6 # Licensed under the Apache License, Version 2.0 (the "License"); #
7 # you may not use this file except in compliance with the License. #
8 # You may obtain a copy of the License at #
9 # #
10 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # #
12 # Unless required by applicable law or agreed to in writing, software #
13 # distributed under the License is distributed on an "AS IS" BASIS, #
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15 # See the License for the specific language governing permissions and #
16 # limitations under the License. #
17 ############################################################################
18
19 #
20 # This shell script is used to create a descriptor package
21 # The main functions of this script include:
22 # - Generate checksums.txt file
23 # - Generate a tar.gz file
24 # This script can be used to create the required folders for
25 # a descriptor package and a template descriptor
26
27 # Usage: generate_descriptor_pkg.sh <base-directory> <package-directory>
28
29 # Descriptor names should be
30 # - (nsd|vnfd).(yaml|yml|json|xml)
31 # - *_(nsd|vnfd).(yaml|yml|json|xml)
32 # - *_(nsd|vnfd)_*.(yaml|yml|json|xml)
33 # - (nsd|vnfd)/*.(yaml|yml|json|xml)
34 #
35
36 SCRIPTNAME=`basename $0`
37
38 # From https://osm.etsi.org/wikipub/index.php/Release_0_Data_Model_Details
39 # Supported folders for VNFD
40 # cloud_init - Rel 4.3, not yet part of OSM
41 VNFD_FOLDERS=(images scripts icons charms cloud_init)
42
43 # Supported folders for NSD
44 # OSM document specifies (ns|vnf)-config folder, while Rel 4.3
45 # is using (ns|vnf)_config.
46 NSD_FOLDERS=(scripts charms icons ns_config vnf_config)
47
48 # Other files allowed in the descriptor base directory
49 ALLOWED_FILES=(README)
50
51 DESC_TYPES=(vnfd nsd)
52 DESC_EXTN=(yml yaml json xml)
53 CHKSUM='checksums.txt'
54
55 VERBOSE=false
56 DRY_RUN=false
57 CREATE=false
58 RM="--remove-files"
59 DEBUG=false
60
61 ARCHIVE=false
62 CREATE_NSD=false
63 VENDOR='OSM'
64 INTF_TYPE='PARAVIRT'
65 VCPU=2
66 MEMORY=4096
67 STORAGE=10
68 INTERFACES=1
69
70 function usage() {
71 cat <<EOF
72 Usage:
73 $SCRIPTNAME [-t <type>] [-N] [-c] [base-directory] <package-name>
74
75 -h|--help : show this message
76
77 -t|--package-type <nsd|vnfd> : Descriptor package type
78 is NSD or VNFD. Script will try to
79 determine the type if not provided.
80 Default is vnfd for create-folders.
81
82 -d|--destination-dir <destination directory>: Directory to create the
83 archived file.
84 Default is base-directory
85
86 -N|--no-remove-files : Do not remove the package files after creating
87 archive
88
89 Options specifc for create descriptor:
90
91 -c|--create-folder : Create folder with the structure for the
92 package type using the base-dir and package-dir
93 and a descriptor template
94
95 -a|--archive: Create package for the descriptor
96
97 --nsd : Generate NSD descriptor package also.
98
99 --vendor : Vendor name for descriptor. Default OSM
100
101 --interface-type : Interface type [PARAVIRT|SR-IOV|PCI-PASSTHROUGH|E1000]
102 Default PARAVIRT
103
104 VM Flavour options:
105
106 --vcpu : Virtual CPU count. Default 2
107
108 --memory : Memory for VM in MB. Default 4096MB
109
110 --storage : Storage size for VM in GB. Default 10GB
111
112 VDU Parameters:
113
114 --image : Location URI of the image
115
116 --cloud-init-file : Cloud init file
117
118 --cloud-init : Cloud init script. Will be ignored if
119 cloud-init-file is specified
120
121 --interfaces : Number of external interfaces in additon to OM-MGMT. Default 1.
122
123 End of create descriptor specific options
124
125 -v| --verbose : Generate progress details
126
127 -n| --dry-run : Validate the package dir
128
129 base-dir : Directory where the archive file or folders are created,
130 if destination directory is not specified.
131 Default is current directory
132
133 package-name : The descriptor name (full path if base-dir not specified)
134 EOF
135 }
136
137 CP_TYPE='VPORT'
138 function get_cp_type() {
139 case ${INTF_TYPE} in
140 PARAVIRT ) CP_TYPE='VPORT';;
141 SR-IOV ) CP_TYPE='VPORT';;
142 PCI-PASSTHROUGH ) CP_TYPE='VPORT';;
143 OM-MGMT ) CP_TYPE='VPORT';;
144 E1000 ) CP_TYPE='VPORT';;
145 * ) echo "ERROR: Unknown interface type ${INTF_TYPE}"; exit 1;;
146 esac
147 }
148
149 # Get pci number starting from 0x0a
150 get_pci() {
151 printf '%02x' $((10 + $1)) | tr '[:upper:]' '[:lower:]'
152 }
153
154 function write_readme() {
155 dir=$1
156 file=${dir}/README
157 date=$(date)
158
159 cat >$file <<EOF
160 Descriptor created by OSM descriptor package generated
161 Created on $date
162 EOF
163
164 }
165
166 function write_vnfd_tmpl() {
167 name=$(basename $1)
168 desc_file="${name}.yaml"
169
170 cat >$desc_file <<EOF
171 vnfd:vnfd-catalog:
172 vnfd:
173 - id: ${name}
174 name: ${name}
175 short-name: ${name}
176 description: Generated by OSM package generator
177 vendor: ${VENDOR}
178 version: '1.0'
179
180 # Place the logo as png in icons directory and provide the name here
181 # logo: <update, optional>
182
183 # Management interface
184 mgmt-interface:
185 cp: vnf-cp0
186
187 # Atleast one VDU need to be specified
188 vdu:
189 # Additional VDUs can be created by copying the
190 # VDU descriptor below
191 - id: ${name}-VM
192 name: ${name}-VM
193 description: ${name}-VM
194 count: 1
195
196 # Flavour of the VM to be instantiated for the VDU
197 vm-flavor:
198 vcpu-count: ${VCPU}
199 memory-mb: ${MEMORY}
200 storage-gb: ${STORAGE}
201
202 # Image including the full path
203 image: '${IMAGE}'
204
205 EOF
206
207 # Add the cloud init file or script
208 if [[ -n ${CLOUD_INIT_FILE} ]]; then
209 cif=$(basename ${CLOUD_INIT_FILE})
210 cat >>$desc_file <<EOF
211 # Cloud init file
212 cloud-init-file: '${cif}'
213 EOF
214 elif [[ -n ${CLOUD_INIT} ]]; then
215 cat >>$desc_file <<EOF
216 # Cloud init to use
217 cloud-init: '${CLOUD_INIT}'
218 EOF
219 fi
220
221 # Add external interfaces
222 cat >>$desc_file <<EOF
223 interface:
224 # Specify the external interfaces
225 # There can be multiple interfaces defined
226 EOF
227
228 # Add mgmt interface
229 cat >>$desc_file <<EOF
230 - name: eth0
231 type: EXTERNAL
232 virtual-interface:
233 type: PARAVIRT
234 external-connection-point-ref: vnf-cp0
235 EOF
236
237 # Add external interfaces
238 for i in `seq 1 ${INTERFACES}`; do
239 eth=$(($i))
240 cat >>$desc_file <<EOF
241 - name: eth${eth}
242 type: EXTERNAL
243 virtual-interface:
244 type: ${INTF_TYPE}
245 external-connection-point-ref: vnf-cp${eth}
246 EOF
247 done
248
249 # Add connection points
250 cat >>$desc_file <<EOF
251
252 connection-point:
253 EOF
254
255 for i in `seq 0 ${INTERFACES}`; do
256 eth=$(($i))
257 cat >>$desc_file <<EOF
258 - name: vnf-cp${eth}
259 EOF
260 done
261
262 cat >>$desc_file <<EOF
263
264 # Uncomment and update below to enable juju
265 # charm configuration for the VNF
266 # vnf-configuration:
267 # juju:
268 # charm: <charm name>
269 # service-primitive:
270 # - name: config
271 # parameter:
272 # - name: <config parameter>
273 # data-type: [STRING|INTEGER]
274 # mandatory: [true|false]
275 # default-value: <value>
276 # - name: <action name>
277 # parameter:
278 # - name: <action parameter>
279 # data-type: [STRING|INTEGER]
280 # mandatory: [true|false]
281 # default-value: <value>
282 # initial-config-primitive:
283 # - name: config
284 # parameter:
285 # - name: <config name>
286 # value: <value>
287 # - name: <action name>
288 # parameter:
289 # - name: <action parameter>
290 # value: <value>
291 EOF
292
293 if [ $VERBOSE == true ]; then
294 echo "INFO: Created $desc_file"
295 fi
296 }
297
298 function write_nsd_tmpl() {
299 name=$(basename $1)
300 vnfd=$2
301 desc_file="${name}.yaml"
302
303 cat >$desc_file <<EOF
304 nsd:nsd-catalog:
305 nsd:
306 - id: ${name}
307 name: ${name}
308 short-name: ${name}
309 description: Generated by OSM package generator
310 vendor: ${VENDOR}
311 version: '1.0'
312
313 # Place the logo as png in icons directory and provide the name here
314 # logo: <update, optional>
315
316 # Specify the VNFDs that are part of this NSD
317 constituent-vnfd:
318 # The member-vnf-index needs to be unique, starting from 1
319 # vnfd-id-ref is the id of the VNFD
320 # Multiple constituent VNFDs can be specified
321 - member-vnf-index: 1
322 vnfd-id-ref: ${vnfd}
323
324 EOF
325
326 cat >>$desc_file <<EOF
327 vld:
328 # Networks for the VNFs
329 EOF
330
331 # Add management VLD
332 cat >>$desc_file <<EOF
333 - id: ${name}_vld0
334 name: management
335 short-name: management
336 type: ELAN
337 mgmt-network: 'true'
338 # vim-network-name: <update>
339 # provider-network:
340 # overlay-type: VLAN
341 # segmentation_id: <update>
342 vnfd-connection-point-ref:
343 # Specify the constituent VNFs
344 # member-vnf-index-ref - entry from constituent vnf
345 # vnfd-id-ref - VNFD id
346 # vnfd-connection-point-ref - connection point name in the VNFD
347 - member-vnf-index-ref: 1
348 vnfd-id-ref: ${vnfd}
349 # NOTE: Validate the entry below
350 vnfd-connection-point-ref: vnf-cp0
351 EOF
352
353 # Add rest of VLDs
354 for i in `seq 1 ${INTERFACES}`; do
355 eth=$(($i))
356 cat >>$desc_file <<EOF
357 - id: ${name}_vld${i}
358 name: ${name}_vld${i}
359 short-name: ${name}_vld${i}
360 type: ELAN
361 # vim-network-name: <update>
362 # provider-network:
363 # overlay-type: VLAN
364 # segmentation_id: <update>
365 vnfd-connection-point-ref:
366 # Specify the constituent VNFs
367 # member-vnf-index-ref - entry from constituent vnf
368 # vnfd-id-ref - VNFD id
369 # vnfd-connection-point-ref - connection point name in the VNFD
370 - member-vnf-index-ref: 1
371 vnfd-id-ref: ${vnfd}
372 # NOTE: Validate the entry below
373 vnfd-connection-point-ref: vnf-cp${eth}
374 EOF
375 done
376
377 if [ $VERBOSE == true ]; then
378 echo "INFO: Created $desc_file"
379 fi
380 }
381
382 function write_nsd_config_tmpl() {
383 name=$(basename $1)
384 cfg_file="ns_config/$name.yaml"
385
386 cat >$cfg_file <<EOF
387
388 EOF
389
390 if [ $VERBOSE == true ]; then
391 echo "INFO: Created $cfg_file"
392 fi
393 }
394
395 cur_dir=`pwd`
396
397 # Check if the array contains a specific value
398 # Taken from
399 # http://stackoverflow.com/questions/3685970/check-if-an-array-contains-a-value
400 function contains() {
401 local n=$#
402 local value=${!n}
403 for ((i=1;i < $#;i++)); do
404 if [ "${!i}" == "${value}" ]; then
405 echo "y"
406 return 0
407 fi
408 done
409 echo "n"
410 return 1
411 }
412
413 function check_type() {
414 type=$1
415 if [ $(contains "${DESC_TYPES[@]}" $type) == "y" ]; then
416 TYPE=$type
417 else
418 echo "ERROR: Unknown descriptor type $type!" >&2
419 exit 1
420 fi
421 }
422
423 function get_expr(){
424 # First argument is to specify if this is a negative match or not
425 # Rest are filename expressions without extension
426
427 local regex=" "
428 local n=$#
429 local neg="${1}"
430 local first="true"
431 for ((i=2;i <= $#;i++)); do
432 for extn in "${DESC_EXTN[@]}"; do
433 if [ $first == true ]; then
434 if [ $neg == true ]; then
435 subexpr='! -name'
436 else
437 subexpr='-name'
438 fi
439 first=false
440 else
441 if [ $neg == true ]; then
442 subexpr=' -a ! -name'
443 else
444 subexpr=' -o -name'
445 fi
446 fi
447
448 regex="$regex $subexpr ${!i}.$extn"
449 done
450 done
451
452 echo "$regex"
453 }
454
455 function generate_package(){
456 type=$1
457 name="${2}_${type}"
458 vnfd="${2}_vnfd" # Required for NSD
459 dest_dir=$3
460
461 dir="${dest_dir}/${name}"
462
463 # Create the folders for the descriptor
464 if [ $VERBOSE == true ]; then
465 echo "INFO: Creating folders for $PKG in $dest_dir"
466 fi
467
468 # Remove any existing directory
469 if [ -d $dir ]; then
470 rm -rf $dir >/dev/null 2>&1
471 fi
472
473 mkdir -p $dir && cd $dir
474 if [ $? -ne 0 ]; then
475 rc=$?
476 echo "ERROR: creating directory $dir ($rc)" >&2
477 exit $rc
478 fi
479
480 if [ $type == 'nsd' ]; then
481 folders=("${NSD_FOLDERS[@]}")
482 else
483 folders=("${VNFD_FOLDERS[@]}")
484 fi
485
486 for d in ${folders[@]}; do
487 mkdir -p $dir/$d
488 if [ $? -ne 0 ]; then
489 rc=$?
490 echo "ERROR: creating directory $dir/$d ($rc)" >&2
491 exit $rc
492 fi
493 if [ $VERBOSE == true ]; then
494 echo "Created folder $d in $dir"
495 fi
496 done
497
498 if [ $VERBOSE == true ]; then
499 echo "INFO: Created folders for in $dir"
500 fi
501
502 # Write a descriptor template file
503 if [ $type == 'vnfd' ]; then
504
505 # Copy cloud init file to correct folder
506 if [[ -n ${CLOUD_INIT_FILE} ]]; then
507 if [[ -e ${CLOUD_INIT_FILE} ]]; then
508 cp ${CLOUD_INIT_FILE} $dir/cloud_init
509 else
510 echo "ERROR: Unable to find cloud-init-file ${CLOUD_INIT_FILE}"
511 exit 1
512 fi
513 fi
514
515 write_vnfd_tmpl $dir
516 else
517 write_nsd_tmpl $dir $vnfd
518 fi
519
520 write_readme $dir
521
522 if [ $ARCHIVE == true ]; then
523 # Create archive of the package
524 cd $dest_dir
525 if [ $VERBOSE == true ]; then
526 tar zcvf ${name}.tar.gz ${name}
527 echo "Created package ${name}.tar.gz in $dest_dir"
528 else
529 tar zcvf ${name}.tar.gz ${name} >/dev/null 2>&1
530 fi
531
532 if [ $? -ne 0 ]; then
533 echo "ERROR: Creating archive for ${name} in $dest_dir" >&2
534 exit 1
535 fi
536
537 echo "$dest_dir/${name}.tar.gz" >&2
538
539 if [ $RM == true ]; then
540 rm -rf ${name}
541 fi
542 fi
543 }
544
545 OPTS=`getopt -o vhnt:d:caN --long verbose,dry-run,help,package-type:,destination-dir,create-folder,no-remove-files,archive,nsd,vendor:,interface-type:,vcpu:,memory:,storage:,image:,cloud-init-file:,cloud-init:,interfaces:,debug -n $SCRIPTNAME -- "$@"`
546
547 if [ $? != 0 ] ; then
548 echo "ERROR: Failed parsing options ($?)." >&2
549 usage
550 exit 1
551 fi
552
553 #echo "$OPTS"
554 eval set -- "$OPTS >/dev/null 2>&1"
555
556 while true; do
557 case "$1" in
558 -v | --verbose ) VERBOSE=true; shift ;;
559 -h | --help ) usage; exit 0; shift ;;
560 -n | --dry-run ) DRY_RUN=true; shift ;;
561 -t | --package-type ) check_type "$2"; shift; shift ;;
562 -d | --destination-dir ) DEST_DIR=$2; shift; shift;;
563 -c | --create-folder ) CREATE=true; shift;;
564 -N | --no-remove-files ) RM=''; shift;;
565 -a | --archive ) ARCHIVE=true; shift;;
566 --nsd ) CREATE_NSD=true; shift;;
567 --vendor ) VENDOR=$2; shift; shift;;
568 --interface-type ) INTF_TYPE=$2; shift; shift;;
569 --vcpu ) VCPU=$2; shift; shift;;
570 --memory ) MEMORY=$2; shift; shift;;
571 --storage ) STORAGE=$2; shift; shift;;
572 --image ) IMAGE=$2; shift; shift;;
573 --cloud-init ) CLOUD_INIT=$2; shift; shift;;
574 --cloud-init-file ) CLOUD_INIT_FILE=$2; shift; shift;;
575 --interfaces ) INTERFACES=$2; shift; shift;;
576 --debug ) DEBUG=true; shift;;
577 -- ) shift; break ;;
578 * ) break ;;
579 esac
580 done
581
582 if [ $DEBUG == true ]; then
583 echo "INFO: Debugging ON"
584 set -x
585 fi
586
587 if [ $VERBOSE == true ]; then
588 echo "INFO: Descriptor type: $TYPE"
589 fi
590
591 # Dry run is to validate existing descriptor folders
592 if [ $DRY_RUN == true ] && [ $CREATE == true ]; then
593 echo "ERROR: Option dry-run with create-folders not supported!" >&2
594 exit 1
595 fi
596
597 if [ $# -gt 1 ]; then
598 BASE_DIR=$1
599 PKG=$(basename $2)
600 else
601 BASE_DIR=$(dirname $1)
602 PKG=$(basename $1)
603 fi
604
605 if [ $VERBOSE == true ]; then
606 echo "INFO: Using base dir: $BASE_DIR"
607 fi
608
609 if [ $VERBOSE == true ]; then
610 echo "INFO: Using package: $PKG"
611 fi
612
613 if [[ -z "$PKG" ]]; then
614 echo "ERROR: Need to specify the package name" >&2
615 usage >&2
616 exit 1
617 fi
618
619 if [[ ! -d $BASE_DIR ]]; then
620 if [ $CREATE == true ]; then
621 mkdir -p $BASE_DIR
622 if [ $? -ne 0 ]; then
623 echo "ERROR: Unable to create base directory $BASE_DIR" >&2
624 exit 1
625 fi
626 fi
627 fi
628 cd $BASE_DIR
629 if [ $? -ne 0 ]; then
630 echo "ERROR: Unable to change to base directory $BASE_DIR!" >&2
631 exit 1
632 fi
633
634 # Get full base dir path
635 BASE_DIR=`pwd`
636 cd $cur_dir
637
638 if [[ -z $DEST_DIR ]]; then
639 DEST_DIR=$BASE_DIR # Default to base directory
640 fi
641
642 mkdir -p $DEST_DIR
643
644 cd $DEST_DIR
645 if [ $? -ne 0 ]; then
646 echo "ERROR: Not able to access destination directory $DEST_DIR!" >&2
647 exit 1
648 fi
649
650 # Get the full destination dir path
651 DEST_DIR=`pwd`
652 cd $cur_dir
653
654 dir=${BASE_DIR}/${PKG}
655
656 function add_chksum() {
657 if [ $VERBOSE == true ]; then
658 echo "INFO: Add file $1 to $CHKSUM"
659 fi
660
661 md5sum $1 >> $CHKSUM
662 }
663
664 if [ $CREATE == false ]; then
665 if [ ! -d $dir ]; then
666 echo "INFO: Package folder $dir not found!" >&2
667 exit 1
668 fi
669
670 cd $dir
671 if [ $? -ne 0 ]; then
672 rc=$?
673 echo "ERROR: changing directory to $dir ($rc)" >&2
674 exit $rc
675 fi
676
677 # Remove checksum file, if present
678 rm -f $CHKSUM
679
680 # Check if the descriptor file is present
681 if [[ -z $TYPE ]]; then
682 # Desc type not specified, look for the desc file and guess the type
683 # Required for backward compatibility
684 for ty in ${DESC_TYPES[@]}; do
685 re=$(get_expr false "$ty" "*_$ty" "*_${ty}_*")
686 desc=$(find * -maxdepth 0 -type f $re 2>/dev/null)
687
688 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
689 # Check the vnfd|nsd folder
690 if [ ! -d $ty ]; then
691 continue
692 fi
693 re=$(get_expr false "*")
694 desc=$(find $ty/* -maxdepth 0 -type f $re 2>/dev/null)
695 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
696 continue
697 elif [ ${#desc[@]} -gt 1 ]; then
698 echo "ERROR: Found multiple descriptor files: ${desc[@]}" >&2
699 exit 1
700 fi
701 # Descriptor sub directory
702 desc_sub_dir=$ty
703 fi
704
705 TYPE=$ty
706 if [ $TYPE == 'nsd' ]; then
707 folders=("${NSD_FOLDERS[@]}")
708 else
709 folders=("${VNFD_FOLDERS[@]}")
710 fi
711
712 if [ $VERBOSE == true ]; then
713 echo "INFO: Determined descriptor is of type $TYPE"
714 fi
715 break
716 done
717
718 if [[ -z $TYPE ]]; then
719 echo "ERROR: Unable to determine the descriptor type!" >&2
720 exit 1
721 fi
722 else
723 if [ $TYPE == 'nsd' ]; then
724 folders=("${NSD_FOLDERS[@]}")
725 else
726 folders=("${VNFD_FOLDERS[@]}")
727 fi
728
729 # Check for descriptor of type provided on command line
730 re=$(get_expr false "$TYPE" "*_${TYPE}" "*_${TYPE}_*")
731 desc=$(find * -maxdepth 0 -type f $re 2>/dev/null)
732
733 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
734 # Check if it is under vnfd/nsd subdirectory
735 # Backward compatibility support
736 re=$(get_expr false "*")
737 desc=$(find $TYPE/* -maxdepth 0 -type f $re 2>/dev/null)
738 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
739 echo "ERROR: Did not find descriptor file of type $TYPE" \
740 " in $dir" >&2
741 exit 1
742 fi
743 desc_sub_dir=$ty
744 fi
745 fi
746
747 if [ ${#desc[@]} -gt 1 ]; then
748 echo "ERROR: Found multiple files of type $TYPE in $dir: $desc" >&2
749 exit 1
750 fi
751
752 descriptor=${desc[0]}
753
754 # Check if there are files not supported
755 files=$(find * -maxdepth 0 -type f ! -name $descriptor 2>/dev/null)
756
757 for f in ${files[@]}; do
758 if [ $(contains "${ALLOWED_FILES[@]}" $f) == "n" ]; then
759 echo "WARN: Unsupported file $f found"
760 fi
761 done
762
763 if [ $VERBOSE == true ]; then
764 echo "INFO: Found descriptor package: ${desc_sub_dir} ${descriptor}"
765 fi
766
767 if [ $DRY_RUN == false ]; then
768 add_chksum ${descriptor}
769 fi
770
771 # Check the folders are supported ones
772 dirs=$( find * -maxdepth 0 -type d )
773
774 for d in ${dirs[@]}; do
775 if [ $(contains "${folders[@]}" $d) == "y" ]; then
776 if [ $DRY_RUN == false ]; then
777 find $d/* -type f 2>/dev/null|
778 while read file; do
779 add_chksum $file
780 done
781 fi
782 elif [[ -z $desc_sub_dir ]] || [ $d != $desc_sub_dir ]; then
783 echo "WARN: $d is not part of standard folders " \
784 "for descriptor type $TYPE in $PKG"
785 fi
786 done
787
788 if [ $VERBOSE == true ]; then
789 echo "INFO: Creating archive for $PKG"
790 fi
791
792 cd $BASE_DIR
793 # Mrityunjay Yadav: Validate descriptor
794 GEN_BASEDIR=$(dirname "$0")
795 python $GEN_BASEDIR/validate_descriptor.py $DEST_DIR/$PKG/$descriptor
796 if [ $? -ne 0 ]; then
797 rc=$?
798 echo "ERROR: validating descriptor for $PKG ($rc)" >&2
799 exit $rc
800 fi
801 if [ $DRY_RUN == false ]; then
802 if [ $VERBOSE == true ]; then
803 tar zcvf "$DEST_DIR/$PKG.tar.gz" "${PKG}" ${RM}
804 else
805 #tar zcvf ${name}.tar.gz ${name} >/dev/null 2>&1
806 tar zcvf "$DEST_DIR/$PKG.tar.gz" "${PKG}" ${RM} > /dev/null 2>&1
807 fi
808 if [ $? -ne 0 ]; then
809 rc=$?
810 echo "ERROR: creating archive for $PKG ($rc)" >&2
811 exit $rc
812 fi
813 fi
814 else
815 # Create, default to VNFD if no type is defined
816 if [[ -z $TYPE ]]; then
817 TYPE=vnfd
818 if [ $VERBOSE == true ]; then
819 echo "WARNING: Defaulting to descriptor type $TYPE"
820 fi
821 fi
822
823 if [ $TYPE == 'vnfd' ]; then
824 if [[ -z $IMAGE ]]; then
825 echo "ERROR: Image file need to be specified for VNF"
826 exit 1
827 fi
828 generate_package vnfd $PKG $DEST_DIR
829 fi
830
831 if [ $TYPE == 'nsd' -o $CREATE_NSD == true ]; then
832 generate_package nsd $PKG $DEST_DIR
833 fi
834
835 fi
836
837 cd $cur_dir