Bug 85: Fix VyOS package build
[osm/devops.git] / src / 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 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='VIRTIO'
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 [VIRTIO|SR-IOV|PCI-PASSTHROUGH|E1000]
102 Default VIRTIO
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 VIRTIO ) 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 pacakage 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 vdu-id: ${name}-VM
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 external-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 virtual-interface:
232 type: OM-MGMT
233 bandwidth: '0'
234 vpci: 0000:00:0a.0
235 vnfd-connection-point-ref: eth0
236 EOF
237
238 # Add external interfaces
239 for i in `seq 1 ${INTERFACES}`; do
240 eth=$(($i))
241 pci=$(get_pci $eth)
242 cat >>$desc_file <<EOF
243 - name: eth${eth}
244 virtual-interface:
245 type: ${INTF_TYPE}
246 bandwidth: '0'
247 vpci: 0000:00:${pci}.0
248 vnfd-connection-point-ref: eth${eth}
249 EOF
250 done
251
252 # Add connection points
253 cat >>$desc_file <<EOF
254
255 connection-point:
256 EOF
257
258 for i in `seq 0 ${INTERFACES}`; do
259 eth=$(($i))
260 cat >>$desc_file <<EOF
261 - name: eth${eth}
262 type: ${CP_TYPE}
263 EOF
264 done
265
266 cat >>$desc_file <<EOF
267
268 # Uncomment and update below to enable juju
269 # charm configuration for the VNF
270 # vnf-configuration:
271 # juju:
272 # charm: <charm name>
273 # service-primitive:
274 # - name: config
275 # parameter:
276 # - name: <config parameter>
277 # data-type: [STRING|INTEGER]
278 # mandatory: [true|false]
279 # default-value: <value>
280 # - name: <action name>
281 # parameter:
282 # - name: <action parameter>
283 # data-type: [STRING|INTEGER]
284 # mandatory: [true|false]
285 # default-value: <value>
286 # initial-config-primitive:
287 # - name: config
288 # parameter:
289 # - name: <config name>
290 # value: <value>
291 # - name: <action name>
292 # parameter:
293 # - name: <action parameter>
294 # value: <value>
295 EOF
296
297 if [ $VERBOSE == true ]; then
298 echo "INFO: Created $desc_file"
299 fi
300 }
301
302 function write_nsd_tmpl() {
303 name=$(basename $1)
304 vnfd=$2
305 desc_file="${name}.yaml"
306
307 cat >$desc_file <<EOF
308 nsd:nsd-catalog:
309 nsd:
310 - id: ${name}
311 name: ${name}
312 short-name: ${name}
313 description: Generated by OSM pacakage generator
314 vendor: ${VENDOR}
315 version: '1.0'
316
317 # Place the logo as png in icons directory and provide the name here
318 # logo: <update, optional>
319
320 # Specify the VNFDs that are part of this NSD
321 constituent-vnfd:
322 # The member-vnf-index needs to be unique, starting from 1
323 # vnfd-id-ref is the id of the VNFD
324 # Multiple constituent VNFDs can be specified
325 - member-vnf-index: 1
326 vnfd-id-ref: ${vnfd}
327
328 EOF
329
330 cat >>$desc_file <<EOF
331 vld:
332 # Networks for the VNFs
333 EOF
334
335 # Add management VLD
336 cat >>$desc_file <<EOF
337 - id: ${name}_vld0
338 name: management
339 short-name: management
340 type: ELAN
341 # vim-network-name: <update>
342 # provider-network:
343 # overlay-type: VLAN
344 # segmentation_id: <update>
345 vnfd-connection-point-ref:
346 # Specify the constituent VNFs
347 # member-vnf-index-ref - entry from constituent vnf
348 # vnfd-id-ref - VNFD id
349 # vnfd-connection-point-ref - connection point name in the VNFD
350 - nsd:member-vnf-index-ref: 1
351 nsd:vnfd-id-ref: ${vnfd}
352 # NOTE: Validate the entry below
353 nsd:vnfd-connection-point-ref: eth0
354 EOF
355
356 # Add rest of VLDs
357 for i in `seq 1 ${INTERFACES}`; do
358 eth=$(($i))
359 cat >>$desc_file <<EOF
360 - id: ${name}_vld${i}
361 name: ${name}_vld${i}
362 short-name: ${name}_vld${i}
363 type: ELAN
364 # vim-network-name: <update>
365 # provider-network:
366 # overlay-type: VLAN
367 # segmentation_id: <update>
368 vnfd-connection-point-ref:
369 # Specify the constituent VNFs
370 # member-vnf-index-ref - entry from constituent vnf
371 # vnfd-id-ref - VNFD id
372 # vnfd-connection-point-ref - connection point name in the VNFD
373 - nsd:member-vnf-index-ref: 1
374 nsd:vnfd-id-ref: ${vnfd}
375 # NOTE: Validate the entry below
376 nsd:vnfd-connection-point-ref: eth${eth}
377 EOF
378 done
379
380 if [ $VERBOSE == true ]; then
381 echo "INFO: Created $desc_file"
382 fi
383 }
384
385 function write_nsd_config_tmpl() {
386 name=$(basename $1)
387 cfg_file="ns_config/$name.yaml"
388
389 cat >$cfg_file <<EOF
390
391 EOF
392
393 if [ $VERBOSE == true ]; then
394 echo "INFO: Created $cfg_file"
395 fi
396 }
397
398 cur_dir=`pwd`
399
400 # Check if the array contains a specific value
401 # Taken from
402 # http://stackoverflow.com/questions/3685970/check-if-an-array-contains-a-value
403 function contains() {
404 local n=$#
405 local value=${!n}
406 for ((i=1;i < $#;i++)); do
407 if [ "${!i}" == "${value}" ]; then
408 echo "y"
409 return 0
410 fi
411 done
412 echo "n"
413 return 1
414 }
415
416 function check_type() {
417 type=$1
418 if [ $(contains "${DESC_TYPES[@]}" $type) == "y" ]; then
419 TYPE=$type
420 else
421 echo "ERROR: Unknown descriptor type $type!" >&2
422 exit 1
423 fi
424 }
425
426 function get_expr(){
427 # First argument is to specify if this is a negative match or not
428 # Rest are filename expressions without extension
429
430 local regex=" "
431 local n=$#
432 local neg="${1}"
433 local first="true"
434 for ((i=2;i <= $#;i++)); do
435 for extn in "${DESC_EXTN[@]}"; do
436 if [ $first == true ]; then
437 if [ $neg == true ]; then
438 subexpr='! -name'
439 else
440 subexpr='-name'
441 fi
442 first=false
443 else
444 if [ $neg == true ]; then
445 subexpr=' -a ! -name'
446 else
447 subexpr=' -o -name'
448 fi
449 fi
450
451 regex="$regex $subexpr ${!i}.$extn"
452 done
453 done
454
455 echo "$regex"
456 }
457
458 function generate_package(){
459 type=$1
460 name="${2}_${type}"
461 vnfd="${2}_vnfd" # Required for NSD
462 dest_dir=$3
463
464 dir="${dest_dir}/${name}"
465
466 # Create the folders for the descriptor
467 if [ $VERBOSE == true ]; then
468 echo "INFO: Creating folders for $PKG in $dest_dir"
469 fi
470
471 # Remove any existing directory
472 if [ -d $dir ]; then
473 rm -rf $dir >/dev/null 2>&1
474 fi
475
476 mkdir -p $dir && cd $dir
477 if [ $? -ne 0 ]; then
478 rc=$?
479 echo "ERROR: creating directory $dir ($rc)" >&2
480 exit $rc
481 fi
482
483 if [ $type == 'nsd' ]; then
484 folders=("${NSD_FOLDERS[@]}")
485 else
486 folders=("${VNFD_FOLDERS[@]}")
487 fi
488
489 for d in ${folders[@]}; do
490 mkdir -p $dir/$d
491 if [ $? -ne 0 ]; then
492 rc=$?
493 echo "ERROR: creating directory $dir/$d ($rc)" >&2
494 exit $rc
495 fi
496 if [ $VERBOSE == true ]; then
497 echo "Created folder $d in $dir"
498 fi
499 done
500
501 if [ $VERBOSE == true ]; then
502 echo "INFO: Created folders for in $dir"
503 fi
504
505 # Write a descriptor template file
506 if [ $type == 'vnfd' ]; then
507
508 # Copy cloud init file to correct folder
509 if [[ -n ${CLOUD_INIT_FILE} ]]; then
510 if [[ -e ${CLOUD_INIT_FILE} ]]; then
511 cp ${CLOUD_INIT_FILE} $dir/cloud_init
512 else
513 echo "ERROR: Unable to find cloud-init-file ${CLOUD_INIT_FILE}"
514 exit 1
515 fi
516 fi
517
518 write_vnfd_tmpl $dir
519 else
520 write_nsd_tmpl $dir $vnfd
521 fi
522
523 write_readme $dir
524
525 if [ $ARCHIVE == true ]; then
526 # Create archive of the package
527 cd $dest_dir
528 if [ $VERBOSE == true ]; then
529 tar zcvf ${name}.tar.gz ${name}
530 echo "Created package ${name}.tar.gz in $dest_dir"
531 else
532 tar zcvf ${name}.tar.gz ${name} >/dev/null 2>&1
533 fi
534
535 if [ $? -ne 0 ]; then
536 echo "ERROR: Creating archive for ${name} in $dest_dir" >&2
537 exit 1
538 fi
539
540 echo "$dest_dir/${name}.tar.gz" >&2
541
542 if [ $RM == true ]; then
543 rm -rf ${name}
544 fi
545 fi
546 }
547
548 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 -- "$@"`
549
550 if [ $? != 0 ] ; then
551 echo "ERROR: Failed parsing options ($?)." >&2
552 usage
553 exit 1
554 fi
555
556 echo "$OPTS"
557 eval set -- "$OPTS >/dev/null 2>&1"
558
559 while true; do
560 case "$1" in
561 -v | --verbose ) VERBOSE=true; shift ;;
562 -h | --help ) usage; exit 0; shift ;;
563 -n | --dry-run ) DRY_RUN=true; shift ;;
564 -t | --package-type ) check_type "$2"; shift; shift ;;
565 -d | --destination-dir ) DEST_DIR=$2; shift; shift;;
566 -c | --create-folder ) CREATE=true; shift;;
567 -N | --no-remove-files ) RM=''; shift;;
568 -a | --archive ) ARCHIVE=true; shift;;
569 --nsd ) CREATE_NSD=true; shift;;
570 --vendor ) VENDOR=$2; shift; shift;;
571 --interface-type ) INTF_TYPE=$2; shift; shift;;
572 --vcpu ) VCPU=$2; shift; shift;;
573 --memory ) MEMORY=$2; shift; shift;;
574 --storage ) STORAGE=$2; shift; shift;;
575 --image ) IMAGE=$2; shift; shift;;
576 --cloud-init ) CLOUD_INIT=$2; shift; shift;;
577 --cloud-init-file ) CLOUD_INIT_FILE=$2; shift; shift;;
578 --interfaces ) INTERFACES=$2; shift; shift;;
579 --debug ) DEBUG=true; shift;;
580 -- ) shift; break ;;
581 * ) break ;;
582 esac
583 done
584
585 if [ $DEBUG == true ]; then
586 echo "INFO: Debugging ON"
587 set -x
588 fi
589
590 if [ $VERBOSE == true ]; then
591 echo "INFO: Descriptor type: $TYPE"
592 fi
593
594 # Dry run is to validate existing descriptor folders
595 if [ $DRY_RUN == true ] && [ $CREATE == true ]; then
596 echo "ERROR: Option dry-run with create-folders not supported!" >&2
597 exit 1
598 fi
599
600 if [ $# -gt 1 ]; then
601 BASE_DIR=$1
602 PKG=$(basename $2)
603 else
604 BASE_DIR=$(dirname $1)
605 PKG=$(basename $1)
606 fi
607
608 if [ $VERBOSE == true ]; then
609 echo "INFO: Using base dir: $BASE_DIR"
610 fi
611
612 if [ $VERBOSE == true ]; then
613 echo "INFO: Using package: $PKG"
614 fi
615
616 if [[ -z "$PKG" ]]; then
617 echo "ERROR: Need to specify the package name" >&2
618 usage >&2
619 exit 1
620 fi
621
622 if [[ ! -d $BASE_DIR ]]; then
623 if [ $CREATE == true ]; then
624 mkdir -p $BASE_DIR
625 if [ $? -ne 0 ]; then
626 echo "ERROR: Unable to create base directory $BASE_DIR" >&2
627 exit 1
628 fi
629 fi
630 fi
631 cd $BASE_DIR
632 if [ $? -ne 0 ]; then
633 echo "ERROR: Unable to change to base directory $BASE_DIR!" >&2
634 exit 1
635 fi
636
637 # Get full base dir path
638 BASE_DIR=`pwd`
639 cd $cur_dir
640
641 if [[ -z $DEST_DIR ]]; then
642 DEST_DIR=$BASE_DIR # Default to base directory
643 fi
644
645 mkdir -p $DEST_DIR
646
647 cd $DEST_DIR
648 if [ $? -ne 0 ]; then
649 echo "ERROR: Not able to access destination directory $DEST_DIR!" >&2
650 exit 1
651 fi
652
653 # Get the full destination dir path
654 DEST_DIR=`pwd`
655 cd $cur_dir
656
657 dir=${BASE_DIR}/${PKG}
658
659 function add_chksum() {
660 if [ $VERBOSE == true ]; then
661 echo "INFO: Add file $1 to $CHKSUM"
662 fi
663
664 md5sum $1 >> $CHKSUM
665 }
666
667 if [ $CREATE == false ]; then
668 if [ ! -d $dir ]; then
669 echo "INFO: Package folder $dir not found!" >&2
670 exit 1
671 fi
672
673 cd $dir
674 if [ $? -ne 0 ]; then
675 rc=$?
676 echo "ERROR: changing directory to $dir ($rc)" >&2
677 exit $rc
678 fi
679
680 # Remove checksum file, if present
681 rm -f $CHKSUM
682
683 # Check if the descriptor file is present
684 if [[ -z $TYPE ]]; then
685 # Desc type not specified, look for the desc file and guess the type
686 # Required for backward compatibility
687 for ty in ${DESC_TYPES[@]}; do
688 re=$(get_expr false "$ty" "*_$ty" "*_${ty}_*")
689 desc=$(find * -maxdepth 0 -type f $re 2>/dev/null)
690
691 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
692 # Check the vnfd|nsd folder
693 if [ ! -d $ty ]; then
694 continue
695 fi
696 re=$(get_expr false "*")
697 desc=$(find $ty/* -maxdepth 0 -type f $re 2>/dev/null)
698 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
699 continue
700 elif [ ${#desc[@]} -gt 1 ]; then
701 echo "ERROR: Found multiple descriptor files: ${desc[@]}" >&2
702 exit 1
703 fi
704 # Descriptor sub directory
705 desc_sub_dir=$ty
706 fi
707
708 TYPE=$ty
709 if [ $TYPE == 'nsd' ]; then
710 folders=("${NSD_FOLDERS[@]}")
711 else
712 folders=("${VNFD_FOLDERS[@]}")
713 fi
714
715 if [ $VERBOSE == true ]; then
716 echo "INFO: Determined descriptor is of type $TYPE"
717 fi
718 break
719 done
720
721 if [[ -z $TYPE ]]; then
722 echo "ERROR: Unable to determine the descriptor type!" >&2
723 exit 1
724 fi
725 else
726 if [ $TYPE == 'nsd' ]; then
727 folders=("${NSD_FOLDERS[@]}")
728 else
729 folders=("${VNFD_FOLDERS[@]}")
730 fi
731
732 # Check for descriptor of type provided on command line
733 re=$(get_expr false "$TYPE" "*_${TYPE}" "*_${TYPE}_*")
734 desc=$(find * -maxdepth 0 -type f $re 2>/dev/null)
735
736 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
737 # Check if it is under vnfd/nsd subdirectory
738 # Backward compatibility support
739 re=$(get_expr false "*")
740 desc=$(find $TYPE/* -maxdepth 0 -type f $re 2>/dev/null)
741 if [[ -z $desc ]] || [ ${#desc[@]} -eq 0 ]; then
742 echo "ERROR: Did not find descriptor file of type $TYPE" \
743 " in $dir" >&2
744 exit 1
745 fi
746 desc_sub_dir=$ty
747 fi
748 fi
749
750 if [ ${#desc[@]} -gt 1 ]; then
751 echo "ERROR: Found multiple files of type $TYPE in $dir: $desc" >&2
752 exit 1
753 fi
754
755 descriptor=${desc[0]}
756
757 # Check if there are files not supported
758 files=$(find * -maxdepth 0 -type f ! -name $descriptor 2>/dev/null)
759
760 for f in ${files[@]}; do
761 if [ $(contains "${ALLOWED_FILES[@]}" $f) == "n" ]; then
762 echo "WARN: Unsupported file $f found"
763 fi
764 done
765
766 if [ $VERBOSE == true ]; then
767 echo "INFO: Found descriptor package: ${desc_sub_dir} ${descriptor}"
768 fi
769
770 if [ $DRY_RUN == false ]; then
771 add_chksum ${descriptor}
772 fi
773
774 # Check the folders are supported ones
775 dirs=$( find * -maxdepth 0 -type d )
776
777 for d in ${dirs[@]}; do
778 if [ $(contains "${folders[@]}" $d) == "y" ]; then
779 if [ $DRY_RUN == false ]; then
780 find $d/* -type f 2>/dev/null|
781 while read file; do
782 add_chksum $file
783 done
784 fi
785 elif [[ -z $desc_sub_dir ]] || [ $d != $desc_sub_dir ]; then
786 echo "WARN: $d is not part of standard folders " \
787 "for descriptor type $TYPE in $PKG"
788 fi
789 done
790
791 if [ $VERBOSE == true ]; then
792 echo "INFO: Creating archive for $PKG"
793 fi
794
795 cd $BASE_DIR
796 if [ $DRY_RUN == false ]; then
797 tar zcvf "$DEST_DIR/$PKG.tar.gz" "${PKG}" ${RM}
798 if [ $? -ne 0 ]; then
799 rc=$?
800 echo "ERROR: creating archive for $PKG ($rc)" >&2
801 exit $rc
802 fi
803 fi
804 else
805 # Create, default to VNFD if no type is defined
806 if [[ -z $TYPE ]]; then
807 TYPE=vnfd
808 if [ $VERBOSE == true ]; then
809 echo "WARNING: Defaulting to descriptor type $TYPE"
810 fi
811 fi
812
813 if [ $TYPE == 'vnfd' ]; then
814 if [[ -z $IMAGE ]]; then
815 echo "ERROR: Image file need to be specified for VNF"
816 exit 1
817 fi
818 generate_package vnfd $PKG $DEST_DIR
819 fi
820
821 if [ $TYPE == 'nsd' -o $CREATE_NSD == true ]; then
822 generate_package nsd $PKG $DEST_DIR
823 fi
824
825 fi
826
827 cd $cur_dir