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